Module: Auth::Behavior::RememberMe::ControllerExtensions
- Defined in:
- lib/auth/behavior/remember_me/controller_extensions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate_current_user_with_remembrance ⇒ Object
- #authenticate_with_remembrance_token ⇒ Object
- #handle_remembrance_token_theft(token) ⇒ Object
-
#login_with_remembrance!(user, options = {}) ⇒ Object
If a :remember option is given, a remembrance cookie will be set.
-
#logout_with_remembrance!(options = {}) ⇒ Object
If a :forget option is given, the remembrance cookie will also be deleted.
- #set_remembrance_token_cookie(token) ⇒ Object
Class Method Details
.included(base) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/auth/behavior/remember_me/controller_extensions.rb', line 52 def self.included(base) base.class_eval do hide_action :login_with_remembrance!, :login_without_remembrance!, :authenticate_current_user_without_remembrance, :authenticate_current_user_with_remembrance, :authenticate_with_remembrance_token, :set_remembrance_token_cookie, :handle_remembrance_token_theft, :logout_with_remembrance!, :logout_without_remembrance! unless method_defined?(:login_without_remembrance!) alias_method_chain :login!, :remembrance alias_method_chain :logout!, :remembrance alias_method_chain :authenticate_current_user, :remembrance end end end |
Instance Method Details
#authenticate_current_user_with_remembrance ⇒ Object
20 21 22 23 24 25 |
# File 'lib/auth/behavior/remember_me/controller_extensions.rb', line 20 def authenticate_current_user_with_remembrance authenticate_current_user_without_remembrance if @current_user == false authenticate_with_remembrance_token end end |
#authenticate_with_remembrance_token ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/auth/behavior/remember_me/controller_extensions.rb', line 27 def authenticate_with_remembrance_token if token_value = [:remembrance_token] token = RemembranceToken.find_by_value(token_value) if token @current_user = token.authenticatable handle_remembrance_token_theft(token) if token.theft? token.regenerate token.save (token) end end end |
#handle_remembrance_token_theft(token) ⇒ Object
40 41 42 43 |
# File 'lib/auth/behavior/remember_me/controller_extensions.rb', line 40 def handle_remembrance_token_theft(token) flash[:error] = Auth.remember_me. token.authenticatable.remembrance_tokens.destroy_all end |
#login_with_remembrance!(user, options = {}) ⇒ Object
If a :remember option is given, a remembrance cookie will be set. If omitted, the cookie will be, too.
3 4 5 6 7 8 9 10 |
# File 'lib/auth/behavior/remember_me/controller_extensions.rb', line 3 def login_with_remembrance!(user, = {}) login_without_remembrance!(user) if [:remember] token = RemembranceToken.create!(:authenticatable => user) (token) end end |
#logout_with_remembrance!(options = {}) ⇒ Object
If a :forget option is given, the remembrance cookie will also be deleted.
13 14 15 16 17 18 |
# File 'lib/auth/behavior/remember_me/controller_extensions.rb', line 13 def logout_with_remembrance!( = {}) logout_without_remembrance! if [:forget] .delete(:remembrance_token) end end |
#set_remembrance_token_cookie(token) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/auth/behavior/remember_me/controller_extensions.rb', line 45 def (token) [:remembrance_token] = { :value => token.value, :expires => Auth.remember_me.duration.from_now } end |