This commit is contained in:
albert
2010-08-18 18:42:33 -04:00
parent 23656e3fa9
commit 5610731b35
48 changed files with 664 additions and 716 deletions

View File

@@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_current_user
after_filter :reset_current_user
before_filter :initialize_cookies
layout "default"
@@ -27,24 +28,29 @@ protected
def set_current_user
if session[:user_id]
@current_user = User.find_by_id(session[:user_id])
CurrentUser.user = User.find_by_id(session[:user_id])
CurrentUser.ip_addr = request.remote_ip
end
if @current_user
if @current_user.is_banned? && @current_user.ban && @current_user.ban.expires_at < Time.now
@current_user.update_attribute(:is_banned, false)
Ban.destroy_all("user_id = #{@current_user.id}")
if CurrentUser.user
if CurrentUser.user.is_banned? && CurrentUser.user.ban && CurrentUser.user.ban.expires_at < Time.now
CurrentUser.user.unban!
end
else
@current_user = AnonymousUser.new
CurrentUser.user = AnonymousUser.new
end
Time.zone = @current_user.time_zone
Time.zone = CurrentUser.user.time_zone
end
def reset_current_user
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
%w(member banned privileged contributor janitor moderator admin).each do |level|
define_method("#{level}_only") do
if @current_user.__send__("is_#{level}?")
if CurrentUser.user.__send__("is_#{level}?")
true
else
access_denied()
@@ -53,10 +59,10 @@ protected
end
def initialize_cookies
if @current_user.is_anonymous?
if CurrentUser.user.is_anonymous?
cookies["blacklisted_tags"] = ""
else
cookies["blacklisted_tags"] = @current_user.blacklisted_tags
cookies["blacklisted_tags"] = CurrentUser.user.blacklisted_tags
end
end
end

View File

@@ -1,11 +1,16 @@
class ArtistsController < ApplicationController
def new
@artist = Artist.new_with_defaults(params)
end
def edit
@artist = Artist.find(params[:id])
end
def index
order = params[:order] == "date" ? "updated_at DESC" : "name"
limit = params[:limit] || 50
@artists = Artist.paginate(Artist.build_relation())
end
def show

View File

@@ -2,6 +2,7 @@ class CommentsController < ApplicationController
respond_to :html, :xml, :json
def index
@posts = Post.paginate :order => "last_commented_at DESC", :per_page => 8
end
def update

View File

@@ -1,7 +1,15 @@
class FavoritesController < ApplicationController
def create
@favorite = Favorite.create(
:user_id => @current_user.id,
:post_id => params[:favorite][:post_id]
)
end
def destroy
Favorite.destroy(
:user_id => @current_user.id,
:post_id => params[:favorite][:post_id]
)
end
end