Class: Cms::UsersController

Inherits:
ResourceController show all
Defined in:
app/controllers/cms/users_controller.rb

Instance Method Summary collapse

Methods inherited from ResourceController

#create, #destroy, #edit, #new, #show, #update

Methods included from PageHelper

#able_to?, #cms_toolbar, #container, #container_has_block?, #current_page, #page_title, #render_breadcrumbs, #render_portlet

Methods included from PathHelper

#cms_connectable_path, #cms_index_path_for, #cms_index_url_for, #cms_new_path_for, #cms_new_url_for, #edit_cms_connectable_path

Methods included from ErrorHandling

#handle_access_denied, #handle_server_error, included

Instance Method Details

#change_passwordObject



38
39
40
# File 'app/controllers/cms/users_controller.rb', line 38

def change_password
  user
end

#disableObject



51
52
53
54
55
56
57
58
59
# File 'app/controllers/cms/users_controller.rb', line 51

def disable
  begin
    user.disable!
    flash[:notice] = "User #{user.} disabled"
  rescue Exception => e
    flash[:error] = e.message
  end
  redirect_to cms_users_path
end

#enableObject



61
62
63
64
# File 'app/controllers/cms/users_controller.rb', line 61

def enable
  user.enable!
  redirect_to cms_users_path
end

#indexObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/cms/users_controller.rb', line 13

def index
  query, conditions = [], []
  
  unless params[:show_expired]
    query << "expires_at IS NULL OR expires_at >= ?"
    conditions << Time.now.utc
  end

  unless params[:key_word].blank?
    query << %w(login email first_name last_name).collect { |f| "lower(#{f}) LIKE lower(?)" }.join(" OR ")
    4.times { conditions << "%#{params[:key_word]}%" }
  end
  
  unless params[:group_id].to_i == 0
    query << "user_group_memberships.group_id = ?"
    conditions << params[:group_id]
  end
  
  query.collect! { |q| "(#{q})"}
  conditions = conditions.unshift(query.join(" AND "))
  per_page = params[:per_page] || 10
  
  @users = User.paginate(:page => params[:page], :per_page => per_page, :include => :user_group_memberships, :conditions => conditions, :order => "first_name, last_name, email")
end

#update_passwordObject



42
43
44
45
46
47
48
49
# File 'app/controllers/cms/users_controller.rb', line 42

def update_password
  if user.update_attributes(params[:user])
    flash[:notice] = "Password for '#{user.}' was changed"
    redirect_to(current_user.able_to?(:administrate) ? cms_users_path : cms_user_path(user))
  else
    render :action => 'change_password'
  end
end