Class: Management::UsersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Management::UsersController
- Defined in:
- app/controllers/management/users_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #disable ⇒ Object
- #edit ⇒ Object
- #enable ⇒ Object
-
#index ⇒ Object
user list.
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/management/users_controller.rb', line 16 def create @usr = User.new @usr.username = params[:user][:username] @usr.first_name = params[:user][:first_name] @usr.last_name = params[:user][:last_name] @usr.email_address = params[:user][:email_address] @usr.password = params[:user][:password] @usr.password_confirmation = params[:user][:password_confirmation] @usr.active = true if request.post? if @usr.save flash[:notice] = "User created successfully. Please check the boxes below to set this user's permissions, then click Save when you are done." redirect_to action: 'edit', id: @usr.id else flash.now[:error] = @usr.errors..join('; ') render :action => 'new' end end end |
#destroy ⇒ Object
92 93 94 95 96 97 |
# File 'app/controllers/management/users_controller.rb', line 92 def destroy @usr = User.find(params[:id]) flash[:notice] = @usr.username + ' has been removed from the system.' @usr.destroy redirect_to :action => 'index' end |
#disable ⇒ Object
76 77 78 79 80 81 82 |
# File 'app/controllers/management/users_controller.rb', line 76 def disable @usr = User.find(params[:id]) @usr.active = false @usr.save flash[:notice] = 'Login privileges have been suspended for ' + @usr.username + '.' redirect_to :action => 'index' end |
#edit ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/controllers/management/users_controller.rb', line 37 def edit unless (:manage_users) || @user.id == params[:id].to_i render plain: "Sorry, you don't have permission to access this section.", layout: true and return false end @usr = User.find(params[:id]) end |
#enable ⇒ Object
84 85 86 87 88 89 90 |
# File 'app/controllers/management/users_controller.rb', line 84 def enable @usr = User.find(params[:id]) @usr.active = true @usr.save flash[:notice] = 'Login privileges for ' + @usr.username + ' have been restored.' redirect_to :action => 'index' end |
#index ⇒ Object
user list
8 9 10 |
# File 'app/controllers/management/users_controller.rb', line 8 def index @usrs = User.order('active desc, username').all end |
#new ⇒ Object
12 13 14 |
# File 'app/controllers/management/users_controller.rb', line 12 def new @usr = User.new end |
#update ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/management/users_controller.rb', line 45 def update @usr = User.find(params[:id]) unless (:manage_users) || @user.id == @usr.id render plain: "Sorry, you don't have permission to access this section.", layout: true and return false end if (:manage_users) params[:user].each { |k,v| @usr.send("#{k}=", v) } elsif @user.id == @usr.id @usr.first_name = params[:user][:first_name] @usr.last_name = params[:user][:last_name] @usr.email_address = params[:user][:email_address] @usr.password = params[:user][:password] @usr.password_confirmation = params[:user][:password_confirmation] end if @usr.save if (:manage_users) flash[:notice] = 'User updated successfully. Please note that the user must log out and log back in for permission changes to take effect.' redirect_to action: 'index' else flash[:notice] = 'Account updated successfully.' redirect_to controller: '/management/default', action: 'index' end else flash.now[:error] = @usr.errors..join('; ') render action: 'edit' end end |