Class: ForestLiana::LoginHandler

Inherits:
Object
  • Object
show all
Defined in:
app/services/forest_liana/login_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(rendering_id, auth_data, use_google_authentication, two_factor_registration, project_id, two_factor_token) ⇒ LoginHandler

Returns a new instance of LoginHandler.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/forest_liana/login_handler.rb', line 5

def initialize(
  rendering_id,
  auth_data,
  use_google_authentication,
  two_factor_registration,
  project_id,
  two_factor_token
)
  @rendering_id = rendering_id
  @auth_data = auth_data
  @use_google_authentication = use_google_authentication
  @two_factor_registration = two_factor_registration
  @project_id = project_id
  @two_factor_token = two_factor_token
end

Instance Method Details

#performObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/forest_liana/login_handler.rb', line 21

def perform
  user = ForestLiana::AuthorizationGetter.new(
    @rendering_id,
    @use_google_authentication,
    @auth_data,
    @two_factor_registration
  ).perform

  if user['two_factor_authentication_enabled']
    if !@two_factor_token.nil?
      if is_two_factor_token_valid(user, @two_factor_token)
        ForestLiana::TwoFactorRegistrationConfirmer
          .new(@project_id, @use_google_authentication, @auth_data)
          .perform

        return { 'token' => create_token(user, @rendering_id) }
      else
        raise ForestLiana::Errors::HTTP401Error.new('Your token is invalid, please try again.')
      end
    else
      return get_two_factor_response(user)
    end
  end

  return { token: create_token(user, @rendering_id) }
end