class Users < Application before :fetch_allowed_user, :only => [ :edit, :update, :destroy ] before :administrator?, :only => [ :destroy ] 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 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 @user.attributes = params[:user] if params[:user] if @user.save flash[:notice] = 'Great success' redirect '/' else render :edit end end def destroy raise NotAllowed unless request.xhr? if @user.destroy flash[:notice] = "Epic failure, goodbye #{@user.user_name}" reset_session if @user.id == session[:user_id] else flash[:error] = 'That did not work...' end redirect url(:users) end end