Class: AdminController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_new_userObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/admin_controller.rb', line 12

def add_new_user
  if params[:user]
    pwd = SecureRandom.hex(8) # user will need to use the "forgot password" feature to set a useful password
    options = {:username => params[:user][:username], :email => params[:user][:email], :password => pwd, :password_confirmation => pwd, :role => User.user_role} if params[:user]
    user = User.new(options)
    unless user.save
      @error_message = user.errors.full_messages.map{|s| s}.join('<br />') if user.errors
      @error_message ||= t(:cannot_save_new_user, :scope => 'myinfo.errors.messages')
    end
  else
    @error_message ||= t(:cannot_save_new_user, :scope => 'myinfo.errors.messages')
  end
  @users = User.order("role,username")
  respond_to do |format|
    format.html { redirect_to admin_path }
    format.js { render :layout=>false }
  end
end

#delete_userObject


40
41
42
43
44
45
46
47
48
# File 'app/controllers/admin_controller.rb', line 40

def delete_user   
  @user = User.find(params[:id])
  @user.destroy if current_user.is_admin?
  @users = User.order("role,username")
  respond_to do |format|
    format.html { redirect_to admin_path }
    format.js { render :layout=>false }
  end
end

#indexObject


8
9
10
# File 'app/controllers/admin_controller.rb', line 8

def index
  @users = User.order("role,username")
end

#update_userObject


31
32
33
34
35
36
37
38
# File 'app/controllers/admin_controller.rb', line 31

def update_user
  @user = User.find(params[:id])
  @user.update_attributes(params[:user])
  respond_to do |format|
      format.html { redirect_to admin_path }
      format.json { respond_with_bip(@user) }
  end
end