Module: DeviseTwoFactorable::Hooks::Sessions

Extended by:
ActiveSupport::Concern
Includes:
Controllers::UrlHelpers
Defined in:
lib/devise_two_factorable/hooks/sessions.rb

Instance Method Summary collapse

Methods included from Controllers::UrlHelpers

#credential_path_for, #persistence_token_path_for, #recovery_token_for, #refresh_credential_path_for, #token_path_for

Instance Method Details

#createObject

replaces Devise::SessionsController#create



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/devise_two_factorable/hooks/sessions.rb', line 8

def create
  resource = warden.authenticate!(auth_options)

  devise_stored_location = stored_location_for(resource) # Grab the current stored location before it gets lost by warden.logout

  otp_refresh_credentials_for(resource)

  if otp_challenge_required_on?(resource)
    challenge = resource.generate_otp_challenge!
    warden.logout
    store_location_for(resource, devise_stored_location) # restore the stored location
    respond_with resource, location: credential_path_for(resource, challenge: challenge)
  elsif otp_mandatory_on?(resource) # if mandatory, log in user but send him to the must activate otp
    set_flash_message(:notice, :signed_in_but_otp) if is_navigational_format?
    (resource_name, resource)
    respond_with resource, location: token_path_for(resource)
  else
    super
  end
end