beyond_canvas 0.15.2.pre → 0.17.0.pre
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/README.md +0 -6
- data/Rakefile +3 -3
- data/app/assets/config/beyond_canvas_manifest.js +1 -0
- data/app/assets/images/icons/arrow_right.svg +1 -0
- data/app/assets/images/icons/close.svg +1 -0
- data/app/assets/images/icons/home.svg +1 -0
- data/app/assets/javascripts/beyond_canvas/base.js +120 -246
- data/app/assets/stylesheets/beyond_canvas/base.scss +8 -1
- data/app/assets/stylesheets/beyond_canvas/components/_action_bar.scss +28 -0
- data/app/assets/stylesheets/beyond_canvas/components/_breadcrumbs.scss +29 -0
- data/app/assets/stylesheets/beyond_canvas/components/_buttons.scss +1 -1
- data/app/assets/stylesheets/beyond_canvas/components/_debug.scss +10 -0
- data/app/assets/stylesheets/beyond_canvas/components/_forms.scss +11 -14
- data/app/assets/stylesheets/beyond_canvas/components/_main.scss +12 -13
- data/app/assets/stylesheets/beyond_canvas/components/_margins.scss +8 -0
- data/app/assets/stylesheets/beyond_canvas/components/_menu.scss +40 -0
- data/app/assets/stylesheets/beyond_canvas/components/_modals.scss +27 -0
- data/app/assets/stylesheets/beyond_canvas/components/_sidebar.scss +53 -0
- data/app/assets/stylesheets/beyond_canvas/components/_titles.scss +7 -0
- data/app/assets/stylesheets/beyond_canvas/settings/_breakpoints.scss +6 -6
- data/app/assets/stylesheets/beyond_canvas/settings/_variables.scss +77 -22
- data/app/controllers/beyond_canvas/application_controller.rb +2 -0
- data/app/controllers/beyond_canvas/authentications_controller.rb +69 -0
- data/app/controllers/concerns/beyond_canvas/authentication.rb +13 -0
- data/app/controllers/concerns/beyond_canvas/locale_management.rb +5 -4
- data/app/controllers/concerns/beyond_canvas/request_validation.rb +1 -1
- data/app/helpers/beyond_canvas/authentications_helper.rb +28 -0
- data/app/helpers/beyond_canvas/cockpit_app_helper.rb +17 -0
- data/app/helpers/beyond_canvas/debug_helper.rb +9 -0
- data/app/helpers/beyond_canvas/locale_switch_helper.rb +5 -1
- data/app/javascript/beyond_canvas/base.js +3 -0
- data/app/javascript/beyond_canvas/initializers/buttons.js +65 -19
- data/app/javascript/beyond_canvas/initializers/flash.js +9 -2
- data/app/javascript/beyond_canvas/initializers/inputs.js +4 -1
- data/app/javascript/beyond_canvas/initializers/modals.js +14 -0
- data/app/views/beyond_canvas/authentications/new.html.erb +27 -0
- data/app/views/beyond_canvas/shared/_action_bar.html.erb +15 -0
- data/app/views/beyond_canvas/shared/_breadcrumbs.html.erb +14 -0
- data/app/views/beyond_canvas/shared/_flash.html.erb +22 -12
- data/app/views/beyond_canvas/shared/_locales.html.erb +8 -0
- data/app/views/beyond_canvas/shared/_menu.html.erb +31 -0
- data/app/views/beyond_canvas/shared/_modal.html.erb +6 -0
- data/app/views/beyond_canvas/shared/_sidebar.html.erb +16 -0
- data/app/views/layouts/beyond_canvas/application.html.erb +31 -0
- data/app/views/layouts/beyond_canvas/public.html.erb +10 -1
- data/config/locales/en.yml +9 -0
- data/config/routes.rb +8 -1
- data/lib/beyond_canvas.rb +18 -2
- data/lib/beyond_canvas/configuration.rb +11 -3
- data/lib/beyond_canvas/engine.rb +6 -0
- data/lib/beyond_canvas/menu_item_registration.rb +19 -0
- data/lib/beyond_canvas/parameter_sanitizer.rb +43 -0
- data/lib/beyond_canvas/rails/routes.rb +22 -0
- data/lib/beyond_canvas/version.rb +1 -1
- data/lib/generators/beyond_canvas/controller/controller_generator.rb +19 -0
- data/lib/generators/beyond_canvas/controller/templates/controller.erb +20 -0
- data/lib/generators/beyond_canvas/custom_menu/custom_menu_generator.rb +13 -0
- data/lib/generators/beyond_canvas/custom_menu/templates/beyond_canvas_custom_menu.html.erb +32 -0
- data/lib/generators/beyond_canvas/custom_styles/custom_styles_generator.rb +1 -1
- data/lib/generators/beyond_canvas/custom_styles/templates/beyond_canvas_custom_styles.scss +199 -0
- data/lib/generators/beyond_canvas/install/install_generator.rb +13 -5
- data/lib/generators/beyond_canvas/install/templates/beyond_canvas.rb.erb +55 -6
- data/lib/generators/beyond_canvas/model/model_generator.rb +49 -0
- data/lib/generators/beyond_canvas/model/templates/migration.erb +18 -0
- data/lib/generators/beyond_canvas/model/templates/model.erb +5 -0
- data/lib/generators/beyond_canvas/views/views_generator.rb +17 -0
- data/lib/models/concerns/authentication.rb +57 -0
- data/lib/models/concerns/utils.rb +79 -0
- data/lib/models/shop.rb +12 -0
- metadata +95 -12
- data/app/javascript/beyond_canvas/initializers/functions.js +0 -41
- data/app/views/beyond_canvas/locales/_edit.html.erb +0 -8
- data/lib/generators/beyond_canvas/custom_styles/templates/beyond_canvas_custom_styles.sass +0 -123
@@ -6,7 +6,7 @@ module BeyondCanvas
|
|
6
6
|
source_root File.expand_path('templates', __dir__)
|
7
7
|
|
8
8
|
def copy_initializer
|
9
|
-
template 'beyond_canvas_custom_styles.
|
9
|
+
template 'beyond_canvas_custom_styles.scss', 'app/assets/stylesheets/_beyond_canvas_custom_styles.scss'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
// ************************************************************
|
2
|
+
// Colors
|
3
|
+
// ************************************************************
|
4
|
+
|
5
|
+
// $palette-primary: rgb(78, 183, 168);
|
6
|
+
// $palette-secondary: rgb(28, 53, 69);
|
7
|
+
// $palette-cancel: rgb(153, 153, 153);
|
8
|
+
// $palette-danger: rgb(218, 60, 60);
|
9
|
+
|
10
|
+
// ************************************************************
|
11
|
+
// General styles
|
12
|
+
// ************************************************************
|
13
|
+
|
14
|
+
// $main-background-public: rgb(233, 232, 220);
|
15
|
+
// $main-background-application: rgb(233, 232, 220);
|
16
|
+
|
17
|
+
// ************************************************************
|
18
|
+
// Typography
|
19
|
+
// ************************************************************
|
20
|
+
|
21
|
+
// $main-color: rgb(62, 62, 62);
|
22
|
+
|
23
|
+
// ************************************************************
|
24
|
+
// Headlines
|
25
|
+
// ************************************************************
|
26
|
+
|
27
|
+
// $headline-color: rgb(122, 118, 76);
|
28
|
+
|
29
|
+
// ************************************************************
|
30
|
+
// Links
|
31
|
+
// ************************************************************
|
32
|
+
|
33
|
+
// $link-primary-color: darken($palette-primary, 10%);
|
34
|
+
// $link-secondary-color: darken($palette-cancel, 10%);
|
35
|
+
// $link-danger-color: darken($palette-danger, 10%);
|
36
|
+
|
37
|
+
// ************************************************************
|
38
|
+
// Buttons
|
39
|
+
// ************************************************************
|
40
|
+
|
41
|
+
// $button-primary-background: $palette-primary;
|
42
|
+
// $button-primary-color: $white;
|
43
|
+
|
44
|
+
// $button-secondary-background: $palette-cancel;
|
45
|
+
// $button-secondary-color: $white;
|
46
|
+
|
47
|
+
// $button-danger-background: $palette-danger;
|
48
|
+
// $button-danger-color: $white;
|
49
|
+
|
50
|
+
// $button-border-radius: 3px;
|
51
|
+
// $button-box-shadow: true;
|
52
|
+
|
53
|
+
// ************************************************************
|
54
|
+
// Cards
|
55
|
+
// ************************************************************
|
56
|
+
|
57
|
+
// $card-border-radius: 3px;
|
58
|
+
// $card-box-shadow: 0 2px 7px rgba($black, 0.2);
|
59
|
+
// $card-separator-color: rgb(222, 222, 222);
|
60
|
+
// $card-title-color: rgb(247, 133, 96);
|
61
|
+
|
62
|
+
// ************************************************************
|
63
|
+
// Containers
|
64
|
+
// ************************************************************
|
65
|
+
|
66
|
+
|
67
|
+
// ************************************************************
|
68
|
+
// Labels
|
69
|
+
// ************************************************************
|
70
|
+
|
71
|
+
// $label-color: rgb(128, 128, 128);
|
72
|
+
|
73
|
+
// ************************************************************
|
74
|
+
// Inputs
|
75
|
+
// ************************************************************
|
76
|
+
|
77
|
+
// $input-border-color: rgb(217, 216, 195);
|
78
|
+
// $input-border-color-focus: $palette-primary;
|
79
|
+
// $input-errors-color: $palette-danger;
|
80
|
+
|
81
|
+
// ************************************************************
|
82
|
+
// Checkboxes
|
83
|
+
// ************************************************************
|
84
|
+
|
85
|
+
// $checkbox-checked-color: #97C344; // This value MUST be HEX
|
86
|
+
// $checkbox-checked-background: #ffffff; // This value MUST be HEX
|
87
|
+
// $checkbox-unchecked-color: #C2BF9D; // This value MUST be HEX
|
88
|
+
// $checkbox-unchecked-background: #ffffff; // This value MUST be HEX
|
89
|
+
|
90
|
+
// ************************************************************
|
91
|
+
// Radiobuttons
|
92
|
+
// ************************************************************
|
93
|
+
|
94
|
+
// $radio-checked-color: #97C344; // This value MUST be HEX
|
95
|
+
// $radio-checked-background: #ffffff; // This value MUST be HEX
|
96
|
+
// $radio-unchecked-color: #C2BF9D; // This value MUST be HEX
|
97
|
+
// $radio-unchecked-background: #ffffff; // This value MUST be HEX
|
98
|
+
|
99
|
+
// ************************************************************
|
100
|
+
// Hints
|
101
|
+
// ************************************************************
|
102
|
+
|
103
|
+
// $hint-color: rgb(158, 158, 158);
|
104
|
+
|
105
|
+
// ************************************************************
|
106
|
+
// Logo
|
107
|
+
// ************************************************************
|
108
|
+
|
109
|
+
// $logo-margin-top-public: 0;
|
110
|
+
// $logo-margin-bottom-public: 34px;
|
111
|
+
|
112
|
+
// ************************************************************
|
113
|
+
// Flash
|
114
|
+
// ************************************************************
|
115
|
+
|
116
|
+
// $flash-success: rgb(123, 170, 81);
|
117
|
+
// $flash-notice: rgb(123, 170, 81);
|
118
|
+
// $flash-info: rgb(153, 153, 153);
|
119
|
+
// $flash-warning: rgb(243, 181, 71);
|
120
|
+
// $flash-error: rgb(218, 60, 60);
|
121
|
+
// $flash-border-radius: 4px;
|
122
|
+
// $flash-box-shadow: 0 1px 2px 0 rgba($black, 0.2);
|
123
|
+
// $flash-color: rgb(128, 128, 128);
|
124
|
+
|
125
|
+
// ************************************************************
|
126
|
+
// Tables
|
127
|
+
// ************************************************************
|
128
|
+
|
129
|
+
// $table-header-background: rgb(243, 242, 236);
|
130
|
+
// $table-border-color: rgb(233, 232, 220);
|
131
|
+
|
132
|
+
// ************************************************************
|
133
|
+
// Comments
|
134
|
+
// ************************************************************
|
135
|
+
|
136
|
+
// $comment-background: rgb(246, 246, 243);
|
137
|
+
// $comment-color: rgb(170, 169, 156);
|
138
|
+
|
139
|
+
// ************************************************************
|
140
|
+
// Notices
|
141
|
+
// ************************************************************
|
142
|
+
|
143
|
+
// $notice-success-background: rgb(123, 170, 81);
|
144
|
+
// $notice-notice-background: rgb(123, 170, 81);
|
145
|
+
// $notice-info-background: rgb(153, 153, 153);
|
146
|
+
// $notice-warning-background: rgb(243, 181, 71);
|
147
|
+
// $notice-error-background: rgb(218, 60, 60);
|
148
|
+
// $notice-border-radius: 4px;
|
149
|
+
// $notice-color: rgb(153, 153, 153);
|
150
|
+
|
151
|
+
// ************************************************************
|
152
|
+
// Breadcrums
|
153
|
+
// ************************************************************
|
154
|
+
|
155
|
+
// $breadcrum-color: rgb(122, 118, 76);
|
156
|
+
// $breadcrum-color-current: rgb(61, 149, 137);
|
157
|
+
|
158
|
+
// ************************************************************
|
159
|
+
// Titles
|
160
|
+
// ************************************************************
|
161
|
+
|
162
|
+
// $title-color: rgb(122, 118, 76);
|
163
|
+
|
164
|
+
// ************************************************************
|
165
|
+
// Menu
|
166
|
+
// ************************************************************
|
167
|
+
|
168
|
+
// $menu-background: #1c3445;
|
169
|
+
// $menu-height: 60px;
|
170
|
+
// $menu-logo-height: 30px;
|
171
|
+
// $menu-item-color: #9ab5c6;
|
172
|
+
// $menu-item-hover-color: lighten($menu-item-color, 13%);
|
173
|
+
// $menu-item-selected-color: #4eb7a8;
|
174
|
+
// $menu-item-selected-hover-color: lighten($menu-item-selected-color, 13%);
|
175
|
+
|
176
|
+
// ************************************************************
|
177
|
+
// Action bar
|
178
|
+
// ************************************************************
|
179
|
+
|
180
|
+
// $action-bar-background: rgb(255, 255, 255);
|
181
|
+
// $action-bar-shadow: 1px solid rgba(0, 0, 0, 0.2);
|
182
|
+
// $action-bar-height: 73px;
|
183
|
+
|
184
|
+
// ************************************************************
|
185
|
+
// Markdown
|
186
|
+
// ************************************************************
|
187
|
+
|
188
|
+
|
189
|
+
// ************************************************************
|
190
|
+
// Sidebar
|
191
|
+
// ************************************************************
|
192
|
+
|
193
|
+
|
194
|
+
// ************************************************************
|
195
|
+
// Modals
|
196
|
+
// ************************************************************
|
197
|
+
|
198
|
+
// $modal-close-icon-color: #8b8b8b;
|
199
|
+
// $modal-background-color: rgba(0, 0, 0, 0.5);
|
@@ -15,10 +15,6 @@ module BeyondCanvas
|
|
15
15
|
template 'beyond_canvas.rb.erb', 'config/initializers/beyond_canvas.rb'
|
16
16
|
end
|
17
17
|
|
18
|
-
def setup_routes
|
19
|
-
route "mount BeyondCanvas::Engine => '/'"
|
20
|
-
end
|
21
|
-
|
22
18
|
def create_assets
|
23
19
|
if options[:skip_webpacker]
|
24
20
|
generate 'beyond_canvas:assets'
|
@@ -28,7 +24,19 @@ module BeyondCanvas
|
|
28
24
|
end
|
29
25
|
|
30
26
|
def install_beyond_api
|
31
|
-
generate 'beyond_api
|
27
|
+
generate 'beyond_canvas:beyond_api'
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_model
|
31
|
+
generate 'beyond_canvas:model shop'
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup_routes
|
35
|
+
route 'beyond_canvas_routes'
|
36
|
+
end
|
37
|
+
|
38
|
+
def copy_locale
|
39
|
+
copy_file '../../../../../config/locales/en.yml', 'config/locales/beyond_canvas.en.yml'
|
32
40
|
end
|
33
41
|
end
|
34
42
|
end
|
@@ -1,9 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
BeyondCanvas.setup do |config|
|
4
|
+
# Carefully read and fill this configuration file.
|
5
|
+
#
|
6
|
+
# All uncommented configuration parameters are necessary for proper operation
|
7
|
+
# of Beyond Canvas.
|
8
|
+
|
9
|
+
# ==> Engine configuration
|
10
|
+
|
11
|
+
# Set the namespace where the Engine is going to be mounted.
|
12
|
+
#
|
13
|
+
# config.namespace = '/'
|
14
|
+
|
15
|
+
# Set the url or path where a shop is going to be redirected after a
|
16
|
+
# succesful authentication.
|
17
|
+
#
|
18
|
+
config.open_app_url = nil
|
19
|
+
|
20
|
+
# Set if your app ig going to run as a cockpit app. If you are not sure about
|
21
|
+
# this, please contact apps@epages.com.
|
22
|
+
#
|
23
|
+
# config.cockpit_app = false
|
24
|
+
|
25
|
+
# Set if your app is going to be preinstalled on packages. If you are not sure
|
26
|
+
# about this, please contact apps@epages.com.
|
27
|
+
#
|
28
|
+
# config.preinstalled = false
|
29
|
+
|
30
|
+
# Set if you want to enable the available debug mode Beyond Canvas offers.
|
31
|
+
# This options displays a parameter debug as well as some custom Beyond Canvas
|
32
|
+
# logs.
|
33
|
+
#
|
34
|
+
# config.debug_mode = false
|
35
|
+
|
4
36
|
# ==> Site configuration
|
5
37
|
|
6
|
-
# Set the title that is displayed on the main layout
|
38
|
+
# Set the title that is displayed on the main layout.
|
7
39
|
#
|
8
40
|
config.site_title = '<%= Rails.application.class.name.split("::").first.humanize %>'
|
9
41
|
|
@@ -17,24 +49,41 @@ BeyondCanvas.setup do |config|
|
|
17
49
|
#
|
18
50
|
# config.favicon = 'favicon.ico'
|
19
51
|
|
52
|
+
# Set the menu items that will be displayed on the top of your app.
|
53
|
+
# It accepts 3 parameters:
|
54
|
+
# 1. name: the text displayed on the link tag. Supports any string or an I18n compatible path.
|
55
|
+
# 2. url: the href of the link tag. Supports any string or a symbolized route.
|
56
|
+
# 3. options: any html attributes that will be added to the link tag.
|
57
|
+
# You can also run `rails g beyond_canvas:custom_menu` to generate a menu template you can override.
|
58
|
+
# See examples:
|
59
|
+
#
|
60
|
+
# config.register_menu_item 'Contact', '/contact/, class: 'contact'
|
61
|
+
# config.register_menu_item 'menu_item.about_us', :root_path, class: 'about-us', id: 'about-us'
|
62
|
+
# config.register_menu_item 'Our website', 'https://epages.com', target: :_blank
|
63
|
+
|
20
64
|
# ==> Stylesheets & Javascripts
|
21
65
|
|
22
66
|
# We recommend using the built in Beyond Canvas layout and loading up your own
|
23
67
|
# stylesheets / javascripts to customize the look and feel.
|
24
68
|
#
|
25
69
|
# To load a stylesheet:
|
26
|
-
#
|
70
|
+
# config.register_stylesheet 'my_stylesheet.css'
|
27
71
|
#
|
28
|
-
# You can provide an options hash for more control, which is passed along
|
29
|
-
#
|
72
|
+
# You can provide an options hash for more control, which is passed along
|
73
|
+
# to stylesheet_link_tag():
|
74
|
+
# config.register_stylesheet 'my_print_stylesheet.css', media: :print
|
30
75
|
#
|
31
76
|
# To load a javascript file:
|
32
|
-
#
|
77
|
+
# config.register_javascript 'my_javascript.js'
|
33
78
|
|
34
79
|
# ==> Webpacker
|
35
80
|
|
36
|
-
# By default,
|
81
|
+
# By default, Beyond Canvas uses Webpacker.
|
37
82
|
# You can switch to using Sprocket's asset pipeline here.
|
38
83
|
#
|
39
84
|
<% unless @skip_webpacker %># <% end %>config.skip_webpacker = <%= @skip_webpacker %>
|
85
|
+
|
86
|
+
# ==> Authentication with ePages Beyond API
|
87
|
+
|
88
|
+
config.encryption_key = '<%= SecureRandom.hex(32) %>'
|
40
89
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/active_record'
|
4
|
+
|
5
|
+
module BeyondCanvas
|
6
|
+
module Generators
|
7
|
+
class ModelGenerator < ActiveRecord::Generators::Base # :nodoc:
|
8
|
+
desc 'Generates a model with the given name and provides a method to authenticate in Beyond Backend'
|
9
|
+
|
10
|
+
argument :attributes, type: :array, default: [], banner: 'field:type field:type'
|
11
|
+
|
12
|
+
source_root File.expand_path('templates', __dir__)
|
13
|
+
|
14
|
+
def copy_beyond_canvas_migration
|
15
|
+
migration_path = File.join('db', 'migrate')
|
16
|
+
migration_template 'migration.erb',
|
17
|
+
"#{migration_path}/beyond_canvas_create_#{table_name}.rb",
|
18
|
+
migration_version: migration_version
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_model
|
22
|
+
template 'model.erb', File.join("app/models/#{file_path}.rb")
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def rails5_and_up?
|
28
|
+
Rails::VERSION::MAJOR >= 5
|
29
|
+
end
|
30
|
+
|
31
|
+
def migration_version
|
32
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if rails5_and_up?
|
33
|
+
end
|
34
|
+
|
35
|
+
def migration_data
|
36
|
+
<<RUBY
|
37
|
+
t.string :beyond_api_url, null: false
|
38
|
+
|
39
|
+
t.text :encrypted_beyond_access_token, null: true
|
40
|
+
t.text :encrypted_beyond_access_token_iv, null: true
|
41
|
+
|
42
|
+
t.text :encrypted_beyond_refresh_token, null: true
|
43
|
+
t.text :encrypted_beyond_refresh_token_iv, null: true
|
44
|
+
|
45
|
+
RUBY
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class BeyondCanvasCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
4
|
+
def change
|
5
|
+
create_table :<%= table_name %><%= primary_key_type %> do |t|
|
6
|
+
<%= migration_data -%>
|
7
|
+
<% attributes.each do |attribute| -%>
|
8
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
9
|
+
|
10
|
+
<% end -%>
|
11
|
+
t.timestamps null: false
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :<%= table_name %>, :beyond_api_url, unique: true
|
15
|
+
add_index :<%= table_name %>, :encrypted_beyond_access_token_iv, unique: true
|
16
|
+
add_index :<%= table_name %>, :encrypted_beyond_refresh_token_iv, unique: true
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/active_record'
|
4
|
+
|
5
|
+
module BeyondCanvas
|
6
|
+
module Generators
|
7
|
+
class ViewsGenerator < Rails::Generators::Base # :nodoc:
|
8
|
+
desc 'Creates all Beyond Canvas views to overwrite them'
|
9
|
+
|
10
|
+
source_root File.expand_path('../../../../app/views/beyond_canvas', __dir__)
|
11
|
+
|
12
|
+
def copy_views
|
13
|
+
directory 'authentications', 'app/views/beyond_canvas/authentications'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BeyondCanvas
|
4
|
+
module Models
|
5
|
+
module Concerns
|
6
|
+
module Authentication # :nodoc:
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
attr_accessor :code, :signature, :access_token_url, :api_url, :return_url, :terms
|
11
|
+
|
12
|
+
##############################################################################
|
13
|
+
# Encrypted attribute configuration
|
14
|
+
##############################################################################
|
15
|
+
|
16
|
+
attr_encrypted :beyond_access_token, key: [BeyondCanvas.configuration.encryption_key].pack('H*')
|
17
|
+
attr_encrypted :beyond_refresh_token, key: [BeyondCanvas.configuration.encryption_key].pack('H*')
|
18
|
+
|
19
|
+
##############################################################################
|
20
|
+
# Validations
|
21
|
+
##############################################################################
|
22
|
+
|
23
|
+
# Database fields
|
24
|
+
|
25
|
+
validates :beyond_api_url,
|
26
|
+
presence: true
|
27
|
+
validates :beyond_access_token,
|
28
|
+
presence: true,
|
29
|
+
unless: -> { encrypted_beyond_access_token_was.blank? }
|
30
|
+
validates :beyond_refresh_token,
|
31
|
+
presence: true,
|
32
|
+
unless: -> { encrypted_beyond_refresh_token_was.blank? }
|
33
|
+
|
34
|
+
##############################################################################
|
35
|
+
# Instance methods
|
36
|
+
##############################################################################
|
37
|
+
|
38
|
+
#
|
39
|
+
# Get and save access_token and refresh_token using the authentication code
|
40
|
+
# NOTE: This method is used during the shop creation, as it is the only point
|
41
|
+
# we know about the authentication code
|
42
|
+
#
|
43
|
+
def authenticate(params_code)
|
44
|
+
session = BeyondApi::Session.new(api_url: beyond_api_url)
|
45
|
+
session.token.create(params_code)
|
46
|
+
update(beyond_access_token: session.access_token,
|
47
|
+
beyond_refresh_token: session.refresh_token)
|
48
|
+
end
|
49
|
+
|
50
|
+
def authenticated?
|
51
|
+
beyond_access_token.present? && beyond_refresh_token.present?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|