Created
June 7, 2010 11:32
-
-
Save ukstudio/428563 to your computer and use it in GitHub Desktop.
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 | |
| class Warden::SessionSerializer | |
| def serialize(record) | |
| [record.class, record.id] | |
| end | |
| def deserialize(keys) | |
| klass, id = keys | |
| klass.find(:first, :conditions => { :id => id }) | |
| end | |
| end | |
| Warden::Strategies.add(:password) do | |
| def valid? | |
| params.has_key?(:password) && params.has_key?(:login) | |
| end | |
| def authenticate! | |
| u = User.authenticate(params[:login],params[:password]) | |
| u.nil? ? fail("Could not login") : success!(u) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment