Class: ResetPasswordService
- Inherits:
-
Trailblazer::Operation
- Object
- Trailblazer::Operation
- ResetPasswordService
- 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
- #find_user!(options) ⇒ Object
- #generate_new_password!(options) ⇒ Object
- #reset_password!(options) ⇒ Object
- #send_email_notification!(options) ⇒ Object
- #send_sms_notification!(options) ⇒ Object
- #user_not_found!(options) ⇒ Object
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!(, *) params = (['params'] || [:params]).with_indifferent_access ['user'] = ::User.find_by(email: params['email']) return false if ['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!(, *) ['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!(, *) new_password = ['new_password'] ['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!(, *) new_password = ['new_password'] ::UserMailer.notify_new_password(['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!(, *) new_password = ['new_password'] ::SmsWorker.notify_password_changed(new_password, ['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!(, *) ['result.error_messages'] = ['Email not found'] ['result.error_message'] = ['result.error_messages'].to_sentence true end |