Class: RailsBase::Authentication::SendForgotPassword

Inherits:
ServiceBase
  • Object
show all
Defined in:
app/services/rails_base/authentication/send_forgot_password.rb

Instance Method Summary collapse

Methods inherited from ServiceBase

inherited, #internal_validate, #service_base_logging

Methods included from ServiceLogging

#aletered_message, #class_name, #log, #log_prefix, #logger, #service_id

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/rails_base/authentication/send_forgot_password.rb', line 5

def call
  user = User.find_for_authentication(email: email)
  if user.nil?
    log(level: :warn, msg: "Failed to find email assocaited to #{email}. Not sending email")
    context.fail!(message: "Failed to send forget password to #{email}", redirect_url: '')
  end
  email_send = SendVerificationEmail.call(user: user, reason: Constants::VFP_REASON)

  if email_send.failure?
    log(level: :error, msg: "Failed to send forget password: #{email_send.message}")
    context.fail!(message: email_send.message, redirect_url: '/')
  end

  context.message = 'You should receive an email shortly.'
end

#validate!Object



21
22
23
# File 'app/services/rails_base/authentication/send_forgot_password.rb', line 21

def validate!
  raise "Expected email to be a String. Received #{email.class}" unless email.is_a? String
end