This repository has been archived on 2020-05-27. You can view files and clone it, but cannot push or open issues/pull-requests.
binaryattraction/app/controllers/users.rb

72 lines
1.4 KiB
Ruby
Raw Normal View History

2008-10-01 02:19:35 -04:00
class Users < Application
before :prepare_user, :only => [ :show, :edit, :update, :delete ]
include Ambethia::ReCaptcha::Controller
def index
if current_user.administrator?
@users = User.find :all, :order => 'user_name ASC'
render
else
redirect url(:user, :id => current_user.user_name)
end
end
def show
render
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
if @user.save
flash[:notice] = 'Great success'
redirect url(:users)
else
render :edit
end
end
def delete
if @user.destroy
flash[:notice] = "Epic failure, goodbye #{@user.user_name}"
reset_session if @user.id == session[:user_id]
else
flash[:error] = 'That does not work...'
end
redirect url(:users)
end
protected
def prepare_user
@user = if current_user.administrator?
User.find_by_user_name params[:id]
else
current_user
end
raise NotFound if @user.nil?
@user.attributes = params[:user] if params[:user] and request.post?
true
end
end