mints 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/contact.rb +26 -0
- data/lib/generators/mints_assets_controller.rb +3 -0
- data/lib/generators/mints_files_generator.rb +2 -0
- data/lib/mints/controllers/admin_base_controller.rb +27 -11
- data/lib/mints/controllers/base_api_controller.rb +94 -4
- data/lib/mints/controllers/base_controller.rb +18 -1
- data/lib/user.rb +25 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9cce05094ead82499622fb1f66d7caa52848d7940c484917218563d32defa16
|
4
|
+
data.tar.gz: 88e34ca4adfe1f77097206463f6c24a6479b63f2cfdf92bf3106152c00b8dd5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbd81e5fed7023a5b3d489c66bbcc1efa3304d2fe6a7492aef0f0c72f51ad98c2c77635377858e19df92d61fd5a1c26d7d7758d0fde57c223ee9c9968faf0337
|
7
|
+
data.tar.gz: 6f8672d582a57aa9f2128b73b6fb8133387ea604082557b146eadc321cd9fbcd55a9da4bbba4ac9541cfc3225edcc6826858f314b104abea0bf887bd87bc5a0c
|
data/lib/contact.rb
CHANGED
@@ -27,6 +27,32 @@ module Mints
|
|
27
27
|
return response
|
28
28
|
end
|
29
29
|
|
30
|
+
##
|
31
|
+
# === Magic Link Login.
|
32
|
+
# Starts a contact session
|
33
|
+
#
|
34
|
+
def magic_link_login(token)
|
35
|
+
response = @client.raw("get", "/contacts/magic-link-login/#{token}", nil, '/api/v1')
|
36
|
+
if response.key? "session_token"
|
37
|
+
@client.session_token = response["session_token"]
|
38
|
+
end
|
39
|
+
return response
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# === Send magic link to contact
|
44
|
+
def send_magic_link(email, template_slug, redirectUrl = '', lifeTime = 1440, maxVisits = nil)
|
45
|
+
data = {
|
46
|
+
email: email,
|
47
|
+
lifeTime: lifeTime,
|
48
|
+
maxVisits: maxVisits,
|
49
|
+
redirectUrl: redirectUrl,
|
50
|
+
templateId: template_slug
|
51
|
+
}
|
52
|
+
response = @client.raw("post", "/contacts/magic-link", nil, { data: data }, '/api/v1')
|
53
|
+
return response
|
54
|
+
end
|
55
|
+
|
30
56
|
##
|
31
57
|
# === Logout.
|
32
58
|
# Ends a contact session
|
@@ -6,8 +6,10 @@ class MintsFilesGenerator < Rails::Generators::Base
|
|
6
6
|
copy_file 'mints_user_controller.rb', './app/controllers/api/mints_user_controller.rb'
|
7
7
|
copy_file 'mints_contact_controller.rb', './app/controllers/api/v1/mints_contact_controller.rb'
|
8
8
|
copy_file 'mints_public_controller.rb', './app/controllers/api/v1/mints_public_controller.rb'
|
9
|
+
copy_file 'mints_assets_controller.rb', './app/controllers/mints_assets_controller.rb'
|
9
10
|
route <<-eos
|
10
11
|
# Mints auto-generated routes (proxy to send request to mints.cloud)
|
12
|
+
match '/public-assets/*path' => 'mints_assets#index', via: [:get, :post, :put, :patch, :delete]
|
11
13
|
namespace :api, defaults: { format: :json } do
|
12
14
|
match '/user/v1/*path' => 'mints_user#index', via: [:get, :post, :put, :patch, :delete]
|
13
15
|
match '/contact/v1/*path' => 'mints_contact#index', via: [:get, :post, :put, :patch, :delete]
|
@@ -2,16 +2,16 @@ module Mints
|
|
2
2
|
class AdminBaseController < ActionController::Base
|
3
3
|
before_action :set_mints_user_client
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
def mints_user_signed_in?
|
6
|
+
# Check status in mints
|
7
|
+
response = @mints_user.me
|
8
|
+
status = response['data'] ? true : false
|
9
|
+
unless status
|
10
|
+
# if mints response is negative delete the session cookie
|
11
|
+
#cookies.delete(:mints_user_session_token)
|
12
|
+
end
|
13
|
+
return status
|
14
|
+
end
|
15
15
|
|
16
16
|
##
|
17
17
|
# === Mints user Login.
|
@@ -25,6 +25,21 @@ module Mints
|
|
25
25
|
cookies.permanent[:mints_user_session_token] = session_token
|
26
26
|
end
|
27
27
|
|
28
|
+
##
|
29
|
+
# === Mints user Login.
|
30
|
+
# Starts a user session in mints.cloud and set a session cookie
|
31
|
+
def mints_user_magic_link_login(hash)
|
32
|
+
# Login in mints
|
33
|
+
response = @mints_user.magic_link_login(hash)
|
34
|
+
if response['data'] && response['data']['redirect_url']
|
35
|
+
# Set a cookie with the session token
|
36
|
+
cookies[:mints_user_session_token] = { value: response['data']['api_token'], expires: 1.day }
|
37
|
+
redirect_to response['data']['redirect_url']
|
38
|
+
else
|
39
|
+
redirect_to '/'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
28
43
|
##
|
29
44
|
# === Mints user Logout.
|
30
45
|
# Destroy session from mints.cloud and delete local session cookie
|
@@ -51,7 +66,8 @@ module Mints
|
|
51
66
|
raise 'MintsBadCredentialsError'
|
52
67
|
end
|
53
68
|
# Initialize mints user client
|
54
|
-
|
69
|
+
session_token = cookies[:mints_user_session_token] ? cookies[:mints_user_session_token] : nil
|
70
|
+
@mints_user = Mints::User.new(@host, @api_key, session_token, @debug)
|
55
71
|
end
|
56
72
|
end
|
57
73
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Mints
|
2
2
|
class BaseApiController < ActionController::Base
|
3
|
-
before_action :
|
3
|
+
before_action :set_mints_clients
|
4
4
|
|
5
5
|
##
|
6
6
|
# === Mints Contact Login.
|
@@ -15,6 +15,26 @@ module Mints
|
|
15
15
|
cookies.permanent[:mints_contact_session_token] = session_token
|
16
16
|
cookies.permanent[:mints_contact_id] = id_token
|
17
17
|
@contact_token = id_token
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# === Mints cotnact Login.
|
22
|
+
# Starts a cotnact session in mints.cloud and set a session cookie
|
23
|
+
def mints_contact_magic_link_login(hash)
|
24
|
+
# Login in mints
|
25
|
+
response = @mints_contact.magic_link_login(hash)
|
26
|
+
if response['data']
|
27
|
+
# Get session token from response
|
28
|
+
session_token = response['data']['session_token']
|
29
|
+
id_token = response['data']['contact']['id_token']
|
30
|
+
# Set a permanent cookie with the session token
|
31
|
+
cookies.permanent[:mints_contact_session_token] = session_token
|
32
|
+
cookies.permanent[:mints_contact_id] = id_token
|
33
|
+
@contact_token = id_token
|
34
|
+
redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
|
35
|
+
else
|
36
|
+
redirect_to '/'
|
37
|
+
end
|
18
38
|
end
|
19
39
|
|
20
40
|
##
|
@@ -28,26 +48,96 @@ module Mints
|
|
28
48
|
cookies.delete(:mints_contact_id)
|
29
49
|
@contact_token = nil
|
30
50
|
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# === Mints user Login.
|
54
|
+
# Starts a user session in mints.cloud and set a session cookie
|
55
|
+
def mints_user_login(email, password)
|
56
|
+
# Login in mints
|
57
|
+
response = @mints_user.login(email, password)
|
58
|
+
# Get session token from response
|
59
|
+
session_token = response['api_token']
|
60
|
+
# Set a permanent cookie with the session token
|
61
|
+
cookies.permanent[:mints_user_session_token] = session_token
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# === Mints user Login.
|
66
|
+
# Starts a user session in mints.cloud and set a session cookie
|
67
|
+
def mints_user_magic_link_login(hash)
|
68
|
+
# Login in mints
|
69
|
+
response = @mints_user.magic_link_login(hash)
|
70
|
+
if response['data']
|
71
|
+
# Set a cookie with the session token
|
72
|
+
cookies[:mints_user_session_token] = { value: response['data']['api_token'], expires: 1.day }
|
73
|
+
redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
|
74
|
+
else
|
75
|
+
redirect_to '/'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# === Mints user Logout.
|
81
|
+
# Destroy session from mints.cloud and delete local session cookie
|
82
|
+
def mints_user_logout
|
83
|
+
# Logout from mints
|
84
|
+
# @mints_user.logout
|
85
|
+
# Delete local cookie
|
86
|
+
cookies.delete(:mints_user_session_token)
|
87
|
+
end
|
31
88
|
|
32
89
|
private
|
33
90
|
|
34
91
|
##
|
35
|
-
# === Set mints pub
|
36
|
-
# Initialize
|
37
|
-
def
|
92
|
+
# === Set mints clients (pub, user and contact)
|
93
|
+
# Initialize all clients from mitns
|
94
|
+
def set_mints_clients
|
38
95
|
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
39
96
|
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
40
97
|
config = YAML.load template.result(binding)
|
41
98
|
@host = config["mints"]["host"]
|
42
99
|
@api_key = config["mints"]["api_key"]
|
43
100
|
@debug = config["sdk"]["debug"] ? config["sdk"]["debug"] : false
|
101
|
+
|
102
|
+
#public client
|
103
|
+
set_mints_pub_client
|
104
|
+
#contact client
|
105
|
+
set_mints_contact_client
|
106
|
+
#user client
|
107
|
+
set_mints_user_client
|
44
108
|
else
|
45
109
|
raise 'MintsBadCredentialsError'
|
46
110
|
end
|
111
|
+
end
|
112
|
+
|
113
|
+
##
|
114
|
+
# === Set mints pub.
|
115
|
+
# Initialize the public client and set the contact token
|
116
|
+
def set_mints_pub_client
|
117
|
+
|
47
118
|
# Initialize mints pub client, credentials taken from mints_config.yml.erb file
|
48
119
|
@mints_pub = Mints::Pub.new(@host, @api_key, nil, @debug)
|
49
120
|
# Set contact token from cookie
|
50
121
|
@mints_pub.client.session_token = @contact_token
|
51
122
|
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# === Set mints contact client.
|
126
|
+
# Initialize the public client and set the contact token
|
127
|
+
def set_mints_contact_client
|
128
|
+
# Initialize mints clontact client
|
129
|
+
session_token = cookies[:mints_contact_session_token] ? cookies[:mints_contact_session_token] : nil
|
130
|
+
contact_token_id = cookies[:mints_contact_id] ? cookies[:mints_contact_id] : nil
|
131
|
+
@mints_contact = Mints::Contact.new(@host, @api_key, session_token, contact_token_id, @debug)
|
132
|
+
end
|
133
|
+
|
134
|
+
##
|
135
|
+
# === Set Mints user client.
|
136
|
+
# Initialize the public client and set the user token
|
137
|
+
def set_mints_user_client
|
138
|
+
# Initialize mints user client
|
139
|
+
session_token = cookies[:mints_user_session_token] ? cookies[:mints_user_session_token] : nil
|
140
|
+
@mints_user = Mints::User.new(@host, @api_key, session_token, @debug)
|
141
|
+
end
|
52
142
|
end
|
53
143
|
end
|
@@ -31,6 +31,21 @@ module Mints
|
|
31
31
|
@contact_token = id_token
|
32
32
|
end
|
33
33
|
|
34
|
+
##
|
35
|
+
# === Mints Contact Magic Link Login.
|
36
|
+
# Starts a contact session in mints.cloud and set a session cookie
|
37
|
+
def mints_contact_magic_link_login(token)
|
38
|
+
# Login in mints
|
39
|
+
response = @mints_contact.login(email, password)
|
40
|
+
# Get session token from response
|
41
|
+
session_token = response['session_token']
|
42
|
+
id_token = response['contact']['id_token']
|
43
|
+
# Set a permanent cookie with the session token
|
44
|
+
cookies.permanent[:mints_contact_session_token] = session_token
|
45
|
+
cookies.permanent[:mints_contact_id] = id_token
|
46
|
+
@contact_token = id_token
|
47
|
+
end
|
48
|
+
|
34
49
|
##
|
35
50
|
# === Mints Contact Logout.
|
36
51
|
# Destroy session from mints.cloud and delete local session cookie
|
@@ -86,7 +101,9 @@ module Mints
|
|
86
101
|
# Initialize the public client and set the contact token
|
87
102
|
def set_mints_contact_client
|
88
103
|
# Initialize mints clontact client
|
89
|
-
|
104
|
+
session_token = cookies[:mints_contact_session_token] ? cookies[:mints_contact_session_token] : nil
|
105
|
+
contact_token_id = cookies[:mints_contact_id] ? cookies[:mints_contact_id] : nil
|
106
|
+
@mints_contact = Mints::Contact.new(@host, @api_key, session_token, contact_token_id, @debug)
|
90
107
|
end
|
91
108
|
end
|
92
109
|
end
|
data/lib/user.rb
CHANGED
@@ -43,6 +43,31 @@ module Mints
|
|
43
43
|
end
|
44
44
|
return response
|
45
45
|
end
|
46
|
+
|
47
|
+
def magic_link_login(token)
|
48
|
+
response = @client.raw("get", "/users/magic-link-login/#{token}", nil, nil, '/api/v1')
|
49
|
+
return response
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# === Send magic link to user
|
54
|
+
def send_magic_link(email, redirectUrl = '', lifeTime = 24)
|
55
|
+
data = {
|
56
|
+
email: email,
|
57
|
+
redirectUrl: redirectUrl,
|
58
|
+
lifeTime: lifeTime
|
59
|
+
}
|
60
|
+
response = @client.raw("post", "/users/magic-link", nil, { data: data }, '/api/v1')
|
61
|
+
return response
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# === Me.
|
66
|
+
# Get contact logged info
|
67
|
+
#
|
68
|
+
def me
|
69
|
+
return @client.get__profile__me
|
70
|
+
end
|
46
71
|
######################################### CRM #########################################
|
47
72
|
##
|
48
73
|
# === Get contacts.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruben Gomez Garcia, Omar Mora, Luis Payan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- README.md
|
121
121
|
- lib/client.rb
|
122
122
|
- lib/contact.rb
|
123
|
+
- lib/generators/mints_assets_controller.rb
|
123
124
|
- lib/generators/mints_config.yml.erb
|
124
125
|
- lib/generators/mints_contact_controller.rb
|
125
126
|
- lib/generators/mints_files_generator.rb
|