secure the controller up a bit
parent
33d4a7f0fc
commit
3240ba032d
|
@ -1,6 +1,6 @@
|
||||||
class Users < Application
|
class Users < Application
|
||||||
before :fetch_allowed_user, :only => [ :show, :edit, :update, :delete ]
|
before :fetch_allowed_user, :only => [ :edit, :update, :destroy ]
|
||||||
before :prepare_user, :only => [ :show, :edit, :update, :delete ]
|
before :administrator?, :only => [ :destroy ]
|
||||||
|
|
||||||
include Ambethia::ReCaptcha::Controller
|
include Ambethia::ReCaptcha::Controller
|
||||||
|
|
||||||
|
@ -13,10 +13,6 @@ class Users < Application
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
|
||||||
render
|
|
||||||
end
|
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@user = User.new
|
@user = User.new
|
||||||
render
|
render
|
||||||
|
@ -39,27 +35,23 @@ class Users < Application
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
@user.attributes = params[:user] if params[:user]
|
||||||
if @user.save
|
if @user.save
|
||||||
flash[:notice] = 'Great success'
|
flash[:notice] = 'Great success'
|
||||||
redirect url(:users)
|
redirect '/'
|
||||||
else
|
else
|
||||||
render :edit
|
render :edit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete
|
def destroy
|
||||||
|
raise NotAllowed unless request.xhr?
|
||||||
if @user.destroy
|
if @user.destroy
|
||||||
flash[:notice] = "Epic failure, goodbye #{@user.user_name}"
|
flash[:notice] = "Epic failure, goodbye #{@user.user_name}"
|
||||||
reset_session if @user.id == session[:user_id]
|
reset_session if @user.id == session[:user_id]
|
||||||
else
|
else
|
||||||
flash[:error] = 'That does not work...'
|
flash[:error] = 'That did not work...'
|
||||||
end
|
end
|
||||||
redirect url(:users)
|
redirect url(:users)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def prepare_user
|
|
||||||
@user.attributes = params[:user] if params[:user] and request.post?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue