Created
May 27, 2009 06:29
-
-
Save simianhacker/118487 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
| class Application < Merb::Controller | |
| before :check_remember_me | |
| def check_remember_me | |
| unless session.authenticated? | |
| if cookies[:auth_token] | |
| if user = User.first(:auth_token=>cookies[:auth_token]) | |
| if user.valid_token? | |
| session.user = user | |
| end | |
| else | |
| cookies.delete(:auth_token) | |
| end | |
| end | |
| end | |
| end | |
| end |
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
| class Merb::Authentication | |
| def abandon! | |
| Merb::logger.debug("Abondoning the authentication!") | |
| if session.user | |
| session.user.auth_token = nil | |
| session.user.token_expires_on = Time.new() - 86400 * 14 | |
| session.user.save() | |
| end | |
| @user = nil | |
| session.clear | |
| end | |
| end |
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
| Merb::Authentication.after_authentication do |user,request,params| | |
| if params["remember_me"].to_i == 1 | |
| token = user.make_token | |
| request.cookies.set_cookie(:auth_token,user.auth_token,{:expires=>user.token_expires_on.to_time}) | |
| end | |
| user | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment