Class: DeviseCodeAuthenticatable::Strategies::CodeAuthenticatable

Inherits:
Devise::Strategies::Authenticatable
  • Object
show all
Defined in:
lib/devise_code_authenticatable/strategies/code_authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/devise_code_authenticatable/strategies/code_authenticatable.rb', line 7

def authenticate!
  resource = mapping.to.find_for_authentication(authentication_hash)
   = params[scope].fetch "login_code", ""

  if resource.nil?
    fail(:not_found_in_database); return
  end

  if resource..empty?
    fail(:login_code_expired); return
  end

  if resource..last.expired?
    resource.
    fail(:login_code_expired); return
  end

  if validate(resource){ resource..last.verify() }
    remember_me(resource)
    yield resource if block_given?
    resource.after_code_authentication
    success!(resource)
  else
    fail(:invalid_login_code)
  end
end