summaryrefslogtreecommitdiff
path: root/app/services/users/validate_otp_service.rb
blob: c8a9f217d22620dc7d48e3e6769699f3e2bd9b79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module Users
  class ValidateOtpService < BaseService
    include ::Gitlab::Auth::Otp::Fortinet

    def initialize(current_user)
      @current_user = current_user
      @strategy = if forti_authenticator_enabled?(current_user)
                    ::Gitlab::Auth::Otp::Strategies::FortiAuthenticator.new(current_user)
                  elsif forti_token_cloud_enabled?(current_user)
                    ::Gitlab::Auth::Otp::Strategies::FortiTokenCloud.new(current_user)
                  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