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
#mints_contact_login(email, password) ⇒ Object
Mints Contact Login.
Starts a contact session in mints.cloud and set a session cookie
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mints/helpers/contact_auth_helper.rb', line 7 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 |
#mints_contact_logout ⇒ Object
Mints Contact Logout.
Destroy session from mints.cloud and delete local session cookie
43 44 45 46 47 48 49 50 |
# File 'lib/mints/helpers/contact_auth_helper.rb', line 43 def mints_contact_logout # Logout from mints @mints_contact.logout # Delete session token and keep the contact token id # Never delete the mints_contact_id cookie to avoid the creation of ghosts .delete(:mints_contact_session_token) @contact_token = nil end |
#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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mints/helpers/contact_auth_helper.rb', line 22 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'] || '/' if redirect_in_error else redirect_to '/' if redirect_in_error end end |
#mints_contact_signed_in? ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mints/helpers/contact_auth_helper.rb', line 52 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 |