Sha256: 30f2a0c3f3bd6fedbda5021928c8b127c9126ad61d87bc5943bb9505f4d6ee00
Contents?: true
Size: 1.63 KB
Versions: 2
Compression:
Stored size: 1.63 KB
Contents
class RememberMe < Merb::Authentication::Strategy # Called from #current_user. Finaly, attempt to login by an expiring token in the cookie. # for the paranoid: we _should_ be storing user_token = hash(cookie_token, request IP) def run! current_user = cookies[:auth_token] && Merb::Authentication.user_class.first(:conditions => ["remember_token = ?", cookies[:auth_token]]) if current_user && current_user.remember_token? handle_remember_cookie! false # freshen cookie token (keeping date) current_user end end def current_user @current_user end def current_user=(new_user) @current_user = new_user end # # Remember_me Tokens # # Cookies shouldn't be allowed to persist past their freshness date, # and they should be changed at each login # Cookies shouldn't be allowed to persist past their freshness date, # and they should be changed at each login def valid_remember_cookie? return nil unless current_user (current_user.remember_token?) && (cookies[:auth_token] == current_user.remember_token) end # Refresh the cookie auth token if it exists, create it otherwise def handle_remember_cookie! new_cookie_flag return unless current_user case when valid_remember_cookie? then current_user.refresh_token # keeping same expiry date when new_cookie_flag then current_user.remember_me else current_user.forget_me end send_remember_cookie! end def send_remember_cookie! cookies.set_cookie(:auth_token, current_user.remember_token, :expires => current_user.remember_token_expires_at.to_time) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
scottmotte-merb-auth-remember-me-0.1.3.2 | lib/merb-auth-remember-me/strategies/remember_me.rb |
scottmotte-merb-auth-remember-me-0.2 | lib/merb-auth-remember-me/strategies/remember_me.rb |