Class: Clearance::PasswordsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- Clearance::PasswordsController
- Defined in:
- app/controllers/clearance/passwords_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #deliver_email(user) ⇒ Object private
- #edit ⇒ Object
- #email_from_password_params ⇒ Object private
- #ensure_existing_user ⇒ Object private
- #find_user_by_id_and_confirmation_token ⇒ Object private
- #find_user_for_create ⇒ Object private
- #find_user_for_edit ⇒ Object private
- #find_user_for_update ⇒ Object private
- #flash_failure_after_update ⇒ Object private
- #flash_failure_when_forbidden ⇒ Object private
- #new ⇒ Object
- #password_from_password_reset_params ⇒ Object private
- #update ⇒ Object
- #url_after_update ⇒ Object private
Instance Method Details
#create ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'app/controllers/clearance/passwords_controller.rb', line 11 def create if user = find_user_for_create user.forgot_password! deliver_email(user) end render template: "passwords/create" end |
#deliver_email(user) ⇒ Object (private)
46 47 48 49 |
# File 'app/controllers/clearance/passwords_controller.rb', line 46 def deliver_email(user) mail = ::ClearanceMailer.change_password(user) mail.deliver_later end |
#edit ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/clearance/passwords_controller.rb', line 20 def edit @user = find_user_for_edit if params[:token] session[:password_reset_token] = params[:token] redirect_to url_for else render template: "passwords/edit" end end |
#email_from_password_params ⇒ Object (private)
63 64 65 |
# File 'app/controllers/clearance/passwords_controller.rb', line 63 def email_from_password_params params.dig(:password, :email) end |
#ensure_existing_user ⇒ Object (private)
80 81 82 83 84 85 |
# File 'app/controllers/clearance/passwords_controller.rb', line 80 def ensure_existing_user unless find_user_by_id_and_confirmation_token flash_failure_when_forbidden render template: "passwords/new" end end |
#find_user_by_id_and_confirmation_token ⇒ Object (private)
55 56 57 58 59 60 61 |
# File 'app/controllers/clearance/passwords_controller.rb', line 55 def find_user_by_id_and_confirmation_token user_param = Clearance.configuration.user_id_parameter token = params[:token] || session[:password_reset_token] Clearance.configuration.user_model. find_by_id_and_confirmation_token params[user_param], token.to_s end |
#find_user_for_create ⇒ Object (private)
67 68 69 70 |
# File 'app/controllers/clearance/passwords_controller.rb', line 67 def find_user_for_create Clearance.configuration.user_model. find_by_normalized_email(email_from_password_params) end |
#find_user_for_edit ⇒ Object (private)
72 73 74 |
# File 'app/controllers/clearance/passwords_controller.rb', line 72 def find_user_for_edit find_user_by_id_and_confirmation_token end |
#find_user_for_update ⇒ Object (private)
76 77 78 |
# File 'app/controllers/clearance/passwords_controller.rb', line 76 def find_user_for_update find_user_by_id_and_confirmation_token end |
#flash_failure_after_update ⇒ Object (private)
93 94 95 96 97 |
# File 'app/controllers/clearance/passwords_controller.rb', line 93 def flash_failure_after_update flash.now[:alert] = translate(:blank_password, scope: [:clearance, :controllers, :passwords], default: t("flashes.failure_after_update")) end |
#flash_failure_when_forbidden ⇒ Object (private)
87 88 89 90 91 |
# File 'app/controllers/clearance/passwords_controller.rb', line 87 def flash_failure_when_forbidden flash.now[:alert] = translate(:forbidden, scope: [:clearance, :controllers, :passwords], default: t("flashes.failure_when_forbidden")) end |
#new ⇒ Object
7 8 9 |
# File 'app/controllers/clearance/passwords_controller.rb', line 7 def new render template: "passwords/new" end |
#password_from_password_reset_params ⇒ Object (private)
51 52 53 |
# File 'app/controllers/clearance/passwords_controller.rb', line 51 def password_from_password_reset_params params.dig(:password_reset, :password) end |
#update ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/clearance/passwords_controller.rb', line 31 def update @user = find_user_for_update if @user.update_password(password_from_password_reset_params) sign_in @user redirect_to url_after_update session[:password_reset_token] = nil else flash_failure_after_update render template: "passwords/edit" end end |
#url_after_update ⇒ Object (private)
99 100 101 |
# File 'app/controllers/clearance/passwords_controller.rb', line 99 def url_after_update Clearance.configuration.redirect_url end |