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