Class: RailsBase::Authentication::SsoVerifyEmail

Inherits:
ServiceBase
  • Object
show all
Defined in:
app/services/rails_base/authentication/sso_verify_email.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



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

def call
  datum = get_short_lived_datum(verification)
  validate_datum?(datum)

  user = datum[:user]
  user.update(email_validated: true)

  context.user = datum[:user]
  params = {
    expires_at: Time.zone.now + Constants::SVE_TTL,
    user: user,
    purpose: Constants::SSOVE_PURPOSE
  }
  context.encrypted_val = RailsBase::Mfa::EncryptToken.(params).encrypted_val
end

#get_short_lived_datum(mfa_code) ⇒ Object



37
38
39
# File 'app/services/rails_base/authentication/sso_verify_email.rb', line 37

def get_short_lived_datum(mfa_code)
  ShortLivedData.find_datum(data: mfa_code, reason: Constants::)
end

#validate!Object



41
42
43
# File 'app/services/rails_base/authentication/sso_verify_email.rb', line 41

def validate!
  raise "verification is expected" if verification.nil?
end

#validate_datum?(datum) ⇒ Boolean



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/rails_base/authentication/sso_verify_email.rb', line 23

def validate_datum?(datum)
  return true if datum[:valid]

  if datum[:found]
    msg = "Errors with Email Verification: #{datum[:invalid_reason].join(", ")}. Please login again"
    log(level: :warn, msg: msg)
    context.fail!(message: msg, redirect_url: Constants::URL_HELPER.new_user_session_path, level: :warn)
  end

  log(level: :warn, msg: "Could not find MFA code. Incorrect Email verification code. User may be doing Fishyyyyy things")

  context.fail!(message: "Invalid Email Verification Code. Log in again.", redirect_url: Constants::URL_HELPER.new_user_session_path, level: :warn)
end