Module: SimpleAuth::Authentication::InstanceMethods
- Defined in:
- lib/simple_auth/authentication.rb
Instance Method Summary collapse
-
#authenticate ⇒ Object
Deny the user access if they are signed out.
- #current_permission(invoice = nil) ⇒ Object
-
#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.
-
#permission_exist? ⇒ true, false
Is exist permission and invoice.
-
#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.
76 77 78 |
# File 'lib/simple_auth/authentication.rb', line 76 def authenticate deny_access if (!signed_in? && !) end |
#current_permission(invoice = nil) ⇒ Object
29 30 31 |
# File 'lib/simple_auth/authentication.rb', line 29 def (invoice = nil) @_current_permission ||= (invoice) end |
#current_user ⇒ User?
User in the current cookie
24 25 26 |
# File 'lib/simple_auth/authentication.rb', line 24 def current_user @_current_user ||= end |
#current_user=(user) ⇒ Object
Set the current user
40 41 42 |
# File 'lib/simple_auth/authentication.rb', line 40 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.
110 111 112 113 114 |
# File 'lib/simple_auth/authentication.rb', line 110 def deny_access( = nil) store_location flash[:failure] = if redirect_to(signup_url) end |
#permission_exist? ⇒ true, false
Is exist permission and invoice
54 55 56 57 58 59 60 61 |
# File 'lib/simple_auth/authentication.rb', line 54 def if params[:token] && = params[:token][32..-1] _invoice_token = params[:token][0..31] _invoice = Invoice.find(_invoice_token) = Permission.find_by_token() _invoice && end end |
#sign_in(user) ⇒ Object
Sign user in to cookie.
86 87 88 89 90 91 92 93 94 |
# File 'lib/simple_auth/authentication.rb', line 86 def sign_in(user) if user [: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.
100 101 102 103 104 |
# File 'lib/simple_auth/authentication.rb', line 100 def sign_out current_user.reset_remember_token! if current_user .delete(:remember_token) current_user = nil end |
#signed_in? ⇒ true, false
Is the current user signed in?
47 48 49 |
# File 'lib/simple_auth/authentication.rb', line 47 def signed_in? ! current_user.nil? end |
#signed_out? ⇒ true, false
Is the current user signed out?
68 69 70 |
# File 'lib/simple_auth/authentication.rb', line 68 def signed_out? current_user.nil? end |