2010-03-29 14:52:34 -04:00
|
|
|
require 'devise/strategies/authenticatable'
|
2009-12-07 17:26:00 -05:00
|
|
|
|
2009-10-18 09:15:23 -04:00
|
|
|
module Devise
|
|
|
|
module Strategies
|
2010-03-29 17:44:47 -04:00
|
|
|
# Default strategy for signing in a user, based on his email and password in the database.
|
2010-03-29 14:52:34 -04:00
|
|
|
class DatabaseAuthenticatable < Authenticatable
|
2009-10-18 09:15:23 -04:00
|
|
|
def authenticate!
|
2010-05-16 08:13:43 -04:00
|
|
|
resource = valid_password? && mapping.to.find_for_database_authentication(authentication_hash)
|
2010-03-29 17:44:47 -04:00
|
|
|
|
|
|
|
if validate(resource){ resource.valid_password?(password) }
|
2010-04-06 07:26:56 -04:00
|
|
|
resource.after_database_authentication
|
2009-11-21 21:49:23 -05:00
|
|
|
success!(resource)
|
2009-10-18 09:15:23 -04:00
|
|
|
else
|
2010-03-28 06:52:05 -04:00
|
|
|
fail(:invalid)
|
2009-10-18 09:15:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-10-22 15:24:14 -04:00
|
|
|
|
2010-03-29 10:13:19 -04:00
|
|
|
Warden::Strategies.add(:database_authenticatable, Devise::Strategies::DatabaseAuthenticatable)
|