Class: Auth::CustomerPasswordsController
- Inherits:
-
Devise::PasswordsController
- Object
- Devise::PasswordsController
- Auth::CustomerPasswordsController
- Includes:
- Controllers::DeviseReturnable
- Defined in:
- app/controllers/auth/customer_passwords_controller.rb
Overview
Controller: customer passwords.
Constant Summary
Constants included from Controllers::DeviseReturnable
Controllers::DeviseReturnable::ALLOWED_REDIRECT_HOSTS
Instance Method Summary collapse
-
#after_resetting_password_path_for(_resource) ⇒ String
protected
Where to land after a successful password reset.
-
#after_sending_reset_password_instructions_path_for(resource_name) ⇒ String
protected
Where to land after sending reset-password instructions.
-
#create {|resource| ... } ⇒ void
POST /accounts/password — sends reset-password instructions.
-
#new ⇒ void
GET /accounts/password/new — forgot-password form, pre-filling
loginwhen passed as a query param. -
#set_report_errors_for ⇒ Object
protected
This controller instance set the model to use for detecting errors in the application_controller#write_flash_to_cookie method.
-
#update {|resource| ... } ⇒ void
PUT /accounts/password — resets the password using the emailed token.
Methods included from Controllers::DeviseReturnable
#check_for_devise_return_path, #devise_return_path_from_omniauth_hash, #safe_referer
Instance Method Details
#after_resetting_password_path_for(_resource) ⇒ String (protected)
Returns where to land after a successful password reset.
73 74 75 76 77 |
# File 'app/controllers/auth/customer_passwords_controller.rb', line 73 def after_resetting_password_path_for(_resource) return new_session_path(resource_name) unless sign_in_after_reset_password? @devise_return_path.presence || my_account_path end |
#after_sending_reset_password_instructions_path_for(resource_name) ⇒ String (protected)
Returns where to land after sending reset-password instructions.
81 82 83 84 85 86 87 |
# File 'app/controllers/auth/customer_passwords_controller.rb', line 81 def after_sending_reset_password_instructions_path_for(resource_name) if @devise_return_path.present? new_session_path(resource_name, devise_return_path: @devise_return_path) else new_session_path(resource_name) end end |
#create {|resource| ... } ⇒ void
This method returns an undefined value.
POST /accounts/password — sends reset-password instructions.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/auth/customer_passwords_controller.rb', line 22 def create login = params.dig(:account, :login) @account = begin Account.where(login: login).first || Account.where(email: login).first rescue StandardError nil end self.resource = resource_class.send_reset_password_instructions(resource_params) yield resource if block_given? if successfully_sent?(resource) # Devise uses respond_with({}, location: …). With Turbo Stream, responders ignore # that location and fall back to GET /accounts/password, which has no route and # becomes a CMS 404 (production.log: PagesController#show id "accounts/password"). redirect_to after_sending_reset_password_instructions_path_for(resource_name) else # Turbo sends Accept: text/vnd.turbo-stream.html; respond_with would render HTML with a # turbo-stream MIME type and 200 — Turbo does not apply that as a full-page validation # response, so users see no errors. Force HTML + 422 so Turbo Drive updates the page. render :new, status: :unprocessable_content, formats: :html end end |
#new ⇒ void
This method returns an undefined value.
GET /accounts/password/new — forgot-password form, pre-filling login
when passed as a query param.
14 15 16 17 |
# File 'app/controllers/auth/customer_passwords_controller.rb', line 14 def new super resource.login = params[:login].presence if resource.respond_to?(:login=) end |
#set_report_errors_for ⇒ Object (protected)
This controller instance set the model to use for detecting errors in the application_controller#write_flash_to_cookie method.
90 91 92 |
# File 'app/controllers/auth/customer_passwords_controller.rb', line 90 def set_report_errors_for @report_errors_for = [resource] end |
#update {|resource| ... } ⇒ void
This method returns an undefined value.
PUT /accounts/password — resets the password using the emailed token.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/auth/customer_passwords_controller.rb', line 48 def update self.resource = resource_class.reset_password_by_token(resource_params) yield resource if block_given? if resource.errors.empty? resource.unlock_access! if unlockable?(resource) if sign_in_after_reset_password? = resource.active_for_authentication? ? :updated : :updated_not_active (:notice, ) resource.after_database_authentication sign_in(resource_name, resource) else (:notice, :updated_not_active) end redirect_to after_resetting_password_path_for(resource) else set_minimum_password_length render :edit, status: :unprocessable_content, formats: :html end end |