Module: Clearance::Authentication::InstanceMethods
- Defined in:
- lib/clearance/authentication.rb
Instance Method Summary collapse
-
#authenticate ⇒ Object
Deny the user access if they are signed out.
-
#current_user ⇒ User?
User in the current cookie.
-
#current_user=(user) ⇒ Object
Set the current user.
-
#deny_access(flash_message = nil) ⇒ Object
Store the current location.
-
#sign_in(user) ⇒ Object
Sign user in to cookie.
-
#sign_out ⇒ Object
Sign user out of cookie.
-
#signed_in? ⇒ true, false
Is the current user signed in?.
-
#signed_out? ⇒ true, false
Is the current user signed out?.
Instance Method Details
#authenticate ⇒ Object
Deny the user access if they are signed out.
46 47 48 |
# File 'lib/clearance/authentication.rb', line 46 def authenticate deny_access unless signed_in? end |
#current_user ⇒ User?
User in the current cookie
17 18 19 |
# File 'lib/clearance/authentication.rb', line 17 def current_user @_current_user ||= end |
#current_user=(user) ⇒ Object
Set the current user
24 25 26 |
# File 'lib/clearance/authentication.rb', line 24 def current_user=(user) @_current_user = user end |
#deny_access(flash_message = nil) ⇒ Object
Store the current location. Display a flash message if included. Redirect to sign in.
81 82 83 84 85 |
# File 'lib/clearance/authentication.rb', line 81 def deny_access( = nil) store_location flash[:failure] = if redirect_to(new_session_url) end |
#sign_in(user) ⇒ Object
Sign user in to cookie.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/clearance/authentication.rb', line 56 def sign_in(user) if user user.remember_me! [:remember_token] = { :value => user.remember_token, :expires => 1.year.from_now.utc } current_user = user end end |
#sign_out ⇒ Object
Sign user out of cookie.
71 72 73 74 |
# File 'lib/clearance/authentication.rb', line 71 def sign_out .delete(:remember_token) current_user = nil end |
#signed_in? ⇒ true, false
Is the current user signed in?
31 32 33 |
# File 'lib/clearance/authentication.rb', line 31 def signed_in? ! current_user.nil? end |
#signed_out? ⇒ true, false
Is the current user signed out?
38 39 40 |
# File 'lib/clearance/authentication.rb', line 38 def signed_out? current_user.nil? end |