Class: RailsBase::Mfa::Sms::Remove

Inherits:
ServiceBase show all
Defined in:
app/services/rails_base/mfa/sms/remove.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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/rails_base/mfa/sms/remove.rb', line 11

def call
  password_result = RailsBase::Authentication::AuthenticateUser.(email: current_user.email, current_user: current_user, password: password)
  if password_result.failure?
    log(level: :debug, msg: "Password validation failed. Unable to continue")
    context.fail!(message: password_result.message)
  end

  validate_code = Validate.(mfa_event:,sms_code:, session_mfa_user_id:, current_user:)

  if validate_code.failure?
    log(level: :warn, msg: "Unable to confirm SMS OTP code. Will not remove")
    context.fail!(message: "Incorrect One Time Password Code")
  end

  current_user.update!(mfa_sms_enabled: false, last_mfa_sms_login: nil)
end

#validate!Object



28
29
30
31
32
33
# File 'app/services/rails_base/mfa/sms/remove.rb', line 28

def validate!
  raise 'Expected the current_user passed' if current_user.nil?
  raise 'Expected the sms_code passed' if sms_code.nil?
  raise 'session_mfa_user_id is not present' if session_mfa_user_id.nil?
  raise 'password is not present' if password.nil?
end