Class: Mints::BaseController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Mints::BaseController
- Defined in:
- lib/mints/controllers/base_controller.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(token) ⇒ Object
Mints Contact Magic Link 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
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mints/controllers/base_controller.rb', line 22 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
52 53 54 55 56 57 58 59 |
# File 'lib/mints/controllers/base_controller.rb', line 52 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(token) ⇒ Object
Mints Contact Magic Link Login.
Starts a contact session in mints.cloud and set a session cookie
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mints/controllers/base_controller.rb', line 37 def mints_contact_magic_link_login(token) # 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_signed_in? ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mints/controllers/base_controller.rb', line 8 def mints_contact_signed_in? # Check status in mints response = @mints_contact.status status = response['success'] ? response['success'] : false unless status # if mints response is negative delete the session cookie .delete(:mints_contact_session_token) end return status end |