Created
December 20, 2010 00:42
-
-
Save mthomas/747878 to your computer and use it in GitHub Desktop.
warden.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.configuration.middleware.use RailsWarden::Manager do |manager| | |
manager.default_strategies :password | |
manager.failure_app = SessionsController | |
end | |
# Setup Session Serialization | |
class Warden::SessionSerializer | |
def serialize(user) | |
user.id | |
end | |
def deserialize(key) | |
User.find(key) | |
end | |
end | |
# Declare your strategies here | |
Warden::Strategies.add(:password) do | |
def valid? | |
params["session"]["email"] || params["session"]["password"] | |
end | |
def authenticate! | |
u = User.authenticate(params["session"]["email"], params["session"]["password"]) | |
u.nil? ? fail!("could not log in") : success!(u) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment