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_content_editor, #cms_toolbar, #container, #container_has_block?, #current_page, #page_title, #render_breadcrumbs, #render_portlet

Methods included from PathHelper

#attachment_path_for, #cms_connectable_path, #cms_index_path_for, #cms_index_url_for, #cms_new_path_for, #cms_new_url_for, #cms_sortable_column_path, #edit_cms_connectable_path, #engine_for, #link_to_usages, #path_elements_for

Methods included from ErrorHandling

#handle_access_denied, #handle_server_error, #with_format

Instance Method Details

#change_passwordObject


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

def change_password
  user
end

#disableObject


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

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

#enableObject


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

def enable
  user.enable!
  redirect_to users_path
end

#indexObject

verify :method => :put, :only => [ :enable, :disable, :update_password ]


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

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 << "#{UserGroupMembership.table_name}.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


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

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