Class: Auth::CustomerPasswordsController

Inherits:
Devise::PasswordsController
  • Object
show all
Includes:
Controllers::DeviseReturnable
Defined in:
app/controllers/auth/customer_passwords_controller.rb

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) ⇒ Object (protected)



55
56
57
58
59
# File 'app/controllers/auth/customer_passwords_controller.rb', line 55

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) ⇒ Object (protected)



61
62
63
64
65
66
67
# File 'app/controllers/auth/customer_passwords_controller.rb', line 61

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| ... } ⇒ Object

Yields:

  • (resource)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/auth/customer_passwords_controller.rb', line 13

def create
   = params.dig(:account, :login)
  @account = Account.where(login: ).first || Account.where(email: ).first rescue nil
  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_entity, formats: :html
  end
end

#newObject



8
9
10
11
# File 'app/controllers/auth/customer_passwords_controller.rb', line 8

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.



70
71
72
# File 'app/controllers/auth/customer_passwords_controller.rb', line 70

def set_report_errors_for
 @report_errors_for = [resource]
end

#update {|resource| ... } ⇒ Object

Yields:

  • (resource)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/auth/customer_passwords_controller.rb', line 32

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_entity, formats: :html
  end
end