diff --git a/app/assets/images/arrow-darkred.png b/app/assets/images/arrow-darkred.png deleted file mode 100644 index 9d7e2ce..0000000 Binary files a/app/assets/images/arrow-darkred.png and /dev/null differ diff --git a/app/assets/images/arrow-grey.png b/app/assets/images/arrow-grey.png new file mode 100644 index 0000000..23bd814 Binary files /dev/null and b/app/assets/images/arrow-grey.png differ diff --git a/app/assets/images/arrow-midgrey.png b/app/assets/images/arrow-midgrey.png deleted file mode 100644 index fc42ff9..0000000 Binary files a/app/assets/images/arrow-midgrey.png and /dev/null differ diff --git a/app/assets/images/arrow-red.png b/app/assets/images/arrow-red.png new file mode 100644 index 0000000..0a19c0f Binary files /dev/null and b/app/assets/images/arrow-red.png differ diff --git a/app/assets/images/logo.png b/app/assets/images/logo.png index ce58fb1..ebce703 100644 Binary files a/app/assets/images/logo.png and b/app/assets/images/logo.png differ diff --git a/app/assets/images/rails.png b/app/assets/images/rails.png deleted file mode 100644 index d5edc04..0000000 Binary files a/app/assets/images/rails.png and /dev/null differ diff --git a/app/assets/stylesheets/blogposts.css.scss b/app/assets/stylesheets/blogposts.css.scss deleted file mode 100644 index 916c0b2..0000000 --- a/app/assets/stylesheets/blogposts.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// 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 deleted file mode 100644 index e730912..0000000 --- a/app/assets/stylesheets/comments.css.scss +++ /dev/null @@ -1,3 +0,0 @@ -// 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/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss deleted file mode 100644 index 6ec6a8f..0000000 --- a/app/assets/stylesheets/scaffolds.css.scss +++ /dev/null @@ -1,69 +0,0 @@ -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 index 4d61af2..b9dca84 100644 --- a/app/assets/stylesheets/screen.css.scss +++ b/app/assets/stylesheets/screen.css.scss @@ -2,15 +2,21 @@ $lightgrey: #D1D1D1; +$lightergrey: #959595; $midgrey: #787878; $darkgrey: #434343; $darkred: #AB0000; + @media only screen and (min-width: 1000px) { + html { + overflow-y: scroll; + } + a { transition: color 0.25s; color: $darkred; @@ -19,17 +25,6 @@ and (min-width: 1000px) color: #F00; } } - a.arrow { - background: url('/assets/arrow-midgrey.png') no-repeat left; - color: $midgrey; - padding-left: 0.7em; - margin: 0.6em; - &:hover { - background: url('/assets/arrow-darkred.png') no-repeat left; - color: $darkred; - padding-left: 0.7em; - } - } #notice { background: #8e8; text-align: center; @@ -54,7 +49,6 @@ and (min-width: 1000px) box-shadow: 0 0 2px; z-index: 99; position: relative; - text-shadow: 1px 1px #555; #logo { margin: 9px; margin-left: 20px; @@ -88,10 +82,16 @@ and (min-width: 1000px) float: right; padding: 0 10px; margin-top: 6px; + text-align: right; + &.logged-out { + margin-top: 2px; + } img.avatar { border: 1px solid #000; border-radius: 16px; vertical-align: middle; + height: 32px; + width: 32px; &:hover { box-shadow: 0 0 2px; } @@ -107,7 +107,19 @@ and (min-width: 1000px) img.user-avatar { border: 1px solid #000; border-radius: 4px; + height: 128px; + width: 128px; } + + img.avatar { + image-rendering:optimizeSpeed; + image-rendering:-moz-crisp-edges; + image-rendering:-o-crisp-edges; + image-rendering:optimize-contrast; + image-rendering:-webkit-optimize-contrast; + -ms-interpolation-mode: nearest-neighbor; + } + span.no-about { color: #888; font-style: italic; @@ -165,6 +177,15 @@ and (min-width: 1000px) #comments { margin: 50px 0 0 40px; + .comment { + margin-bottom: 12px; + padding: 15px; + box-shadow: 0 0 10px #bbb inset; + &.author { + background: #dadada; + box-shadow: 0 0 10px #a7a7a7 inset; + } + } textarea { width: 480px; height: 106px; @@ -172,4 +193,77 @@ and (min-width: 1000px) } } + input { + &[type=text], &[type=email], &[type=password] { + border: 1px solid #aaa; + border-radius: 3px; + background: #eee; + margin: 4px; + box-shadow: 0 0 5px $lightgrey inset; + height: 17px; + width: 300px; + padding: 1px 0; + display: block; + } + } + + textarea { + border: 1px solid #aaa; + border-radius: 3px; + background: #eee; + margin: 4px; + box-shadow: 0 0 5px $lightgrey inset; + height: 300px; + width: 300px; + max-width: 100%; + min-width: 300px; + min-height: 50px; + padding: 1px 0; + display: block; + } + + .field_with_errors { + input { + &[type=text], &[type=email], &[type=password] { + border: 1px solid #f00; + box-shadow: 0 0 5px #faa inset; + } + } + .error { + color: #f60; + } + } + + #form_labels { + text-align: right; + float: left; + label { + display: block; + padding: 0 0 4px 0; + margin: 0 4px 4px; + height: 17px; + } + } + #form_inputs { + + } + + #edit_profile { + float: right; + } + + .btn-blue { + border: 1px solid; + padding: 6px; + background: #4096ee; + cursor: default; + color: #fff; + &:hover { + box-shadow: 0 0 5px #095fb7 inset; + color: #fff; + outline: none; + } + } + + } \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c5928db..d2125a8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,10 +1,12 @@ class ApplicationController < ActionController::Base protect_from_forgery - force_ssl - require "Tools" + # force_ssl + helper :all + include ToolsHelper + helper_method :current_user + private def current_user - @current_user ||= User.find(session[:user_id]) if session[:user_id] + @current_user ||= User.find_by_id(session[:user_id]) end - helper_method :current_user -end +end \ No newline at end of file diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb index 9df5451..1992538 100644 --- a/app/controllers/blogposts_controller.rb +++ b/app/controllers/blogposts_controller.rb @@ -1,19 +1,14 @@ 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) + @comment = Comment.new(:blogpost => @post) end - # GET /blogposts/new - # GET /blogposts/new.json def new @post = Blogpost.new end @@ -26,12 +21,17 @@ class BlogpostsController < ApplicationController # 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.' + if current_user && current_user.rank >= rank_to_int("mod") + @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 else - render action: "new" + flash[:alert] = "You are not allowed to create new posts" + redirect_to blog_path end end @@ -53,6 +53,6 @@ class BlogpostsController < ApplicationController @post = Blogpost.find(params[:id]) @post.destroy - redirect_to blogposts_url + redirect_to blog_url end end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 0d9e5b7..82f64cb 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -42,13 +42,12 @@ class CommentsController < ApplicationController def create @comment = Comment.new(params[:comment]) @comment.user_id = current_user.id - respond_to do |format| + @comment.blogpost = Blogpost.find(params[:blogpost_id]) if @comment.save - format.html { redirect_to @comment, notice: 'Comment was successfully created.' } - format.json { render json: @comment, status: :created, location: @comment } + redirect_to @comment.blogpost, notice: 'Comment was successfully created.' else - format.html { render action: "new" } - format.json { render json: @comment.errors, status: :unprocessable_entity } + flash[:alert] = "There was a problem while saving your comment" + redirect_to blogpost_path(params[:blogpost_id]) end end end @@ -59,13 +58,12 @@ class CommentsController < ApplicationController @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 + 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 diff --git a/app/controllers/serverchecker_controller.rb b/app/controllers/serverchecker_controller.rb index c87a4bf..30d510d 100644 --- a/app/controllers/serverchecker_controller.rb +++ b/app/controllers/serverchecker_controller.rb @@ -1,7 +1,7 @@ class ServercheckerController < ApplicationController def show - require "Tools" - if Tools.mc_running? + + if 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" diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 62af4b3..90ef8e5 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,13 +1,9 @@ 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.last_login = Time.now user.save if user.banned flash[:alert] = "You are banned!" @@ -24,6 +20,6 @@ class SessionsController < ApplicationController def destroy session[:user_id] = nil - redirect_to root_path, :notice => "Logged out!" + redirect_to login_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 index eb194da..45f2da1 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,12 +14,22 @@ class UsersController < ApplicationController # GET /users/new # GET /users/new.json def new - @user = User.new + if current_user + flash[:alert] = "You are already registered!" + redirect_to user_path(current_user.id) + else + @user = User.new + end end # GET /users/1/edit def edit - @user = User.find(params[:id]) + if current_user && (current_user.id = params[:id] || current_user.rank >= rank_to_int("mod")) + @user = User.find(params[:id]) + else + flash[:alert] = "You are not allwoed to edit this user" + redirect_to user_path(params[:id]) + end end # POST /users diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..3a2b877 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,2 @@ module ApplicationHelper -end +end \ No newline at end of file diff --git a/app/helpers/tools_helper.rb b/app/helpers/tools_helper.rb new file mode 100644 index 0000000..68d0e9c --- /dev/null +++ b/app/helpers/tools_helper.rb @@ -0,0 +1,2 @@ +module ToolsHelper +end \ No newline at end of file diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 2310a24..709431c 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,2 +1,39 @@ module UsersHelper + def avatar_url(user_id) + u = User.find_by_id(user_id) + u.nil? ? ign = :char : ign = u.ign + return "https://minotar.net/avatar/#{ign}/8" + end + + def 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 rank_to_int(rank) + r = ranks[rank] + end + + def int_to_rank(int) + r = ranks.rassoc(int) + r.nil? ? "unknown" : r[0].to_s + end + + def ranks + # Lower case !!! + {"visitor" => 10, "member" => 20, "builder" => 30, "donor" => 40, "donor+" => 45, "mod" => 100, "admin" => 200, "superadmin" => 500} + end end diff --git a/app/models/blogpost.rb b/app/models/blogpost.rb index 4663d50..d142fa9 100644 --- a/app/models/blogpost.rb +++ b/app/models/blogpost.rb @@ -3,4 +3,5 @@ class Blogpost < ActiveRecord::Base validates_presence_of :title, :text, :user belongs_to :user has_many :comments + accepts_nested_attributes_for :comments end diff --git a/app/models/comment.rb b/app/models/comment.rb index bc2e39e..2e367b3 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,6 +1,6 @@ class Comment < ActiveRecord::Base - attr_accessible :text, :user_id, :blogpost_id + attr_accessible :text, :user_id, :blogpost, :post validates_presence_of :text, :user_id, :blogpost_id belongs_to :blogpost belongs_to :user -end +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 9347249..914da3b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,10 @@ class User < ActiveRecord::Base - attr_accessible :name, :ign, :email, :about, :password, :password_confirmation + attr_accessible :name, :ign, :email, :about, :password, :password_confirmation, :rank has_secure_password - validates_presence_of :password, :on => :create + validates_presence_of :password, :name, :email, :ign, :password_confirmation, :on => :create + validates :email, :uniqueness => true + validates :name, :uniqueness => true + validates :ign, :uniqueness => true has_many :blogposts has_many :comments diff --git a/app/views/blogposts/_form.html.erb b/app/views/blogposts/_form.html.erb index a61fb20..f86f61d 100644 --- a/app/views/blogposts/_form.html.erb +++ b/app/views/blogposts/_form.html.erb @@ -1,5 +1,5 @@ <%= simple_form_for @post do |f|%> - <%= f.input :title %> - <%= f.input :text %> - <%= f.submit %> + <%= f.input :title, :label => false %> + <%= f.input :text, :label => false %> + <%= f.submit "Create Post" %> <% end %> \ No newline at end of file diff --git a/app/views/blogposts/index.html.erb b/app/views/blogposts/index.html.erb index c680062..8189858 100644 --- a/app/views/blogposts/index.html.erb +++ b/app/views/blogposts/index.html.erb @@ -2,10 +2,19 @@
New comment
<%= simple_form_for [@post, @comment] do |f| %> - <%= f.input :text, :label => false, :as => "text", :placeholder => "Comment" %><%= f.submit %> + <%= f.input :text, :label => false, :as => "text", :placeholder => "Comment" %> + <%= f.submit %> <% end %> <% end %>- <%= link_to image_tag("logout.png"), logout_path %> - - <%= link_to image_tag(Tools.avatar_url(current_user.id, 32), :class => "avatar"), current_user %> + + <%= link_to current_user.name.truncate(14), current_user %>
+ <%= link_to "Logout", logout_path %> + + <%= link_to image_tag(avatar_url(current_user.id), :class => "avatar size32"), current_user %> <% else %> - <%= link_to "Log in", login_path, :action => "new" %> + <%= link_to "Log in", login_path, :action => "new" %>
+ <%= link_to "Register", register_path %> <% end %>
Log in
<%= form_tag login_path do |f| %> - <%= label_tag :email %>- <%= text_field_tag :email %>
- <%= label_tag :password %>
- <%= password_field_tag :password %>
- <%= submit_tag %> +
New user
+Register
-<%= render 'form' %> - -<%= link_to 'Back', users_path %> \ No newline at end of file +<%= simple_form_for @user do |f| %> + <%= f.input :name %> + <%= f.input :ign, label: "Ingame name" %> + <%= f.input :email %> + <%= f.input :password %> + <%= f.input :password_confirmation %> + <%= f.submit "Register" %> +<% end %> \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 1cfab4e..41e2221 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,10 +1,14 @@ --<% 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 +
+ <% if @user.banned %> + This user is banned! + <% end %> + IGN: <%= @user.ign %>
+ Rank: <%= int_to_rank(@user.rank) %>
+ Joined: <%= @user.created_at.strftime("%e. %b %Y") %>
+ <% if current_user && current_user.rank >= rank_to_int("mod") %> + Last IP: <%= @user.last_ip %>
+ <% end %> + About: <%= @user.about.blank? ? "nothing".html_safe : @user.about %> +