Module: Headstart::Authentication::InstanceMethods
- Defined in:
- lib/headstart/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.
- #get_full_app_path ⇒ Object
- #impersonating? ⇒ Boolean
-
#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.
61 62 63 |
# File 'lib/headstart/authentication.rb', line 61 def authenticate deny_access unless signed_in? end |
#current_user ⇒ User?
User in the current cookie
32 33 34 |
# File 'lib/headstart/authentication.rb', line 32 def current_user @_current_user ||= end |
#current_user=(user) ⇒ Object
Set the current user
39 40 41 |
# File 'lib/headstart/authentication.rb', line 39 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.
95 96 97 98 99 |
# File 'lib/headstart/authentication.rb', line 95 def deny_access( = nil) store_location flash[:failure] = if redirect_to(sign_in_url) end |
#get_full_app_path ⇒ Object
25 26 27 |
# File 'lib/headstart/authentication.rb', line 25 def get_full_app_path return "http://" + APP_CONFIG[:domain] end |
#impersonating? ⇒ Boolean
101 102 103 |
# File 'lib/headstart/authentication.rb', line 101 def impersonating? !session[:admin_user_id].blank? end |
#sign_in(user) ⇒ Object
Sign user in to cookie.
71 72 73 74 75 76 77 78 79 |
# File 'lib/headstart/authentication.rb', line 71 def sign_in(user) if user [:remember_token] = { :value => user.remember_token, :expires => 1.year.from_now.utc } self.current_user = user end end |
#sign_out ⇒ Object
Sign user out of cookie.
85 86 87 88 89 |
# File 'lib/headstart/authentication.rb', line 85 def sign_out current_user.reset_remember_token! if current_user .delete(:remember_token) self.current_user = nil end |
#signed_in? ⇒ true, false
Is the current user signed in?
46 47 48 |
# File 'lib/headstart/authentication.rb', line 46 def signed_in? ! current_user.nil? end |
#signed_out? ⇒ true, false
Is the current user signed out?
53 54 55 |
# File 'lib/headstart/authentication.rb', line 53 def signed_out? current_user.nil? end |