Class: Auth::CustomerPasswordsController

Inherits:
Devise::PasswordsController
  • Object
show all
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

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.

Parameters:

  • _resource (Account)

    the account whose password was reset (unused)

Returns:

  • (String)

    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 

  @devise_return_path.presence || 
end

#after_sending_reset_password_instructions_path_for(resource_name) ⇒ String (protected)

Returns where to land after sending reset-password instructions.

Parameters:

  • resource_name (Symbol)

    the Devise resource name (:account)

Returns:

  • (String)

    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.

Yields:

  • (resource)


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
   = params.dig(:account, :login)
  @account = begin
    Account.where(login: ).first || Account.where(email: ).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

#newvoid

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. = params[:login].presence if resource.respond_to?(:login=)
end

#set_report_errors_forObject (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.

Yields:

  • (resource)


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 
      flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
      set_flash_message!(:notice, flash_message)
      resource.after_database_authentication
      (resource_name, resource)
    else
      set_flash_message!(: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