mints 0.0.26 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/client.rb +72 -34
- data/lib/contact.rb +46 -46
- data/lib/errors.rb +98 -0
- data/lib/mints/controllers/admin_base_controller.rb +8 -66
- data/lib/mints/controllers/base_api_controller.rb +16 -134
- data/lib/mints/controllers/base_controller.rb +20 -106
- data/lib/mints/controllers/concerns/mints_clients.rb +74 -0
- data/lib/mints/controllers/concerns/read_config_file.rb +28 -0
- data/lib/mints/controllers/contact_api_controller.rb +6 -85
- data/lib/mints/controllers/public_api_controller.rb +6 -79
- data/lib/mints/controllers/user_api_controller.rb +7 -82
- data/lib/mints/helpers/contact_auth_helper.rb +67 -0
- data/lib/{mints_helper.rb → mints/helpers/mints_helper.rb} +7 -5
- data/lib/mints/helpers/proxy_controllers_methods.rb +126 -0
- data/lib/mints/helpers/user_auth_helper.rb +53 -0
- data/lib/mints.rb +2 -0
- data/lib/pub.rb +21 -21
- data/lib/user/config/api_keys.rb +4 -4
- data/lib/user/config/appointments.rb +13 -13
- data/lib/user/config/attribute_groups.rb +5 -5
- data/lib/user/config/attributes.rb +6 -6
- data/lib/user/config/calendars.rb +5 -5
- data/lib/user/config/config.rb +7 -7
- data/lib/user/config/importers.rb +13 -13
- data/lib/user/config/public_folders.rb +7 -7
- data/lib/user/config/relationships.rb +9 -9
- data/lib/user/config/roles.rb +6 -6
- data/lib/user/config/seeds.rb +3 -3
- data/lib/user/config/system_settings.rb +4 -4
- data/lib/user/config/tags.rb +4 -4
- data/lib/user/config/taxonomies.rb +7 -7
- data/lib/user/config/teams.rb +5 -5
- data/lib/user/config/users.rb +5 -5
- data/lib/user/contacts/contacts.rb +1 -1
- data/lib/user/content/assets.rb +17 -17
- data/lib/user/content/content.rb +13 -13
- data/lib/user/content/content_instances.rb +9 -9
- data/lib/user/content/content_templates.rb +7 -7
- data/lib/user/content/conversations.rb +13 -13
- data/lib/user/content/dam.rb +8 -8
- data/lib/user/content/forms.rb +16 -16
- data/lib/user/content/message_templates.rb +11 -11
- data/lib/user/content/messages.rb +5 -5
- data/lib/user/content/pages.rb +7 -7
- data/lib/user/content/stories.rb +6 -6
- data/lib/user/content/story_templates.rb +6 -6
- data/lib/user/content/story_versions.rb +6 -6
- data/lib/user/crm/companies.rb +5 -5
- data/lib/user/crm/contacts.rb +18 -18
- data/lib/user/crm/deals.rb +6 -6
- data/lib/user/crm/favorites.rb +3 -3
- data/lib/user/crm/segments.rb +9 -9
- data/lib/user/crm/users.rb +1 -1
- data/lib/user/crm/workflow_step_objects.rb +5 -5
- data/lib/user/crm/workflow_steps.rb +3 -3
- data/lib/user/crm/workflows.rb +4 -4
- data/lib/user/ecommerce/item_prices.rb +5 -5
- data/lib/user/ecommerce/locations.rb +10 -10
- data/lib/user/ecommerce/order_items_groups.rb +15 -14
- data/lib/user/ecommerce/order_statuses.rb +2 -2
- data/lib/user/ecommerce/orders.rb +16 -16
- data/lib/user/ecommerce/price_lists.rb +3 -3
- data/lib/user/ecommerce/product_templates.rb +7 -7
- data/lib/user/ecommerce/product_variations.rb +8 -8
- data/lib/user/ecommerce/products.rb +10 -10
- data/lib/user/ecommerce/skus.rb +5 -5
- data/lib/user/ecommerce/taxes.rb +5 -5
- data/lib/user/ecommerce/variant_options.rb +4 -4
- data/lib/user/ecommerce/variant_values.rb +4 -4
- data/lib/user/helpers/helpers.rb +8 -8
- data/lib/user/helpers/object_activities.rb +5 -5
- data/lib/user/helpers/object_folders.rb +5 -5
- data/lib/user/helpers/user_folders.rb +5 -5
- data/lib/user/marketing/marketing.rb +8 -8
- data/lib/user/profile/profile.rb +8 -8
- data/lib/user.rb +1 -1
- metadata +10 -4
@@ -1,94 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative "./concerns/read_config_file.rb"
|
2
|
+
require_relative "../helpers/proxy_controllers_methods.rb"
|
3
|
+
|
3
4
|
module Mints
|
4
5
|
class ContactAPIController < ActionController::API
|
5
6
|
include AbstractController::Helpers
|
6
|
-
include ActionController::Cookies
|
7
7
|
include ReverseProxy::Controller
|
8
|
-
|
8
|
+
include ReadConfigFile
|
9
|
+
include ProxyControllersMethods
|
9
10
|
|
10
11
|
def index
|
11
|
-
|
12
|
-
'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
|
13
|
-
'ApiKey' => "#{@api_key}",
|
14
|
-
'Content-Type'=> 'application/json',
|
15
|
-
'Accept'=> 'application/json'
|
16
|
-
}
|
17
|
-
# Set contact token id as header
|
18
|
-
if cookies[:mints_contact_id]
|
19
|
-
headers['ContactToken'] = cookies[:mints_contact_id]
|
20
|
-
end
|
21
|
-
# Set contact session token as header
|
22
|
-
if cookies[:mints_contact_session_token]
|
23
|
-
session_token = cookies[:mints_contact_session_token]
|
24
|
-
headers["Authorization"] = "Bearer #{session_token}"
|
25
|
-
end
|
26
|
-
|
27
|
-
url_need_cache = false
|
28
|
-
result_from_cache = false
|
29
|
-
time = 0
|
30
|
-
full_url = request.original_url
|
31
|
-
|
32
|
-
if request.method == "GET"
|
33
|
-
if @use_cache
|
34
|
-
@redis_config['groups'].each do |group|
|
35
|
-
group['urls'].each do |url|
|
36
|
-
if full_url.match url
|
37
|
-
time = group['time']
|
38
|
-
url_need_cache = true
|
39
|
-
break
|
40
|
-
end
|
41
|
-
end
|
42
|
-
break if url_need_cache
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
if url_need_cache
|
48
|
-
if @redis_server.get(full_url)
|
49
|
-
response = @redis_server.get(full_url)
|
50
|
-
result_from_cache = true
|
51
|
-
render json: response
|
52
|
-
else
|
53
|
-
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
54
|
-
# Request succeded!
|
55
|
-
config.on_response do |code, response|
|
56
|
-
@redis_server.setex(full_url,time,response.body)
|
57
|
-
end
|
58
|
-
# Request failed!
|
59
|
-
config.on_missing do |code, response|
|
60
|
-
# We got a 404!
|
61
|
-
if code == 404
|
62
|
-
raise ActionController::RoutingError.new('Not Found')
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
else
|
68
|
-
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
69
|
-
# Request failed!
|
70
|
-
config.on_missing do |code, response|
|
71
|
-
# We got a 404!
|
72
|
-
if code == 404
|
73
|
-
raise ActionController::RoutingError.new('Not Found')
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def set_config_variables
|
83
|
-
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
84
|
-
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
85
|
-
config = YAML.load template.result(binding)
|
86
|
-
@host = config["mints"]["host"]
|
87
|
-
@api_key = config["mints"]["api_key"]
|
88
|
-
@redis_server = Redis.new(host: config['redis_cache']['redis_host'], port: config['redis_cache']['redis_port'] ? config['redis_cache']['redis_port'] : 6379, db: config['redis_cache']['redis_db'] ? config['redis_cache']['redis_db'] : 1) if config['redis_cache']['use_cache']
|
89
|
-
@redis_config = config['redis_cache']
|
90
|
-
@use_cache = config['redis_cache']['use_cache']
|
91
|
-
end
|
12
|
+
super('contact')
|
92
13
|
end
|
93
14
|
end
|
94
15
|
end
|
@@ -1,85 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative "./concerns/read_config_file.rb"
|
2
|
+
require_relative "../helpers/proxy_controllers_methods.rb"
|
3
|
+
|
4
4
|
module Mints
|
5
5
|
class PublicAPIController < ActionController::API
|
6
6
|
include ReverseProxy::Controller
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
headers = {
|
11
|
-
'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
|
12
|
-
'ApiKey' => "#{@api_key}",
|
13
|
-
'Content-Type'=> 'application/json',
|
14
|
-
'Accept'=> 'application/json'
|
15
|
-
}
|
16
|
-
|
17
|
-
url_need_cache = false
|
18
|
-
result_from_cache = false
|
19
|
-
time = 0
|
20
|
-
full_url = request.original_url
|
21
|
-
|
22
|
-
if request.method == "GET"
|
23
|
-
if @use_cache
|
24
|
-
@redis_config['groups'].each do |group|
|
25
|
-
group['urls'].each do |url|
|
26
|
-
if full_url.match url
|
27
|
-
time = group['time']
|
28
|
-
url_need_cache = true
|
29
|
-
break
|
30
|
-
end
|
31
|
-
end
|
32
|
-
break if url_need_cache
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
if url_need_cache
|
38
|
-
if @redis_server.get(full_url)
|
39
|
-
response = @redis_server.get(full_url)
|
40
|
-
result_from_cache = true
|
41
|
-
render json: response
|
42
|
-
else
|
43
|
-
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
44
|
-
# Request succeded!
|
45
|
-
config.on_response do |code, response|
|
46
|
-
@redis_server.setex(full_url,time,response.body)
|
47
|
-
end
|
48
|
-
# Request failed!
|
49
|
-
config.on_missing do |code, response|
|
50
|
-
# We got a 404!
|
51
|
-
if code == 404
|
52
|
-
raise ActionController::RoutingError.new('Not Found')
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
else
|
58
|
-
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
59
|
-
# Request failed!
|
60
|
-
config.on_missing do |code, response|
|
61
|
-
# We got a 404!
|
62
|
-
if code == 404
|
63
|
-
raise ActionController::RoutingError.new('Not Found')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
7
|
+
include AbstractController::Helpers
|
8
|
+
include ReadConfigFile
|
9
|
+
include ProxyControllersMethods
|
72
10
|
|
73
|
-
def set_config_variables
|
74
|
-
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
75
|
-
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
76
|
-
config = YAML.load template.result(binding)
|
77
|
-
@host = config["mints"]["host"]
|
78
|
-
@api_key = config["mints"]["api_key"]
|
79
|
-
@redis_server = Redis.new(host: config['redis_cache']['redis_host'], port: config['redis_cache']['redis_port'] ? config['redis_cache']['redis_port'] : 6379, db: config['redis_cache']['redis_db'] ? config['redis_cache']['redis_db'] : 1) if config['redis_cache']['use_cache']
|
80
|
-
@redis_config = config['redis_cache']
|
81
|
-
@use_cache = config['redis_cache']['use_cache']
|
82
|
-
end
|
83
|
-
end
|
84
11
|
end
|
85
12
|
end
|
@@ -1,89 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative "./concerns/read_config_file.rb"
|
2
|
+
require_relative "../helpers/proxy_controllers_methods.rb"
|
3
|
+
|
3
4
|
module Mints
|
4
5
|
class UserAPIController < ActionController::API
|
5
6
|
include AbstractController::Helpers
|
6
|
-
include
|
7
|
-
include
|
8
|
-
before_action :set_config_variables
|
9
|
-
|
10
|
-
def index
|
11
|
-
headers = {
|
12
|
-
'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
|
13
|
-
'ApiKey' => "#{@api_key}",
|
14
|
-
'Content-Type'=> 'application/json',
|
15
|
-
'Accept'=> 'application/json'
|
16
|
-
}
|
17
|
-
if cookies[:mints_user_session_token]
|
18
|
-
session_token = cookies[:mints_user_session_token]
|
19
|
-
headers["Authorization"] = "Bearer #{session_token}"
|
20
|
-
end
|
21
|
-
|
22
|
-
url_need_cache = false
|
23
|
-
result_from_cache = false
|
24
|
-
time = 0
|
25
|
-
full_url = request.original_url
|
26
|
-
|
27
|
-
if request.method == "GET"
|
28
|
-
if url_need_cache
|
29
|
-
@redis_config['groups'].each do |group|
|
30
|
-
group['urls'].each do |url|
|
31
|
-
if full_url.match url
|
32
|
-
time = group['time']
|
33
|
-
url_need_cache = true
|
34
|
-
break
|
35
|
-
end
|
36
|
-
end
|
37
|
-
break if url_need_cache
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
7
|
+
include ReadConfigFile
|
8
|
+
include ProxyControllersMethods
|
41
9
|
|
42
|
-
|
43
|
-
|
44
|
-
response = @redis_server.get(full_url)
|
45
|
-
result_from_cache = true
|
46
|
-
render json: response
|
47
|
-
else
|
48
|
-
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
49
|
-
# Request succeded!
|
50
|
-
config.on_response do |code, response|
|
51
|
-
@redis_server.setex(full_url,time,response.body)
|
52
|
-
end
|
53
|
-
# Request failed!
|
54
|
-
config.on_missing do |code, response|
|
55
|
-
# We got a 404!
|
56
|
-
if code == 404
|
57
|
-
raise ActionController::RoutingError.new('Not Found')
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
else
|
63
|
-
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
64
|
-
# Request failed!
|
65
|
-
config.on_missing do |code, response|
|
66
|
-
# We got a 404!
|
67
|
-
if code == 404
|
68
|
-
raise ActionController::RoutingError.new('Not Found')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def set_config_variables
|
78
|
-
if File.exists?("#{Rails.root}/mints_config.yml.erb")
|
79
|
-
template = ERB.new File.new("#{Rails.root}/mints_config.yml.erb").read
|
80
|
-
config = YAML.load template.result(binding)
|
81
|
-
@host = config["mints"]["host"]
|
82
|
-
@api_key = config["mints"]["api_key"]
|
83
|
-
@redis_server = Redis.new(host: config['redis_cache']['redis_host'], port: config['redis_cache']['redis_port'] ? config['redis_cache']['redis_port'] : 6379, db: config['redis_cache']['redis_db'] ? config['redis_cache']['redis_db'] : 1) if config['redis_cache']['use_cache']
|
84
|
-
@redis_config = config['redis_cache']
|
85
|
-
@use_cache = config['redis_cache']['use_cache'] if config['redis_cache']['use_cache']
|
86
|
-
end
|
10
|
+
def index
|
11
|
+
super('user')
|
87
12
|
end
|
88
13
|
end
|
89
14
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module ContactAuthHelper
|
2
|
+
##
|
3
|
+
# === Mints Contact Login.
|
4
|
+
# Starts a contact session in mints.cloud and set a session cookie
|
5
|
+
def mints_contact_login(email, password)
|
6
|
+
# Login in mints
|
7
|
+
response = @mints_contact.login(email, password)
|
8
|
+
# Get session token from response
|
9
|
+
session_token = response['session_token']
|
10
|
+
id_token = response['contact']['contact_token'] ? response['contact']['contact_token'] : response['contact']['id_token']
|
11
|
+
# Set a permanent cookie with the session token
|
12
|
+
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
13
|
+
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
14
|
+
@contact_token = id_token
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# === Mints contact Login.
|
19
|
+
# Starts a contact session in mints.cloud and set a session cookie
|
20
|
+
def mints_contact_magic_link_login(hash, redirect_in_error = false)
|
21
|
+
# Login in mints
|
22
|
+
response = @mints_contact.magic_link_login(hash)
|
23
|
+
|
24
|
+
if response['data']
|
25
|
+
# Get session token from response
|
26
|
+
session_token = response['data']['session_token']
|
27
|
+
id_token = response['data']['contact']['contact_token'] ? response['data']['contact']['contact_token'] : response['data']['contact']['id_token']
|
28
|
+
# Set a permanent cookie with the session token
|
29
|
+
cookies.permanent[:mints_contact_session_token] = { value: session_token, secure: true, httponly: true }
|
30
|
+
cookies.permanent[:mints_contact_id] = { value: id_token, secure: true, httponly: true }
|
31
|
+
@contact_token = id_token
|
32
|
+
redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/' if redirect_in_error
|
33
|
+
else
|
34
|
+
redirect_to '/' if redirect_in_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# === Mints Contact Logout.
|
40
|
+
# Destroy session from mints.cloud and delete local session cookie
|
41
|
+
def mints_contact_logout
|
42
|
+
# Logout from mints
|
43
|
+
@mints_contact.logout
|
44
|
+
# Delete local cookie
|
45
|
+
cookies.delete(:mints_contact_session_token)
|
46
|
+
cookies.delete(:mints_contact_id)
|
47
|
+
@contact_token = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def mints_contact_signed_in?
|
51
|
+
|
52
|
+
begin
|
53
|
+
# Check status in mints
|
54
|
+
# Check status in mints
|
55
|
+
response = @mints_contact.status
|
56
|
+
status = response['success'] || false
|
57
|
+
rescue => e
|
58
|
+
# Handle the client Unauthorized error
|
59
|
+
# if mints response is negative delete the session cookie
|
60
|
+
cookies.delete(:mints_contact_session_token)
|
61
|
+
|
62
|
+
status = false
|
63
|
+
end
|
64
|
+
|
65
|
+
status
|
66
|
+
end
|
67
|
+
end
|
@@ -10,9 +10,9 @@ module MintsHelper
|
|
10
10
|
#
|
11
11
|
def get_query_results(url, options = nil, use_post = true)
|
12
12
|
if use_post
|
13
|
-
|
13
|
+
@client.raw("post", "#{url}/query", options)
|
14
14
|
else
|
15
|
-
|
15
|
+
@client.raw("get", url, options)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -24,10 +24,12 @@ module MintsHelper
|
|
24
24
|
#
|
25
25
|
def data_transform(data)
|
26
26
|
data = correct_json(data)
|
27
|
+
|
27
28
|
unless data[:data]
|
28
29
|
data = {data: data}
|
29
30
|
end
|
30
|
-
|
31
|
+
|
32
|
+
data.to_json
|
31
33
|
end
|
32
34
|
|
33
35
|
# === Correct json.
|
@@ -40,8 +42,8 @@ module MintsHelper
|
|
40
42
|
if data.is_a? String
|
41
43
|
data = JSON.parse(data)
|
42
44
|
end
|
43
|
-
|
44
|
-
|
45
|
+
|
46
|
+
data.symbolize_keys
|
45
47
|
end
|
46
48
|
|
47
49
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'reverse_proxy/controller'
|
3
|
+
require 'reverse_proxy/client'
|
4
|
+
|
5
|
+
module ProxyControllersMethods
|
6
|
+
include ActionController::Cookies
|
7
|
+
include ReverseProxy::Controller
|
8
|
+
|
9
|
+
# === Index
|
10
|
+
# Is the base index method for all controllers, manage the headers depending
|
11
|
+
# on the controller type (Contact or User)
|
12
|
+
#
|
13
|
+
# ==== Parameters
|
14
|
+
# controller_type:: (String) -- Controller type that be called, this manages the headers to send (contact, user, pub).
|
15
|
+
# ==== Return
|
16
|
+
# Returns the response returned by send_mints_request
|
17
|
+
#
|
18
|
+
def index(controller_type = nil)
|
19
|
+
headers = {
|
20
|
+
'host' => "#{@host.gsub('http://', '').gsub('https://', '')}",
|
21
|
+
'ApiKey' => "#{@api_key}",
|
22
|
+
'Content-Type'=> 'application/json',
|
23
|
+
'Accept'=> 'application/json'
|
24
|
+
}
|
25
|
+
|
26
|
+
if %w[contact user].include? controller_type
|
27
|
+
session_token = cookies["mints_#{controller_type}_session_token".to_sym]
|
28
|
+
headers["Authorization"] = session_token ? "Bearer #{session_token}" : request.headers["Authorization"]
|
29
|
+
end
|
30
|
+
|
31
|
+
headers['ContactToken'] = cookies[:mints_contact_id] if controller_type === 'contact' and cookies[:mints_contact_id]
|
32
|
+
|
33
|
+
full_url = request.original_url
|
34
|
+
url_need_cache, time = url_need_cache?(full_url)
|
35
|
+
|
36
|
+
if @debug or true
|
37
|
+
puts "URL: #{full_url}"
|
38
|
+
puts "URL need cache: #{url_need_cache}"
|
39
|
+
puts "URL time cache: #{time}"
|
40
|
+
puts "Headers: #{headers}"
|
41
|
+
end
|
42
|
+
|
43
|
+
if url_need_cache
|
44
|
+
cached_response = @redis_server.get(full_url)
|
45
|
+
|
46
|
+
if cached_response
|
47
|
+
puts "RESPONSE FROM CACHE" if @debug
|
48
|
+
return render json: cached_response
|
49
|
+
end
|
50
|
+
|
51
|
+
send_mints_request(full_url, headers, true, time)
|
52
|
+
else
|
53
|
+
send_mints_request(full_url, headers)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# === Url need cache?
|
58
|
+
# Method used to check if the given URL should be cached and for how long
|
59
|
+
#
|
60
|
+
# ==== Parameters
|
61
|
+
# full_url:: (String) -- URL to check if has cache.
|
62
|
+
# ==== Return
|
63
|
+
# Returns if the URL has cache and the time to be cached
|
64
|
+
|
65
|
+
def url_need_cache?(full_url)
|
66
|
+
url_need_cache = false
|
67
|
+
time = 0
|
68
|
+
methods_with_cache = %w[GET]
|
69
|
+
|
70
|
+
if methods_with_cache.include? request.method
|
71
|
+
if @use_cache
|
72
|
+
@redis_config['groups'].each do |group|
|
73
|
+
group['urls'].each do |url|
|
74
|
+
|
75
|
+
if full_url.match url
|
76
|
+
time = group['time']
|
77
|
+
url_need_cache = true
|
78
|
+
break
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
break if url_need_cache
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
[url_need_cache, time]
|
89
|
+
end
|
90
|
+
|
91
|
+
# === Send mints request
|
92
|
+
# Method used to make each request to CXF, in addition to verifying and saving
|
93
|
+
# the response in cache for cases where it requires cache
|
94
|
+
#
|
95
|
+
# ==== Parameters
|
96
|
+
# full_url:: (String) -- URL to make the request.
|
97
|
+
# headers:: (Hash|Object) -- Headers to send in the request.
|
98
|
+
# cache_result:: (Boolean) -- This parameter controls whether the response will be cached..
|
99
|
+
# time:: (Integer) -- It is the time that the response will be stored in cache.
|
100
|
+
# ==== Return
|
101
|
+
# Returns the response given by CXF or Redis
|
102
|
+
|
103
|
+
def send_mints_request(full_url, headers, cache_result = false, time = 30)
|
104
|
+
puts "RESPONSE FROM MINTS.CLOUD" if @debug
|
105
|
+
|
106
|
+
reverse_proxy "#{@host}", headers: headers, verify_ssl: false do |config|
|
107
|
+
|
108
|
+
if cache_result
|
109
|
+
# Request succeeded!
|
110
|
+
config.on_response do |code, response|
|
111
|
+
@redis_server.setex(
|
112
|
+
full_url,
|
113
|
+
time || 30,
|
114
|
+
response.body
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Request failed!
|
120
|
+
config.on_missing do |code, response|
|
121
|
+
# We got a 404!
|
122
|
+
raise ActionController::RoutingError.new('Not Found') if code == 404
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module UserAuthHelper
|
2
|
+
|
3
|
+
def mints_user_signed_in?
|
4
|
+
begin
|
5
|
+
# Check status in mints
|
6
|
+
response = @mints_user.me['data']
|
7
|
+
rescue => e
|
8
|
+
# Handle the client Unauthorized error
|
9
|
+
# if mints response is negative delete the session cookie
|
10
|
+
cookies.delete(:mints_user_session_token)
|
11
|
+
response = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
response
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# === Mints user Login.
|
19
|
+
# Starts a user session in mints.cloud and set a session cookie
|
20
|
+
def mints_user_login(email, password)
|
21
|
+
# Login in mints
|
22
|
+
response = @mints_user.login(email, password)
|
23
|
+
# Get session token from response
|
24
|
+
session_token = response['api_token']
|
25
|
+
# Set a permanent cookie with the session token
|
26
|
+
cookies[:mints_user_session_token] = { value: session_token, secure: true, httponly: true, expires: 1.day }
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# === Mints user Login.
|
31
|
+
# Starts a user session in mints.cloud and set a session cookie
|
32
|
+
def mints_user_magic_link_login(hash)
|
33
|
+
# Login in mints
|
34
|
+
response = @mints_user.magic_link_login(hash)
|
35
|
+
if response['data']
|
36
|
+
# Set a cookie with the session token
|
37
|
+
cookies[:mints_user_session_token] = { value: response['data']['api_token'], secure: true, httponly: true, expires: 1.day }
|
38
|
+
redirect_to response['data']['redirect_url'] ? response['data']['redirect_url'] : '/'
|
39
|
+
else
|
40
|
+
redirect_to '/'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# === Mints user Logout.
|
46
|
+
# Destroy session from mints.cloud and delete local session cookie
|
47
|
+
def mints_user_logout
|
48
|
+
# Logout from mints
|
49
|
+
# @mints_user.logout
|
50
|
+
# Delete local cookie
|
51
|
+
cookies.delete(:mints_user_session_token)
|
52
|
+
end
|
53
|
+
end
|
data/lib/mints.rb
CHANGED
@@ -7,5 +7,7 @@ require_relative "./mints/controllers/admin_base_controller.rb"
|
|
7
7
|
require_relative "./mints/controllers/public_api_controller.rb"
|
8
8
|
require_relative "./mints/controllers/contact_api_controller.rb"
|
9
9
|
require_relative "./mints/controllers/user_api_controller.rb"
|
10
|
+
require_relative './errors.rb'
|
11
|
+
|
10
12
|
module Mints
|
11
13
|
end
|