Skip to content

Instantly share code, notes, and snippets.

@simianhacker
Created May 27, 2009 06:29
Show Gist options
  • Save simianhacker/118487 to your computer and use it in GitHub Desktop.
Save simianhacker/118487 to your computer and use it in GitHub Desktop.
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
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
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