Class: ResetPasswordService

Inherits:
Trailblazer::Operation
  • Object
show all
Extended by:
Trailblazer::Operation::Contract::DSL
Defined in:
app/services/reset_password_service.rb

Overview

responsible to sending email reset password

Instance Method Summary collapse

Instance Method Details

#find_user!(options) ⇒ Object



20
21
22
23
24
25
# File 'app/services/reset_password_service.rb', line 20

def find_user!(options, *)
  params = (options['params'] || options[:params]).with_indifferent_access
  options['user'] = ::User.find_by(email: params['email'])
  return false if options['user'].blank?
  true
end

#generate_new_password!(options) ⇒ Object



27
28
29
30
# File 'app/services/reset_password_service.rb', line 27

def generate_new_password!(options, *)
  options['new_password'] = ('0'..'z').to_a.sample(8).join
  true
end

#reset_password!(options) ⇒ Object



32
33
34
35
# File 'app/services/reset_password_service.rb', line 32

def reset_password!(options, *)
  new_password = options['new_password']
  options['user'].reset_password(new_password, new_password)
end

#send_email_notification!(options) ⇒ Object



37
38
39
40
# File 'app/services/reset_password_service.rb', line 37

def send_email_notification!(options, *)
  new_password = options['new_password']
  ::UserMailer.notify_new_password(options['user'].to_json, new_password).deliver_later!
end

#send_sms_notification!(options) ⇒ Object



42
43
44
45
# File 'app/services/reset_password_service.rb', line 42

def send_sms_notification!(options, *)
  new_password = options['new_password']
  ::SmsWorker.notify_password_changed(new_password, options['user'].phone)
end

#user_not_found!(options) ⇒ Object



47
48
49
50
51
# File 'app/services/reset_password_service.rb', line 47

def user_not_found!(options, *)
  options['result.error_messages'] = ['Email not found']
  options['result.error_message'] = options['result.error_messages'].to_sentence
  true
end