Class: Authengine::UsersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Authengine::UsersController
- Defined in:
- app/controllers/authengine/users_controller.rb
Overview
Besides the ususal REST actions, this controller contains show_self, edit_self and update_self actions. This permits access to be explicitly controlled via the check_permissions filter, distinguishing between actions on one’s own model vs. actions on other users’ models.
Instance Method Summary collapse
-
#activate ⇒ Object
account was created by admin and now user is entering username/password.
-
#create ⇒ Object
users may only be created by the administrator from the index page.
- #destroy ⇒ Object
- #disable ⇒ Object
-
#edit ⇒ Object
edit a user profile with id given.
-
#edit_self ⇒ Object
edit profile of current user.
- #enable ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #show_self ⇒ Object
- #signup ⇒ Object
- #update ⇒ Object
- #update_self ⇒ Object
Instance Method Details
#activate ⇒ Object
account was created by admin and now user is entering username/password
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/authengine/users_controller.rb', line 58 def activate # TODO must remember to reset the session[:activation_code] # looks as if setting current user (next line) was causing the user to be # logged-in after activation user = User.find_and_activate!(params[:activation_code]) if user.update_attributes(params[:user].slice(:login, :email, :password, :password_confirmation)) redirect_to root_path else flash[:warn] = user.errors. redirect_to signup_authengine_user_path(user) end rescue User::ArgumentError flash[:notice] = 'Activation code not found. Please ask the database administrator to create an account for you.' redirect_to new_authengine_user_path rescue User::ActivationCodeNotFound flash[:notice] = 'Activation code not found. Please ask the database administrator to create an account for you.' redirect_to new_authengine_user_path rescue User::AlreadyActivated flash[:notice] = 'Your account has already been activated. You can log in below.' redirect_to login_path end |
#create ⇒ Object
users may only be created by the administrator from the index page
37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/authengine/users_controller.rb', line 37 def create .delete :auth_token @user = User.new(params[:user]) @user.save! redirect_to authengine_users_path rescue ActiveRecord::RecordInvalid flash[:error] = "There was a problem creating the user account." @roles=Role.all render :action => 'new' end |
#destroy ⇒ Object
101 102 103 104 105 |
# File 'app/controllers/authengine/users_controller.rb', line 101 def destroy @user = User.find(params[:id]) @user.destroy redirect_to authengine_users_path end |
#disable ⇒ Object
107 108 109 110 111 112 113 |
# File 'app/controllers/authengine/users_controller.rb', line 107 def disable @user = User.find(params[:id]) unless @user.update_attribute(:enabled, false) flash[:error] = "There was a problem disabling this user." end redirect_to authengine_users_path end |
#edit ⇒ Object
edit a user profile with id given
48 49 50 |
# File 'app/controllers/authengine/users_controller.rb', line 48 def edit # edit a user profile with id given @user = User.find(params[:id]) end |
#edit_self ⇒ Object
edit profile of current user
52 53 54 55 |
# File 'app/controllers/authengine/users_controller.rb', line 52 def edit_self # edit profile of current user @user = current_user render :template => 'users/edit' end |
#enable ⇒ Object
115 116 117 118 119 120 121 |
# File 'app/controllers/authengine/users_controller.rb', line 115 def enable @user = User.find(params[:id]) unless @user.update_attribute(:enabled, true) flash[:error] = "There was a problem enabling this user." end redirect_to authengine_users_path end |
#index ⇒ Object
17 18 19 |
# File 'app/controllers/authengine/users_controller.rb', line 17 def index @users = User.find(:all, :order=>"lastName, firstName") end |
#new ⇒ Object
30 31 32 33 34 |
# File 'app/controllers/authengine/users_controller.rb', line 30 def new @user = User.new @user.user_roles.build @roles = Role.all end |
#show ⇒ Object
21 22 23 |
# File 'app/controllers/authengine/users_controller.rb', line 21 def show @user = User.find(params[:id]) end |
#show_self ⇒ Object
25 26 27 28 |
# File 'app/controllers/authengine/users_controller.rb', line 25 def show_self @user = current_user render :template=>"users/show" end |
#signup ⇒ Object
123 124 125 |
# File 'app/controllers/authengine/users_controller.rb', line 123 def signup @user = User.find(params[:id]) end |
#update ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/authengine/users_controller.rb', line 91 def update @user = User.find(params[:id]) if @user.update_attributes(params[:user]) flash[:notice] = "User updated" redirect_to authengine_users_path else render :action => 'edit' end end |
#update_self ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/authengine/users_controller.rb', line 80 def update_self @user = User.find(current_user.id) if @user.update_attributes(params[:user]) flash[:notice] = "Your profile has been updated" redirect_to authengine_users_path else flash[:notice] = @user.errors. render :action => 'edit' end end |