Module: ContactAuthHelper
- Included in:
- Mints::BaseApiController, Mints::BaseController
- Defined in:
- lib/mints/helpers/contact_auth_helper.rb
Instance Method Summary collapse
-
#mints_contact_login(email, password) ⇒ Object
Mints Contact Login.
-
#mints_contact_logout ⇒ Object
Mints Contact Logout.
-
#mints_contact_magic_link_login(hash, redirect_in_error = false) ⇒ Object
Mints contact Login.
- #mints_contact_signed_in? ⇒ Boolean
Instance Method Details
permalink #mints_contact_login(email, password) ⇒ Object
Mints Contact Login.
Starts a contact session in mints.cloud and set a session cookie
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mints/helpers/contact_auth_helper.rb', line 5 def mints_contact_login(email, password) # Login in mints response = @mints_contact.login(email, password) # Get session token from response session_token = response['session_token'] id_token = response['contact']['contact_token'] ? response['contact']['contact_token'] : response['contact']['id_token'] # Set a permanent cookie with the session token .permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true } .permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true } @contact_token = id_token end |
permalink #mints_contact_logout ⇒ Object
Mints Contact Logout.
Destroy session from mints.cloud and delete local session cookie
41 42 43 44 45 46 47 48 |
# File 'lib/mints/helpers/contact_auth_helper.rb', line 41 def mints_contact_logout # Logout from mints @mints_contact.logout # Delete local cookie .delete(:mints_contact_session_token) .delete(:mints_contact_id) @contact_token = nil end |
permalink #mints_contact_magic_link_login(hash, redirect_in_error = false) ⇒ Object
Mints contact Login.
Starts a contact session in mints.cloud and set a session cookie
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mints/helpers/contact_auth_helper.rb', line 20 def mints_contact_magic_link_login(hash, redirect_in_error = false) # Login in mints response = @mints_contact.magic_link_login(hash) if response['data'] # Get session token from response session_token = response['data']['session_token'] id_token = response['data']['contact']['contact_token'] ? response['data']['contact']['contact_token'] : response['data']['contact']['id_token'] # Set a permanent cookie with the session token .permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true } .permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true } @contact_token = id_token redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/' if redirect_in_error else redirect_to '/' if redirect_in_error end end |
permalink #mints_contact_signed_in? ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mints/helpers/contact_auth_helper.rb', line 50 def mints_contact_signed_in? begin # Check status in mints # Check status in mints response = @mints_contact.status status = response['success'] || false rescue => e # Handle the client Unauthorized error # if mints response is negative delete the session cookie .delete(:mints_contact_session_token) status = false end status end |