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
2010-03-03 12:03:42 +01:00

36 lines
1 KiB
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 < Base
def valid?
valid_controller? && valid_params? && mapping.to.respond_to?(:authenticate)
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
protected
def valid_controller?
mapping.controllers[:sessions] == params[:controller]
end
def valid_params?
params[scope] && params[scope][:password].present?
end
end
end
end
Warden::Strategies.add(:authenticatable, Devise::Strategies::Authenticatable)