Class: Protected::Admin::UsersController

Inherits:
ProtectedController show all
Defined in:
app/controllers/protected/admin/users_controller.rb

Instance Method Summary collapse

Methods inherited from Protected::ApplicationController

#pagination_params, #set_cache_buster

Instance Method Details

#createObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/protected/admin/users_controller.rb', line 36

def create
  @user = User.new
  if params[:user].present?
    @user.is_admin = params[:user][:is_admin]
    params[:user].delete(:is_admin)
  end
  @user.attributes = params[:user]
  @user.random_password
  if @user.save
    flash[:success] = "User #{@user.name} created successfully."
    redirect_to ['admin','users']
  else
    render :action => :new
  end
rescue Errno::ETIMEDOUT
  @user.errors.add(:base, I18n.t('devise.failure.user.service_error'))
  render :action => :new
end

#destroyObject



25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/protected/admin/users_controller.rb', line 25

def destroy
  unless @user == current_user
    @user.destroy
    flash[:success] = "The user was deleted"
    redirect_to ['admin','users']
  else
    flash[:error] = "The user could not be deleted"
    redirect_to ['admin',@user]
  end
end

#indexObject



5
6
7
# File 'app/controllers/protected/admin/users_controller.rb', line 5

def index
  @users = User.paginate(pagination_params)
end

#newObject



9
10
11
12
# File 'app/controllers/protected/admin/users_controller.rb', line 9

def new
  @user = User.new
  @user.is_admin = false
end

#unlockObject



55
56
57
58
59
# File 'app/controllers/protected/admin/users_controller.rb', line 55

def unlock
  @user.unlock_access!
  flash[:success] = "User's account has been unlocked"
  redirect_to admin_users_url
end

#updateObject



14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/protected/admin/users_controller.rb', line 14

def update
  @user.is_admin = params[:user][:is_admin] unless current_user == @user
  params[:user].delete(:is_admin)
  if @user.update_without_password(params[:user])
    flash[:success] = "User #{@user.name} updated successfully."
    redirect_to admin_users_url
  else
    render :action => 'edit'
  end
end