Class: PreferencesController

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

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#admin_login_required, #all_done_todos_for, #boolean_param, cas_enabled?, #cas_enabled?, #check_for_deprecated_password_hash, #count_deferred_todos, #count_undone_todos, #count_undone_todos_phrase, #done_todos_for, #enable_mobile_content_negotiation, #for_autocomplete, #format_date, #format_dependencies_as_json_for_auto_complete, #handle_unverified_request, #init_data_for_sidebar, #init_not_done_counts, #init_project_hidden_todo_counts, #mobile?, #notify, openid_enabled?, #openid_enabled?, #parse_date_per_user_prefs, prefered_auth?, #prefered_auth?, #redirect_back_or_home, #render_failure, #sanitize, #set_charset, #set_group_view_by, #set_locale, #set_session_expiration, #set_time_zone, #set_zindex_counter, #todo_xml_params

Methods included from LoginSystem

#access_denied, #authorize?, #basic_auth_denied, #current_user, #get_basic_auth_data, #get_current_user, #logged_in?, #login_from_cookie, #login_optional, #login_or_feed_token_required, #login_required, #logout_user, #prefs, #protect?, #redirect_back_or_default, #redirect_to_login, #set_current_user, #store_location

Instance Method Details

- (Object) index



3
4
5
6
7
# File 'app/controllers/preferences_controller.rb', line 3

def index
  @page_title = t('preferences.page_title')
  @prefs = current_user.prefs
  @user = current_user
end

- (Object) preference_updated (private)

Display notification if preferences are successful updated



51
52
53
54
# File 'app/controllers/preferences_controller.rb', line 51

def preference_updated
  notify :notice, t('preferences.updated')
  redirect_to :action => 'index'
end

- (Object) prefs_params (private)



36
37
38
39
40
41
42
43
44
# File 'app/controllers/preferences_controller.rb', line 36

def prefs_params
  params.require(:prefs).permit(
    :date_format, :week_starts, :show_number_completed, 
    :show_completed_projects_in_sidebar, :show_hidden_contexts_in_sidebar, 
    :staleness_starts, :due_style, :locale, :title_date_format, :time_zone, 
    :show_hidden_projects_in_sidebar, :show_project_on_todo_done, 
    :review_period, :refresh, :verbose_action_descriptors, 
    :mobile_todos_per_page, :sms_email, :sms_context_id)
end

- (Object) render_date_format



29
30
31
32
# File 'app/controllers/preferences_controller.rb', line 29

def render_date_format
  format = params[:date_format]
  render :text => l(Date.today, :format => format)
end

- (Object) update



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/preferences_controller.rb', line 9

def update
  @prefs = current_user.prefs
  @user = current_user
  user_updated = current_user.update_attributes(user_params)
  prefs_updated = current_user.preference.update_attributes(prefs_params)
  if (user_updated && prefs_updated)
    if params['user']['password'].present? # password updated?
      logout_user t('preferences.password_changed')
    else
      preference_updated
    end
  else
    msg = "Preferences could not be updated: "
    msg += "User model errors; " unless user_updated
    msg += "Prefs model errors; " unless prefs_updated
    notify :warning, msg
    render 'index'
  end
end

- (Object) user_params (private)



46
47
48
# File 'app/controllers/preferences_controller.rb', line 46

def user_params
  params.require(:user).permit(:login, :first_name, :last_name, :password_confirmation, :password, :auth_type, :open_id_url)
end