2008-10-01 02:19:35 -04:00
|
|
|
class Users < Application
|
2008-10-17 02:03:21 -04:00
|
|
|
before :fetch_allowed_user, :only => [ :edit, :update, :destroy ]
|
|
|
|
before :administrator?, :only => [ :destroy ]
|
2008-10-01 02:19:35 -04:00
|
|
|
|
|
|
|
include Ambethia::ReCaptcha::Controller
|
|
|
|
|
|
|
|
def index
|
2008-12-04 23:47:20 -05:00
|
|
|
if logged_in? and current_user.administrator?
|
2008-11-26 12:57:50 -05:00
|
|
|
@users = User.find :all, :order => 'user_name ASC', :conditions => 'facebook_id IS NULL'
|
2008-10-01 02:19:35 -04:00
|
|
|
render
|
|
|
|
else
|
|
|
|
redirect url(:user, :id => current_user.user_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@user = User.new
|
|
|
|
render
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@user = User.new params[:user]
|
|
|
|
@user.user_name = params[:user][:user_name] rescue nil
|
|
|
|
if verify_recaptcha(@user) and @user.save
|
|
|
|
flash[:notice] = 'Great success'
|
|
|
|
redirect '/'
|
|
|
|
else
|
|
|
|
flash[:error] = 'The user could not be created...'
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
render
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2008-10-17 02:03:21 -04:00
|
|
|
@user.attributes = params[:user] if params[:user]
|
2008-10-01 02:19:35 -04:00
|
|
|
if @user.save
|
|
|
|
flash[:notice] = 'Great success'
|
2008-10-17 02:03:21 -04:00
|
|
|
redirect '/'
|
2008-10-01 02:19:35 -04:00
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-17 02:03:21 -04:00
|
|
|
def destroy
|
|
|
|
raise NotAllowed unless request.xhr?
|
2008-10-01 02:19:35 -04:00
|
|
|
if @user.destroy
|
|
|
|
flash[:notice] = "Epic failure, goodbye #{@user.user_name}"
|
|
|
|
reset_session if @user.id == session[:user_id]
|
|
|
|
else
|
2008-10-17 02:03:21 -04:00
|
|
|
flash[:error] = 'That did not work...'
|
2008-10-01 02:19:35 -04:00
|
|
|
end
|
|
|
|
redirect url(:users)
|
|
|
|
end
|
2008-10-17 18:17:42 -04:00
|
|
|
|
|
|
|
def validate_anonymous_user
|
|
|
|
if logged_in? or valid_anonymous_user?
|
|
|
|
flash[:notice] = 'You are already good, doofus.'
|
|
|
|
redirect '/'
|
|
|
|
elsif request.post? and !verify_recaptcha
|
|
|
|
flash.now[:error] = 'That does not work. Try again.'
|
|
|
|
render
|
|
|
|
elsif request.post?
|
|
|
|
valid_anonymous_user!
|
|
|
|
flash[:notice] = 'Great success!'
|
|
|
|
redirect url(:new_vote)
|
|
|
|
else
|
|
|
|
render
|
|
|
|
end
|
|
|
|
end
|
2008-10-01 02:19:35 -04:00
|
|
|
end
|