Class: Admin::UsersController

Inherits:
BaseController
  • Object
show all
Defined in:
vendor/plugins/authentication/app/controllers/admin/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'vendor/plugins/authentication/app/controllers/admin/users_controller.rb', line 18

def create
  @user = User.new(params[:user])
  @selected_plugin_titles = params[:user][:plugins] || []

  if @user.save
    @user.plugins = @selected_plugin_titles
    @user.register!
    @user.activate!
    flash[:notice] = "'#{@user.}' was successfully created."
    redirect_to :action => 'index'
  else
    render :action => 'new'
  end
end

#editObject



33
34
35
36
# File 'vendor/plugins/authentication/app/controllers/admin/users_controller.rb', line 33

def edit
  @user = User.find params[:id]
  @selected_plugin_titles = @user.plugins.collect{|p| p.title}
end

#newObject



13
14
15
16
# File 'vendor/plugins/authentication/app/controllers/admin/users_controller.rb', line 13

def new
  @user = User.new
  @selected_plugin_titles = []
end

#updateObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'vendor/plugins/authentication/app/controllers/admin/users_controller.rb', line 38

def update
  @selected_plugin_titles = params[:user][:plugins]
  # Prevent the current user from locking themselves out of the User manager
  if current_user.id == @user.id and !params[:user][:plugins].include?("Users")
    flash.now[:error] = "You cannot remove the 'Users' plugin from the currently logged in account."
    render :action => "edit"
  else
    @previously_selected_plugins_titles = @user.plugins.collect{|p| p.title}
    if @user.update_attributes params[:user]
      flash[:notice] = "'#{@user.}' was successfully updated."
      redirect_to admin_users_url
    else
      @user.plugins = @previously_selected_plugins_titles
      @user.save
      render :action => 'edit'
    end
  end
end