1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
heartcombo--devise/lib/devise/strategies/authenticatable.rb
2009-12-07 20:26:00 -02:00

28 lines
860 B
Ruby

require 'devise/strategies/base'
module Devise
module Strategies
# Default strategy for signing in a user, based on his email and password.
# Redirects to sign_in page if it's not authenticated
class Authenticatable < Warden::Strategies::Base
include Devise::Strategies::Base
def valid?
super && params[scope] && params[scope][:password].present?
end
# Authenticate a user based on email and password params, returning to warden
# success and the authenticated user if everything is okay. Otherwise redirect
# to sign in page.
def authenticate!
if resource = mapping.to.authenticate(params[scope])
success!(resource)
else
fail!(:invalid)
end
end
end
end
end
Warden::Strategies.add(:authenticatable, Devise::Strategies::Authenticatable)