Class: Caseadilla::UsersController

Inherits:
CaseadillaController show all
Defined in:
app/controllers/caseadilla/users_controller.rb

Instance Method Summary collapse

Methods inherited from CaseadillaController

#blank

Methods included from ConfigHelper

#caseadilla_config_dashboard_url, #caseadilla_config_email_from_address, #caseadilla_config_hostname, #caseadilla_config_javascript_includes, #caseadilla_config_logo, #caseadilla_config_stylesheet_includes, #caseadilla_config_website_name

Methods included from CaseadillaHelper

#caseadilla_check_box, #caseadilla_check_box_group, #caseadilla_collection_check_boxes, #caseadilla_collection_select, #caseadilla_color_field, #caseadilla_custom_field, #caseadilla_date_field, #caseadilla_date_select, #caseadilla_datetime_field, #caseadilla_datetime_local_field, #caseadilla_datetime_select, #caseadilla_email_field, #caseadilla_file_field, #caseadilla_format_date, #caseadilla_format_datetime, #caseadilla_format_time, #caseadilla_generate_page_title, #caseadilla_get_access_level_array, #caseadilla_get_access_level_text, #caseadilla_get_footer_string, #caseadilla_get_full_version_string, #caseadilla_get_short_version_string, #caseadilla_hidden_field, #caseadilla_month_field, #caseadilla_no_yes_label, #caseadilla_number_field, #caseadilla_pagination_details, #caseadilla_password_field, #caseadilla_radio_button, #caseadilla_radio_button_group, #caseadilla_range_field, #caseadilla_search_field, #caseadilla_select, #caseadilla_show_icon, #caseadilla_show_row_icon, #caseadilla_sort_link, #caseadilla_table_cell_link, #caseadilla_table_cell_no_link, #caseadilla_telephone_field, #caseadilla_text_area, #caseadilla_text_area_wysiwym, #caseadilla_text_field, #caseadilla_time_field, #caseadilla_time_select, #caseadilla_time_zone_select, #caseadilla_url_field, #caseadilla_week_field, #caseadilla_yes_no_label

Instance Method Details

#change_passwordObject

This action not related to update_password action


56
57
58
59
# File 'app/controllers/caseadilla/users_controller.rb', line 56

def change_password
  @caseadilla_user = User.find params[:id]
  @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Change password"
end

#createObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/caseadilla/users_controller.rb', line 21

def create

  generate_random_password if params[:generate_random_password]

  @caseadilla_user = User.new caseadilla_user_params

  if @caseadilla_user.save
    flash[:notice] = "An email has been sent to " + @caseadilla_user.first_name + " with the new account details"
    redirect_to caseadilla_users_path
  else
    flash.now[:warning] = "There were problems when trying to create a new user"
    render :action => :new
  end
end

#destroyObject


104
105
106
107
108
109
# File 'app/controllers/caseadilla/users_controller.rb', line 104

def destroy
  user = User.find params[:id]
  user.destroy
  flash[:notice] = "#{user.first_name} #{user.last_name} has been deleted"
  redirect_to caseadilla_users_path
end

#indexObject

before_filter :needs_admin, :except => [:show, :destroy, :update, :update_password] before_filter :needs_or_current_user, :only => [:show, :destroy, :update, :update_password]


10
11
12
13
# File 'app/controllers/caseadilla/users_controller.rb', line 10

def index
  @caseadilla_page_title = "Users"
  @users = User.order(sort_order(:id)).paginate :page => params[:page]
end

#newObject


15
16
17
18
19
# File 'app/controllers/caseadilla/users_controller.rb', line 15

def new
  @caseadilla_page_title = "Add a new user"
	@caseadilla_user = User.new
	@caseadilla_user.time_zone = Rails.configuration.time_zone
end

#reset_passwordObject


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/caseadilla/users_controller.rb', line 80

def reset_password
  @caseadilla_user = User.find params[:id]
  @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Reset password"
   
  if params[:generate_random_password].blank? && params[:caseadilla_user][:password].blank? && params[:caseadilla_user][:password_confirmation].blank?
    flash[:warning] = "New password cannot be blank"
  else
    generate_random_password if params[:generate_random_password]
    @caseadilla_user.notify_of_new_password = true unless (@caseadilla_user.id == @session_user.id && params[:generate_random_password].blank?)

    if @caseadilla_user.update_attributes caseadilla_user_params
      unless @caseadilla_user.notify_of_new_password
        flash[:notice] = "Your password has been reset"
      else    
        flash[:notice] = "Password has been reset and #{@caseadilla_user.first_name} #{@caseadilla_user.last_name} has been notified by email"
      end
    else
      flash[:warning] = "There were problems when trying to reset this user's password"
    end
  end

  redirect_to :action => :show
end

#showObject


36
37
38
39
# File 'app/controllers/caseadilla/users_controller.rb', line 36

def show
	@caseadilla_user = User.find params[:id]
	@caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > View user"
end

#updateObject


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/caseadilla/users_controller.rb', line 41

def update
  @caseadilla_user = User.find params[:id]
  @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Update user"

  if @caseadilla_user.update_attributes caseadilla_user_params
    flash[:notice] = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} has been updated"
    redirect_to action: :index
  else
    flash.now[:warning] = "There were problems when trying to update this user"
    render :action => :show
    return
  end
end

#update_passwordObject


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/caseadilla/users_controller.rb', line 61

def update_password
  @caseadilla_user = User.find params[:id]
  @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Update password"
   
  if @caseadilla_user.valid_password? params[:form_current_password]
    if params[:caseadilla_user][:password].blank? && params[:caseadilla_user][:password_confirmation].blank?
      flash[:warning] = "New password cannot be blank"
    elsif @caseadilla_user.update_attributes caseadilla_user_params
      flash[:notice] = "Your password has been changed"
    else
      flash[:warning] = "There were problems when trying to change your password"
    end
  else
    flash[:warning] = "The current password is incorrect"
  end
  
  redirect_to :action => :show
end