Class: RailsBase::Mfa::Totp::Remove
- Inherits:
-
ServiceBase
- Object
- ServiceBase
- RailsBase::Mfa::Totp::Remove
- Includes:
- Helper
- Defined in:
- app/services/rails_base/mfa/totp/remove.rb
Instance Method Summary collapse
Methods included from Helper
#current_code, #lgp, #otp, #secret
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
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/rails_base/mfa/totp/remove.rb', line 11 def call password_result = RailsBase::Authentication::AuthenticateUser.(email: user.email, current_user: user, password: password) if password_result.failure? log(level: :debug, msg: "#{lgp} Password validation failed. Unable to continue") context.fail!(message: password_result.) end valid_code = ValidateCode.(user: user, otp_code: otp_code) if valid_code.failure? log(level: :debug, msg: "#{lgp} Code Validation failed.") context.fail!(message: "#{valid_code.}. Please try again.") end begin user.reset_otp! log(level: :info, msg: "#{lgp} TOTP successfully removed from User Account") rescue => e context.fail!(message: "Yikes! Unknown error occured. TOTP was not removed from the account.") end end |
#validate! ⇒ Object
33 34 35 36 37 |
# File 'app/services/rails_base/mfa/totp/remove.rb', line 33 def validate! raise "Expected user to be a User." unless User === user raise "Expected otp_code to be present" if otp_code.nil? raise "Expected password to be present" if password.nil? end |