2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Users
|
|
|
|
class ValidateOtpService < BaseService
|
2021-02-22 17:27:13 +05:30
|
|
|
include ::Gitlab::Auth::Otp::Fortinet
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def initialize(current_user)
|
|
|
|
@current_user = current_user
|
2021-02-22 17:27:13 +05:30
|
|
|
@strategy = if forti_authenticator_enabled?(current_user)
|
2021-01-03 14:25:43 +05:30
|
|
|
::Gitlab::Auth::Otp::Strategies::FortiAuthenticator.new(current_user)
|
2021-02-22 17:27:13 +05:30
|
|
|
elsif forti_token_cloud_enabled?(current_user)
|
|
|
|
::Gitlab::Auth::Otp::Strategies::FortiTokenCloud.new(current_user)
|
2021-01-03 14:25:43 +05:30
|
|
|
else
|
|
|
|
::Gitlab::Auth::Otp::Strategies::Devise.new(current_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(otp_code)
|
|
|
|
strategy.validate(otp_code)
|
|
|
|
rescue StandardError => ex
|
|
|
|
Gitlab::ErrorTracking.log_exception(ex)
|
|
|
|
error(message: ex.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :strategy
|
|
|
|
end
|
|
|
|
end
|