Class: Devise::Strategies::TwoFactorAuthenticatable

Inherits:
DatabaseAuthenticatable
  • Object
show all
Defined in:
lib/devise_two_factor/strategies/two_factor_authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/devise_two_factor/strategies/two_factor_authenticatable.rb', line 5

def authenticate!
  resource = mapping.to.find_for_database_authentication(authentication_hash)
  # We authenticate in two cases:
  # 1. The password and the OTP are correct
  # 2. The password is correct, and OTP is not required for login
  # We check the OTP, then defer to DatabaseAuthenticatable
  if validate(resource) { validate_otp(resource) }
    super
  end

  fail(Devise.paranoid ? :invalid : :not_found_in_database) unless resource

  # We want to cascade to the next strategy if this one fails,
  # but database authenticatable automatically halts on a bad password
  @halted = false if @result == :failure
end

#validate_otp(resource) ⇒ Object



22
23
24
25
26
# File 'lib/devise_two_factor/strategies/two_factor_authenticatable.rb', line 22

def validate_otp(resource)
  return true unless resource.
  return if params[scope]['otp_attempt'].nil?
  resource.validate_and_consume_otp!(params[scope]['otp_attempt'])
end