blob: 7bd908597c94b9d6a6b7eca8cead6056a97dde8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# frozen_string_literal: true
# Concern that overrides the Devise methods to allow reset password instructions
# to be sent to any users' confirmed secondary emails.
# See https://github.com/heartcombo/devise/blob/main/lib/devise/models/recoverable.rb
module RecoverableByAnyEmail
extend ActiveSupport::Concern
class_methods do
def send_reset_password_instructions(attributes = {})
return super unless attributes[:email]
email = Email.confirmed.find_by(email: attributes[:email].to_s)
return super unless email
recoverable = email.user
recoverable.send_reset_password_instructions(to: email.email)
recoverable
end
end
def send_reset_password_instructions(opts = {})
token = set_reset_password_token
send_reset_password_instructions_notification(token, opts)
token
end
protected
def send_reset_password_instructions_notification(token, opts = {})
send_devise_notification(:reset_password_instructions, token, opts)
end
end
|