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 and redirect to sign in.
- #fb_deny_access(flash_message = nil) ⇒ Object
-
#sign_in(user, fb_token = nil, token_expiration = nil) ⇒ 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.
53 54 55 56 57 58 59 |
# File 'lib/clearance/authentication.rb', line 53 def authenticate if user_from_fb? then #Manage different authentication if its a FB user fb_deny_access unless authenticated_fbu? #Created a special deny access when a FB user loggout else deny_access unless signed_in? end end |
#current_user ⇒ User?
User in the current cookie
24 25 26 |
# File 'lib/clearance/authentication.rb', line 24 def current_user @_current_user ||= end |
#current_user=(user) ⇒ Object
Set the current user
31 32 33 |
# File 'lib/clearance/authentication.rb', line 31 def current_user=(user) @_current_user = user end |
#deny_access(flash_message = nil) ⇒ Object
Store the current location and redirect to sign in. Display a failure flash message if included.
98 99 100 101 102 |
# File 'lib/clearance/authentication.rb', line 98 def deny_access( = nil) store_location flash[:failure] = if redirect_to(sign_in_url) end |
#fb_deny_access(flash_message = nil) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/clearance/authentication.rb', line 104 def fb_deny_access( = nil) store_location flash[:failure] = if redirect_to FB_CLOSED_URL end |
#sign_in(user, fb_token = nil, token_expiration = nil) ⇒ Object
Sign user in to cookie.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/clearance/authentication.rb', line 67 def sign_in(user, fb_token = nil, token_expiration = nil) if user [:remember_token] = { :value => user.remember_token, :expires => 1.year.from_now.utc } if !user.fbid.blank? then [:fb_token] = { :value => fb_token, :expires => token_expiration.to_i.seconds.from_now.utc } end self.current_user = user end end |
#sign_out ⇒ Object
Sign user out of cookie.
87 88 89 90 91 92 |
# File 'lib/clearance/authentication.rb', line 87 def sign_out current_user.reset_remember_token! if current_user .delete(:remember_token) .delete(:fb_token) self.current_user = nil end |
#signed_in? ⇒ true, false
Is the current user signed in?
38 39 40 |
# File 'lib/clearance/authentication.rb', line 38 def signed_in? ! current_user.nil? end |
#signed_out? ⇒ true, false
Is the current user signed out?
45 46 47 |
# File 'lib/clearance/authentication.rb', line 45 def signed_out? current_user.nil? end |