many things, comments working.

This commit is contained in:
jomo
2013-06-24 13:29:39 +02:00
parent 7a894f4f6a
commit fb52e8bed2
44 changed files with 490 additions and 223 deletions
+7 -5
View File
@@ -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
+13 -13
View File
@@ -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
+10 -12
View File
@@ -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
+2 -2
View File
@@ -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"
+2 -6
View File
@@ -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
+12 -2
View File
@@ -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