diff --git a/Gemfile b/Gemfile index e4e9806..18434a7 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,11 @@ gem 'rails', '3.2.12' # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' - +gem 'jquery-rails' +gem 'therubyracer' +gem 'bcrypt-ruby', '~> 3.0.0' # To use ActiveModel has_secure_password +gem 'simple_form' +gem 'rbbcode' # Gems used only for assets and not required # in production environments by default. @@ -20,11 +24,10 @@ group :assets do gem 'uglifier', '>= 1.0.3' end -gem 'jquery-rails' -gem 'therubyracer' - -# To use ActiveModel has_secure_password -# gem 'bcrypt-ruby', '~> 3.0.0' +group :development do + gem 'better_errors' + gem 'binding_of_caller' +end # To use Jbuilder templates for JSON # gem 'jbuilder' diff --git a/Gemfile.lock b/Gemfile.lock index eecfb76..30f44e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,7 +29,14 @@ GEM i18n (~> 0.6) multi_json (~> 1.0) arel (3.0.2) + bcrypt-ruby (3.0.1) + better_errors (0.7.2) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + binding_of_caller (0.7.1) + debug_inspector (>= 0.0.1) builder (3.0.4) + coderay (1.0.9) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -37,6 +44,7 @@ GEM coffee-script-source execjs coffee-script-source (1.6.2) + debug_inspector (0.0.2) erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) @@ -54,6 +62,7 @@ GEM treetop (~> 1.4.8) mime-types (1.23) multi_json (1.7.3) + nokogiri (1.5.9) polyglot (0.3.3) rack (1.4.5) rack-cache (1.2) @@ -78,14 +87,23 @@ GEM rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.0.4) + rbbcode (1.0.3) + sanitize + treetop rdoc (3.12.2) json (~> 1.4) ref (1.0.4) + sanitize (2.0.3) + nokogiri (>= 1.4.4, < 1.6) + nokogiri (>= 1.4.4, < 1.6) sass (3.2.9) sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) + simple_form (2.1.0) + actionpack (~> 3.0) + activemodel (~> 3.0) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -109,10 +127,15 @@ PLATFORMS ruby DEPENDENCIES + bcrypt-ruby (~> 3.0.0) + better_errors + binding_of_caller coffee-rails (~> 3.2.1) jquery-rails rails (= 3.2.12) + rbbcode sass-rails (~> 3.2.3) + simple_form sqlite3 therubyracer uglifier (>= 1.0.3) diff --git a/app/assets/images/favicon.ico b/app/assets/images/favicon.ico new file mode 100644 index 0000000..501f61a Binary files /dev/null and b/app/assets/images/favicon.ico differ diff --git a/app/assets/images/logo.png b/app/assets/images/logo.png new file mode 100644 index 0000000..ce58fb1 Binary files /dev/null and b/app/assets/images/logo.png differ diff --git a/app/assets/images/off.png b/app/assets/images/off.png new file mode 100644 index 0000000..2720164 Binary files /dev/null and b/app/assets/images/off.png differ diff --git a/app/assets/images/on.png b/app/assets/images/on.png new file mode 100644 index 0000000..12a001a Binary files /dev/null and b/app/assets/images/on.png differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9097d83..a6df101 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,6 +10,6 @@ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // -//= require jquery -//= require jquery_ujs -//= require_tree . +//= #require jquery +//= #require jquery_ujs +//= #require_tree . diff --git a/app/assets/javascripts/blogposts.js.coffee b/app/assets/javascripts/blogposts.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/blogposts.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/comments.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/users.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 3192ec8..e93ffaf 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -1,13 +1,6 @@ /* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the top of the - * compiled file, but it's generally better to create a new file per style scope. - * *= require_self - *= require_tree . - */ + *= require style.css + *= require screen.css + *= require mobi.css + */ \ No newline at end of file diff --git a/app/assets/stylesheets/blogposts.css.scss b/app/assets/stylesheets/blogposts.css.scss new file mode 100644 index 0000000..916c0b2 --- /dev/null +++ b/app/assets/stylesheets/blogposts.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Blogposts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/comments.css.scss b/app/assets/stylesheets/comments.css.scss new file mode 100644 index 0000000..e730912 --- /dev/null +++ b/app/assets/stylesheets/comments.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Comments controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/mobi.css.scss b/app/assets/stylesheets/mobi.css.scss new file mode 100644 index 0000000..154a36b --- /dev/null +++ b/app/assets/stylesheets/mobi.css.scss @@ -0,0 +1,6 @@ +/* CSS for Phones only */ +@media only screen +and (max-width: 999px) +{ + +} \ No newline at end of file diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 0000000..6ec6a8f --- /dev/null +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,69 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + &:visited { + color: #666; + } + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + ul li { + font-size: 12px; + list-style: square; + } +} diff --git a/app/assets/stylesheets/screen.css.scss b/app/assets/stylesheets/screen.css.scss new file mode 100644 index 0000000..18f730f --- /dev/null +++ b/app/assets/stylesheets/screen.css.scss @@ -0,0 +1,127 @@ +/* CSS for PCs only */ +@media only screen +and (min-width: 1000px) +{ + + + + + a { + transition: color 0.25s; + color: #700; + text-decoration: none; + &:hover { + color: #F00; + } + } + #notice { + background: #8e8; + text-align: center; + padding: 10px; + border-bottom: 3px dashed #8d8; + font-weight: bold; + } + #alert { + background: #ebb; + text-align: center; + padding: 10px; + border-bottom: 3px dashed #fdd; + font-weight: bold; + } + #head { + width: 100%; + height: 40px; + background: #ccc; + border-bottom: 2px solid #aaa; + vertical-align: middle; + #logo { + margin: 4px; + margin-left: 20px; + height: 32px; + width: 32px; + float: left; + background: url('/assets/logo.png'); + } + #userinfo { + float: right; + padding: 0 10px; + margin-top: 2px; + img.avatar { + border: 1px solid #000; + border-radius: 16px; + vertical-align: middle; + &:hover { + box-shadow: 0 0 2px; + } + } + } + } + img.user-avatar { + border: 1px solid #000; + border-radius: 4px; + } + span.no-about { + color: #888; + font-style: italic; + } + + #main-content { + width: 650px; + margin: 0 auto; + background: #eee; + padding: 30px; + + h1 { + font-weight: normal; + font-size: 400%; + margin: 0; + color: #888; + text-shadow: 0 1px #999; + } + } + + #posts { + #post { + margin-bottom: 50px; + #post-title { + margin-bottom: 10px; + h2 { + font-weight: normal; + color: #700; + text-transform: uppercase; + display: inline; + font-size: 250%; + } + .comment-counter { + float: right; + } + } + } + } + + .post-info { + border-bottom: 2px dashed #999; + color: #888; + a { + color: #755; + &:hover{ + color: #d55; + } + } + } + + #post-content { + margin-top: 10px; + clear: both; + } + + #comments { + margin: 50px 0 0 40px; + textarea { + width: 480px; + height: 106px; + max-width: 610px; + } + } + +} \ No newline at end of file diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss new file mode 100644 index 0000000..82d020d --- /dev/null +++ b/app/assets/stylesheets/style.css.scss @@ -0,0 +1,9 @@ +/* General CSS for all screens */ +body { + margin: 0; + padding: 0; + font: 14px/1.6 "Open Sans","Lucida Sans","Lucida Grande","Lucida Sans Unicode",Calibri,sans-serif; +} + +// use screen.css +// and mobi.css \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e8065d9..c5928db 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,10 @@ class ApplicationController < ActionController::Base protect_from_forgery + force_ssl + require "Tools" + private + def current_user + @current_user ||= User.find(session[:user_id]) if session[:user_id] + end + helper_method :current_user end diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb new file mode 100644 index 0000000..9df5451 --- /dev/null +++ b/app/controllers/blogposts_controller.rb @@ -0,0 +1,58 @@ +class BlogpostsController < ApplicationController + # GET /blogposts + # GET /blogposts.json + def index + @posts = Blogpost.all.reverse + end + + # GET /blogposts/1 + # GET /blogposts/1.json + def show + @post = Blogpost.find(params[:id]) + @comment = Comment.new(:blogpost_id => @post.id) + end + + # GET /blogposts/new + # GET /blogposts/new.json + def new + @post = Blogpost.new + end + + # GET /blogposts/1/edit + def edit + @post = Blogpost.find(params[:id]) + end + + # POST /blogposts + # POST /blogposts.json + def create + @post = Blogpost.new(params[:blogpost]) + @post.user_id = current_user.id unless current_user.nil? + if @post.save + redirect_to @post, notice: 'Post has been created.' + else + render action: "new" + end + end + + # PUT /blogposts/1 + # PUT /blogposts/1.json + def update + @post = Blogpost.find(params[:id]) + + if @post.update_attributes(params[:blogpost]) + redirect_to @post, notice: 'Post has been updated.' + else + render action: "edit" + end + end + + # DELETE /blogposts/1 + # DELETE /blogposts/1.json + def destroy + @post = Blogpost.find(params[:id]) + @post.destroy + + redirect_to blogposts_url + end +end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..0d9e5b7 --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,83 @@ +class CommentsController < ApplicationController + # GET /comments + # GET /comments.json + def index + @comments = Comment.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @comments } + end + end + + # GET /comments/1 + # GET /comments/1.json + def show + @comment = Comment.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @comment } + end + end + + # GET /comments/new + # GET /comments/new.json + def new + @comment = Comment.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @comment } + end + end + + # GET /comments/1/edit + def edit + @comment = Comment.find(params[:id]) + end + + # POST /comments + # POST /comments.json + def create + @comment = Comment.new(params[:comment]) + @comment.user_id = current_user.id + respond_to do |format| + if @comment.save + format.html { redirect_to @comment, notice: 'Comment was successfully created.' } + format.json { render json: @comment, status: :created, location: @comment } + else + format.html { render action: "new" } + format.json { render json: @comment.errors, status: :unprocessable_entity } + end + end + end + + # PUT /comments/1 + # PUT /comments/1.json + def update + @comment = Comment.find(params[:id]) + + respond_to do |format| + if @comment.update_attributes(params[:comment]) + format.html { redirect_to @comment, notice: 'Comment was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @comment.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /comments/1 + # DELETE /comments/1.json + def destroy + @comment = Comment.find(params[:id]) + @comment.destroy + + respond_to do |format| + format.html { redirect_to comments_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/paypal_controller.rb b/app/controllers/paypal_controller.rb new file mode 100644 index 0000000..6fc50f9 --- /dev/null +++ b/app/controllers/paypal_controller.rb @@ -0,0 +1,35 @@ +class PaypalController < ApplicationController + protect_from_forgery :except => [:create] #Otherwise the request from PayPal wouldn't make it to the controller + def create + puts request.raw_post + response = validate_IPN_notification(request.raw_post) + case response + when "VERIFIED" + # check that paymentStatus=Completed + # check that txnId has not been previously processed + # check that receiverEmail is your Primary PayPal email + # check that paymentAmount/paymentCurrency are correct + # process payment + when "INVALID" + # log for investigation + else + # error + end + render :nothing => true + end + + + protected + def validate_IPN_notification(raw) + uri = URI.parse('https://www.paypal.com/cgi-bin/webscr?cmd=_notify-validate') + http = Net::HTTP.new(uri.host, uri.port) + http.open_timeout = 60 + http.read_timeout = 60 + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + http.use_ssl = true + response = http.post(uri.request_uri, raw, + 'Content-Length' => "#{raw.size}", + 'User-Agent' => "Redstoner.com" + ).body + end +end \ No newline at end of file diff --git a/app/controllers/serverchecker_controller.rb b/app/controllers/serverchecker_controller.rb new file mode 100644 index 0000000..c87a4bf --- /dev/null +++ b/app/controllers/serverchecker_controller.rb @@ -0,0 +1,10 @@ +class ServercheckerController < ApplicationController + def show + require "Tools" + if Tools.mc_running? + send_file "app/assets/images/on.png", :type => "image/png", :disposition => "inline" + else + send_file "app/assets/images/off.png", :type => "image/png", :disposition => "inline" + end + end +end \ No newline at end of file diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..62af4b3 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,29 @@ +class SessionsController < ApplicationController + + def new + + end + + def create + user = User.find_by_email(params[:email]) + if user && user.authenticate(params[:password]) + user.last_ip = request.remote_ip + user.save + if user.banned + flash[:alert] = "You are banned!" + redirect_to login_path + else + session[:user_id] = user.id + redirect_to root_path, :notice => "Logged in!" + end + else + flash[:alert] = "You're doing it wrong!" + redirect_to login_path + end + end + + def destroy + session[:user_id] = nil + redirect_to root_path, :notice => "Logged out!" + end +end \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..eb194da --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,54 @@ +class UsersController < ApplicationController + # GET /users + # GET /users.json + def index + @users = User.all + end + + # GET /users/1 + # GET /users/1.json + def show + @user = User.find(params[:id]) + end + + # GET /users/new + # GET /users/new.json + def new + @user = User.new + end + + # GET /users/1/edit + def edit + @user = User.find(params[:id]) + end + + # POST /users + # POST /users.json + def create + @user = User.new(params[:user]) + if @user.save + redirect_to @user, notice: 'User was successfully created.' + else + render action: "new" + end + end + + # PUT /users/1 + # PUT /users/1.json + def update + @user = User.find(params[:id]) + if @user.update_attributes(params[:user]) + redirect_to @user, notice: 'User was successfully updated.' + else + render action: "edit" + end + end + + # DELETE /users/1 + # DELETE /users/1.json + def destroy + @user = User.find(params[:id]) + @user.destroy + redirect_to users_url + end +end diff --git a/app/helpers/blogposts_helper.rb b/app/helpers/blogposts_helper.rb new file mode 100644 index 0000000..48e43d1 --- /dev/null +++ b/app/helpers/blogposts_helper.rb @@ -0,0 +1,2 @@ +module BlogpostsHelper +end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 0000000..0ec9ca5 --- /dev/null +++ b/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..2310a24 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/blogpost.rb b/app/models/blogpost.rb new file mode 100644 index 0000000..4663d50 --- /dev/null +++ b/app/models/blogpost.rb @@ -0,0 +1,6 @@ +class Blogpost < ActiveRecord::Base + attr_accessible :title, :text + validates_presence_of :title, :text, :user + belongs_to :user + has_many :comments +end diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..bc2e39e --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,6 @@ +class Comment < ActiveRecord::Base + attr_accessible :text, :user_id, :blogpost_id + validates_presence_of :text, :user_id, :blogpost_id + belongs_to :blogpost + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..9347249 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,8 @@ +class User < ActiveRecord::Base + attr_accessible :name, :ign, :email, :about, :password, :password_confirmation + has_secure_password + validates_presence_of :password, :on => :create + + has_many :blogposts + has_many :comments +end \ No newline at end of file diff --git a/app/views/blogposts/_form.html.erb b/app/views/blogposts/_form.html.erb new file mode 100644 index 0000000..a61fb20 --- /dev/null +++ b/app/views/blogposts/_form.html.erb @@ -0,0 +1,5 @@ +<%= simple_form_for @post do |f|%> + <%= f.input :title %> + <%= f.input :text %> + <%= f.submit %> +<% end %> \ No newline at end of file diff --git a/app/views/blogposts/edit.html.erb b/app/views/blogposts/edit.html.erb new file mode 100644 index 0000000..b120662 --- /dev/null +++ b/app/views/blogposts/edit.html.erb @@ -0,0 +1,6 @@ +

Editing blogpost

+ +<%= render 'form' %> + +<%= link_to 'Show', @blogpost %> | +<%= link_to 'Back', blogposts_path %> diff --git a/app/views/blogposts/index.html.erb b/app/views/blogposts/index.html.erb new file mode 100644 index 0000000..c680062 --- /dev/null +++ b/app/views/blogposts/index.html.erb @@ -0,0 +1,11 @@ +

Blog

+
+ <% @posts.each do |p| %> +
+

<%= link_to p.title, p %>

<%= link_to pluralize(p.comments.count, "Comment"), p %>
+ +
<%= RbbCode.new.convert(p.text).html_safe %>
+
+ <% end %> + <%= link_to 'New Blogpost', new_blogpost_path if current_user && current_user.rank >= Tools.rank_to_int(:mod) %> +
diff --git a/app/views/blogposts/new.html.erb b/app/views/blogposts/new.html.erb new file mode 100644 index 0000000..e2478c9 --- /dev/null +++ b/app/views/blogposts/new.html.erb @@ -0,0 +1,3 @@ +

New Blogpost

+ +<%= render 'form' %> diff --git a/app/views/blogposts/show.html.erb b/app/views/blogposts/show.html.erb new file mode 100644 index 0000000..a555a20 --- /dev/null +++ b/app/views/blogposts/show.html.erb @@ -0,0 +1,27 @@ +

<%= @post.title %>

+<%= link_to @post.user.name, @post.user %> on <%= @post.created_at.strftime("%e. %b %Y") %> + <% if current_user.rank >= Tools.rank_to_int(:mod) %> + - <%= link_to "edit", edit_blogpost_path(@post.id) %> + <% end %> + +
+ <%= RbbCode.new.convert(@post.text).html_safe %> +
+
+ <% @post.comments.each do |c| %> +
+ <%= link_to c.user.name, c.user %> on <%= c.created_at.strftime("%e. %b %Y") %> + <% if current_user.rank >= Tools.rank_to_int(:mod) %> + - <%= link_to "edit", edit_blogpost_comment_path(c.id) %> + <% end %> + +
<%= c.text %>
+
+ <% end %> + <% if current_user && current_user.rank >= Tools.rank_to_int(:visitor) %> +

New comment

+ <%= simple_form_for [@post, @comment] do |f| %> + <%= f.input :text, :label => false, :as => "text", :placeholder => "Comment" %><%= f.submit %> + <% end %> + <% end %> +
\ No newline at end of file diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb new file mode 100644 index 0000000..a568b0b --- /dev/null +++ b/app/views/comments/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@comment) do |f| %> + <% if @comment.errors.any? %> +
+

<%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:

+ + +
+ <% end %> + +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/comments/edit.html.erb b/app/views/comments/edit.html.erb new file mode 100644 index 0000000..12ea7f9 --- /dev/null +++ b/app/views/comments/edit.html.erb @@ -0,0 +1,6 @@ +

Editing comment

+ +<%= render 'form' %> + +<%= link_to 'Show', @comment %> | +<%= link_to 'Back', comments_path %> diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb new file mode 100644 index 0000000..bfa38fe --- /dev/null +++ b/app/views/comments/index.html.erb @@ -0,0 +1,21 @@ +

Listing comments

+ + + + + + + + +<% @comments.each do |comment| %> + + + + + +<% end %> +
<%= link_to 'Show', comment %><%= link_to 'Edit', edit_comment_path(comment) %><%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Comment', new_comment_path %> diff --git a/app/views/comments/new.html.erb b/app/views/comments/new.html.erb new file mode 100644 index 0000000..07a754a --- /dev/null +++ b/app/views/comments/new.html.erb @@ -0,0 +1,5 @@ +

New comment

+ +<%= render 'form' %> + +<%= link_to 'Back', comments_path %> diff --git a/app/views/comments/show.html.erb b/app/views/comments/show.html.erb new file mode 100644 index 0000000..d5e89c7 --- /dev/null +++ b/app/views/comments/show.html.erb @@ -0,0 +1,5 @@ +

<%= notice %>

+ + +<%= link_to 'Edit', edit_comment_path(@comment) %> | +<%= link_to 'Back', comments_path %> diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb new file mode 100644 index 0000000..29e70f3 --- /dev/null +++ b/app/views/layouts/_head.html.erb @@ -0,0 +1,13 @@ + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7387252..7a5326c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,18 @@ - Site - <%= stylesheet_link_tag "application", :media => "all" %> - <%= javascript_include_tag "application" %> + Redstoner + <%= stylesheet_link_tag "application", :media => "all" %> <%= csrf_meta_tags %> + <%= favicon_link_tag "favicon.ico" %> - +<%= render "/layouts/head" %> +<%= "
#{alert}
".html_safe if alert %> +<%= "
#{notice}
".html_safe if notice %> +
<%= yield %> +
- + \ No newline at end of file diff --git a/app/views/rails.png b/app/views/rails.png new file mode 100644 index 0000000..d5edc04 Binary files /dev/null and b/app/views/rails.png differ diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 0000000..7840f59 --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,8 @@ +

Log in

+<%= form_tag login_path do |f| %> + <%= label_tag :email %>
+ <%= text_field_tag :email %>
+ <%= label_tag :password %>
+ <%= password_field_tag :password %>
+ <%= submit_tag %> +<% end %> \ No newline at end of file diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb new file mode 100644 index 0000000..1ccf767 --- /dev/null +++ b/app/views/users/_form.html.erb @@ -0,0 +1,8 @@ +<%= simple_form_for @user do |f| %> + <%= f.input :name %> + <%= f.input :ign %> + <%= f.input :email %> + <%= f.input :password %> + <%= f.input :password_confirmation %> + <%= f.submit %> +<% end %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb new file mode 100644 index 0000000..99bd4cc --- /dev/null +++ b/app/views/users/edit.html.erb @@ -0,0 +1,6 @@ +

Editing user

+ +<%= render 'form' %> + +<%= link_to 'Show', @user %> | +<%= link_to 'Back', users_path %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 0000000..48a5818 --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,4 @@ +

Listing users

+<% @users.each do |u| %> + <%= link_to u.name, u %> (<%= u.ign %>) +<% end %> \ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000..85f8414 --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,5 @@ +

New user

+ +<%= render 'form' %> + +<%= link_to 'Back', users_path %> \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000..1cfab4e --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,10 @@ +
+<%= image_tag Tools.avatar_url(@user.id, 128), :class => "user-avatar", :alt => "avatar" %>
+<% if @user.banned %> + This user is banned! +<% end %> +IGN: <%= @user.ign %>
+Rank: <%= Tools.int_to_rank(@user.rank) %>
+Joined: <%= @user.created_at.strftime("%e. %b %Y") %>
+Last IP: <%= @user.last_ip %>
+About: <%= @user.about.blank? ? "nothing".html_safe : @user.about %> \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 042009b..91338ab 100644 --- a/config/application.rb +++ b/config/application.rb @@ -22,6 +22,18 @@ module Site # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] + + + + + # ****************************************************** + # + # config.force_ssl = true + # + # ****************************************************** + + + # Activate observers that should always be running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer diff --git a/config/routes.rb b/config/routes.rb index 0d76e85..ec390cb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,58 +1,14 @@ Site::Application.routes.draw do - # The priority is based upon order of creation: - # first created -> highest priority. - # Sample of regular route: - # match 'products/:id' => 'catalog#view' - # Keep in mind you can assign values other than :controller and :action + resources :blogposts do + resources :comments + end + resources :users - # Sample of named route: - # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase - # This route can be invoked with purchase_url(:id => product.id) - - # Sample resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Sample resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Sample resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Sample resource route with more complex sub-resources - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', :on => :collection - # end - # end - - # Sample resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end - - # You can have the root of your site routed with "root" - # just remember to delete public/index.html. - # root :to => 'welcome#index' - - # See how all your routes lay out with "rake routes" - - # This is a legacy wild controller route that's not recommended for RESTful applications. - # Note: This route will make all actions in every controller accessible via GET requests. - # match ':controller(/:action(/:id))(.:format)' -end + match '/serverstatus.png' => 'serverchecker#show' + get "logout" => 'sessions#destroy' + get 'login' => 'sessions#new' + post 'login' => 'sessions#create' + post 'paypal' => 'paypal#create' + root :to => 'blogposts#index' +end \ No newline at end of file diff --git a/db/migrate/20130518221216_create_users.rb b/db/migrate/20130518221216_create_users.rb new file mode 100644 index 0000000..f2f0461 --- /dev/null +++ b/db/migrate/20130518221216_create_users.rb @@ -0,0 +1,16 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name, :unique => true, :null => false + t.string :ign, :unique => true, :null => false + t.integer :rank, :default => 10, :null => false + t.boolean :banned, :default => false + t.string :email, :unique => true, :null => false + t.text :about + t.string :password_digest, :null => false + t.string :last_ip + + t.timestamps + end + end +end diff --git a/db/migrate/20130526015928_create_blogposts.rb b/db/migrate/20130526015928_create_blogposts.rb new file mode 100644 index 0000000..3b477f7 --- /dev/null +++ b/db/migrate/20130526015928_create_blogposts.rb @@ -0,0 +1,11 @@ +class CreateBlogposts < ActiveRecord::Migration + def change + create_table :blogposts do |t| + t.string :title + t.text :text + t.integer :user_id + + t.timestamps + end + end +end diff --git a/db/migrate/20130526020734_create_comments.rb b/db/migrate/20130526020734_create_comments.rb new file mode 100644 index 0000000..7e3f744 --- /dev/null +++ b/db/migrate/20130526020734_create_comments.rb @@ -0,0 +1,11 @@ +class CreateComments < ActiveRecord::Migration + def change + create_table :comments do |t| + t.text :text + t.integer :user_id + t.integer :blogpost_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b5e6a79..ed8dc4f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,6 +11,35 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 0) do +ActiveRecord::Schema.define(:version => 20130526020734) do + + create_table "blogposts", :force => true do |t| + t.string "title" + t.text "text" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "comments", :force => true do |t| + t.text "text" + t.integer "user_id" + t.integer "blogpost_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "users", :force => true do |t| + t.string "name", :null => false + t.string "ign", :null => false + t.integer "rank", :default => 10, :null => false + t.boolean "banned", :default => false + t.string "email", :null => false + t.text "about" + t.string "password_digest", :null => false + t.string "last_ip" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end end diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e8..83e9fa7 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,4 @@ # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # -# Examples: -# -# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) -# Mayor.create(name: 'Emanuel', city: cities.first) +User.create(name: "Redstone Sheep", ign: "noobkackboon", email: "theredstonesheep@gmail.com", about: "Hi, I am the admin :)", password: "123", password_confirmation: "123") diff --git a/lib/Tools.rb b/lib/Tools.rb new file mode 100644 index 0000000..6271f11 --- /dev/null +++ b/lib/Tools.rb @@ -0,0 +1,39 @@ +module Tools + def Tools.avatar_url(user_id, size) + u = User.find_by_id(user_id) + u.nil? ? ign = :char : ign = u.ign + return "https://minotar.net/avatar/#{ign}/#{size}" + end + + def Tools.mc_running? + host = "play.redstoner.com" + port = 25565 + wait = 300/1000.0 #milliseconds, the .0 is required!! + require 'timeout' + require 'socket' + r = false + begin + Timeout::timeout(wait) { + TCPSocket.new host, port + r = true + } + rescue Exception + # could not connect to the server + end + return r + end + + def Tools.rank_to_int(rank) + r = Tools.ranks[rank] + end + + def Tools.int_to_rank(int) + r = Tools.ranks.rassoc(int) + r.nil? ? "unknown" : r[0].to_s + end + + def Tools.ranks + # Lower case !!! + {:visitor => 10, :member => 20, "member+" => 25, :builder => 30, :donor => 40, "donor+" => 45, :mod => 100, :admin => 200, :superadmin => 500} + end +end \ No newline at end of file diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..501f61a Binary files /dev/null and b/public/favicon.ico differ diff --git a/test/fixtures/blogposts.yml b/test/fixtures/blogposts.yml new file mode 100644 index 0000000..c63aac0 --- /dev/null +++ b/test/fixtures/blogposts.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/comments.yml b/test/fixtures/comments.yml new file mode 100644 index 0000000..c63aac0 --- /dev/null +++ b/test/fixtures/comments.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..c63aac0 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/functional/blogposts_controller_test.rb b/test/functional/blogposts_controller_test.rb new file mode 100644 index 0000000..831efa2 --- /dev/null +++ b/test/functional/blogposts_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class BlogpostsControllerTest < ActionController::TestCase + setup do + @blogpost = blogposts(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:blogposts) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create blogpost" do + assert_difference('Blogpost.count') do + post :create, blogpost: { } + end + + assert_redirected_to blogpost_path(assigns(:blogpost)) + end + + test "should show blogpost" do + get :show, id: @blogpost + assert_response :success + end + + test "should get edit" do + get :edit, id: @blogpost + assert_response :success + end + + test "should update blogpost" do + put :update, id: @blogpost, blogpost: { } + assert_redirected_to blogpost_path(assigns(:blogpost)) + end + + test "should destroy blogpost" do + assert_difference('Blogpost.count', -1) do + delete :destroy, id: @blogpost + end + + assert_redirected_to blogposts_path + end +end diff --git a/test/functional/comments_controller_test.rb b/test/functional/comments_controller_test.rb new file mode 100644 index 0000000..3ae3778 --- /dev/null +++ b/test/functional/comments_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class CommentsControllerTest < ActionController::TestCase + setup do + @comment = comments(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:comments) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create comment" do + assert_difference('Comment.count') do + post :create, comment: { } + end + + assert_redirected_to comment_path(assigns(:comment)) + end + + test "should show comment" do + get :show, id: @comment + assert_response :success + end + + test "should get edit" do + get :edit, id: @comment + assert_response :success + end + + test "should update comment" do + put :update, id: @comment, comment: { } + assert_redirected_to comment_path(assigns(:comment)) + end + + test "should destroy comment" do + assert_difference('Comment.count', -1) do + delete :destroy, id: @comment + end + + assert_redirected_to comments_path + end +end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb new file mode 100644 index 0000000..f035272 --- /dev/null +++ b/test/functional/users_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class UsersControllerTest < ActionController::TestCase + setup do + @user = users(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:users) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create user" do + assert_difference('User.count') do + post :create, user: { } + end + + assert_redirected_to user_path(assigns(:user)) + end + + test "should show user" do + get :show, id: @user + assert_response :success + end + + test "should get edit" do + get :edit, id: @user + assert_response :success + end + + test "should update user" do + put :update, id: @user, user: { } + assert_redirected_to user_path(assigns(:user)) + end + + test "should destroy user" do + assert_difference('User.count', -1) do + delete :destroy, id: @user + end + + assert_redirected_to users_path + end +end diff --git a/test/unit/blogpost_test.rb b/test/unit/blogpost_test.rb new file mode 100644 index 0000000..f732697 --- /dev/null +++ b/test/unit/blogpost_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class BlogpostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb new file mode 100644 index 0000000..b6d6131 --- /dev/null +++ b/test/unit/comment_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class CommentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/blogposts_helper_test.rb b/test/unit/helpers/blogposts_helper_test.rb new file mode 100644 index 0000000..7418751 --- /dev/null +++ b/test/unit/helpers/blogposts_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class BlogpostsHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/comments_helper_test.rb b/test/unit/helpers/comments_helper_test.rb new file mode 100644 index 0000000..2518c16 --- /dev/null +++ b/test/unit/helpers/comments_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class CommentsHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/users_helper_test.rb b/test/unit/helpers/users_helper_test.rb new file mode 100644 index 0000000..96af37a --- /dev/null +++ b/test/unit/helpers/users_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class UsersHelperTest < ActionView::TestCase +end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb new file mode 100644 index 0000000..82f61e0 --- /dev/null +++ b/test/unit/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end