Module: DeviseOtpAuthenticatable::Hooks::Sessions

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

Instance Method Summary collapse

Methods included from Controllers::UrlHelpers

#otp_credential_path_for, #otp_token_path_for, #persistence_otp_token_path_for, #recovery_otp_token_for, #refresh_otp_credential_path_for

Instance Method Details

#create_with_otpObject

replaces Devise::SessionsController#create



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/devise_otp_authenticatable/hooks/sessions.rb', line 13

def create_with_otp

  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 => otp_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 => otp_token_path_for(resource)
  else

    set_flash_message(:notice, :signed_in) if is_navigational_format?
    (resource_name, resource)
    respond_with resource, :location => (resource)
  end
end