biovision 0.0.200518.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +214 -0
  4. data/Rakefile +22 -0
  5. data/app/assets/config/biovision_manifest.js +1 -0
  6. data/app/assets/images/biovision/components/carousel/arrow-left.svg +4 -0
  7. data/app/assets/images/biovision/components/carousel/arrow-right.svg +4 -0
  8. data/app/assets/images/biovision/icons/breadcrumb-hover.svg +1 -0
  9. data/app/assets/images/biovision/icons/breadcrumb.svg +1 -0
  10. data/app/assets/images/biovision/icons/components/contact.svg +26 -0
  11. data/app/assets/images/biovision/icons/components/content.svg +20 -0
  12. data/app/assets/images/biovision/icons/components/users.svg +21 -0
  13. data/app/assets/images/biovision/icons/key.svg +16 -0
  14. data/app/assets/images/biovision/icons/log_in.svg +15 -0
  15. data/app/assets/images/biovision/icons/log_out.svg +15 -0
  16. data/app/assets/images/biovision/icons/messages/error.svg +14 -0
  17. data/app/assets/images/biovision/icons/messages/info.svg +8 -0
  18. data/app/assets/images/biovision/icons/messages/success.svg +12 -0
  19. data/app/assets/images/biovision/icons/messages/warning.svg +13 -0
  20. data/app/assets/images/biovision/icons/settings.svg +41 -0
  21. data/app/assets/images/biovision/placeholders/16x9.svg +11 -0
  22. data/app/assets/images/biovision/placeholders/1x1.svg +11 -0
  23. data/app/assets/images/biovision/placeholders/3x2.svg +11 -0
  24. data/app/assets/images/biovision/placeholders/user.svg +15 -0
  25. data/app/assets/stylesheets/biovision/admin.scss +6 -0
  26. data/app/assets/stylesheets/biovision/admin/components.scss +59 -0
  27. data/app/assets/stylesheets/biovision/admin/default.scss +57 -0
  28. data/app/assets/stylesheets/biovision/admin/layout.scss +95 -0
  29. data/app/assets/stylesheets/biovision/admin/vars.scss +56 -0
  30. data/app/assets/stylesheets/biovision/biovision.scss +134 -0
  31. data/app/assets/stylesheets/biovision/biovision/messages.scss +41 -0
  32. data/app/assets/stylesheets/biovision/components/carousel.scss +53 -0
  33. data/app/assets/stylesheets/biovision/components/forms.scss +85 -0
  34. data/app/assets/stylesheets/biovision/components/hamburger.scss +56 -0
  35. data/app/assets/stylesheets/biovision/components/lists.scss +91 -0
  36. data/app/assets/stylesheets/biovision/default.scss +57 -0
  37. data/app/assets/stylesheets/biovision/themes/default_theme.scss +2 -0
  38. data/app/assets/stylesheets/biovision/themes/default_theme/components.scss +3 -0
  39. data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +44 -0
  40. data/app/assets/stylesheets/biovision/themes/default_theme/layout/footer.scss +0 -0
  41. data/app/assets/stylesheets/biovision/themes/default_theme/layout/header.scss +39 -0
  42. data/app/assets/stylesheets/biovision/vars.scss +53 -0
  43. data/app/controllers/admin/agents_controller.rb +15 -0
  44. data/app/controllers/admin/components_controller.rb +174 -0
  45. data/app/controllers/admin/index_controller.rb +11 -0
  46. data/app/controllers/admin/ip_addresses_controller.rb +15 -0
  47. data/app/controllers/admin_controller.rb +14 -0
  48. data/app/controllers/authentication_controller.rb +79 -0
  49. data/app/controllers/concerns/authentication.rb +45 -0
  50. data/app/controllers/index_controller.rb +8 -0
  51. data/app/controllers/my/confirmations_controller.rb +2 -0
  52. data/app/controllers/my/index_controller.rb +8 -0
  53. data/app/controllers/my/profiles_controller.rb +128 -0
  54. data/app/controllers/my/recoveries_controller.rb +2 -0
  55. data/app/helpers/biovision_components_helper.rb +14 -0
  56. data/app/helpers/users_helper.rb +11 -0
  57. data/app/lib/biovision/components/base_component.rb +177 -0
  58. data/app/lib/biovision/components/component_settings.rb +30 -0
  59. data/app/lib/biovision/components/privilege_handler.rb +77 -0
  60. data/app/lib/biovision/components/track_component.rb +9 -0
  61. data/app/lib/biovision/components/users/authentication.rb +47 -0
  62. data/app/lib/biovision/components/users/code_handler.rb +23 -0
  63. data/app/lib/biovision/components/users/profile_handler.rb +12 -0
  64. data/app/lib/biovision/components/users/registration_handler.rb +99 -0
  65. data/app/lib/biovision/components/users_component.rb +47 -0
  66. data/app/lib/biovision/notifiers/base_notifier.rb +69 -0
  67. data/app/lib/biovision/notifiers/socialization_notifier.rb +31 -0
  68. data/app/lib/biovision/notifiers/users_notifier.rb +15 -0
  69. data/app/models/agent.rb +35 -0
  70. data/app/models/biovision_component.rb +45 -0
  71. data/app/models/biovision_component_user.rb +21 -0
  72. data/app/models/browser.rb +34 -0
  73. data/app/models/code.rb +71 -0
  74. data/app/models/concerns/checkable.rb +22 -0
  75. data/app/models/concerns/flat_priority.rb +50 -0
  76. data/app/models/concerns/has_language.rb +10 -0
  77. data/app/models/concerns/has_owner.rb +22 -0
  78. data/app/models/concerns/has_simple_image.rb +18 -0
  79. data/app/models/concerns/has_track.rb +10 -0
  80. data/app/models/concerns/has_uuid.rb +12 -0
  81. data/app/models/concerns/meta_texts.rb +16 -0
  82. data/app/models/concerns/nested_priority.rb +58 -0
  83. data/app/models/concerns/required_unique_name.rb +16 -0
  84. data/app/models/concerns/required_unique_slug.rb +15 -0
  85. data/app/models/concerns/toggleable.rb +33 -0
  86. data/app/models/foreign_site.rb +34 -0
  87. data/app/models/foreign_user.rb +21 -0
  88. data/app/models/ip_address.rb +31 -0
  89. data/app/models/language.rb +31 -0
  90. data/app/models/login_attempt.rb +35 -0
  91. data/app/models/metric.rb +48 -0
  92. data/app/models/metric_value.rb +11 -0
  93. data/app/models/notification.rb +37 -0
  94. data/app/models/simple_image.rb +47 -0
  95. data/app/models/simple_image_tag.rb +30 -0
  96. data/app/models/simple_image_tag_image.rb +13 -0
  97. data/app/models/token.rb +96 -0
  98. data/app/models/user.rb +136 -0
  99. data/app/models/user_language.rb +15 -0
  100. data/app/uploaders/simple_image_uploader.rb +96 -0
  101. data/app/uploaders/user_image_uploader.rb +58 -0
  102. data/app/views/admin/agents/_nav_item.html.erb +6 -0
  103. data/app/views/admin/agents/entity/_in_list.html.erb +6 -0
  104. data/app/views/admin/agents/index.html.erb +13 -0
  105. data/app/views/admin/components/_list.html.erb +12 -0
  106. data/app/views/admin/components/entity/_links.html.erb +35 -0
  107. data/app/views/admin/components/entity/_section.html.erb +12 -0
  108. data/app/views/admin/components/index.html.erb +12 -0
  109. data/app/views/admin/components/links/_track.html.erb +2 -0
  110. data/app/views/admin/components/links/_users.html.erb +11 -0
  111. data/app/views/admin/components/privileges.html.erb +20 -0
  112. data/app/views/admin/components/privileges/_component_user.html.erb +17 -0
  113. data/app/views/admin/components/privileges/_links.html.erb +35 -0
  114. data/app/views/admin/components/privileges/_privilege_flag.html.erb +28 -0
  115. data/app/views/admin/components/privileges/_users.html.erb +23 -0
  116. data/app/views/admin/components/settings.html.erb +39 -0
  117. data/app/views/admin/components/settings/_new_parameter.html.erb +46 -0
  118. data/app/views/admin/components/settings/_parameters.html.erb +20 -0
  119. data/app/views/admin/components/settings/_setting.html.erb +18 -0
  120. data/app/views/admin/components/settings/_settings.html.erb +31 -0
  121. data/app/views/admin/components/show.html.erb +14 -0
  122. data/app/views/admin/index/index.html.erb +14 -0
  123. data/app/views/admin/ip_addresses/_nav_item.html.erb +6 -0
  124. data/app/views/admin/ip_addresses/entity/_in_list.html.erb +6 -0
  125. data/app/views/admin/ip_addresses/index.html.erb +13 -0
  126. data/app/views/admin/unauthorized.html.erb +19 -0
  127. data/app/views/authentication/_form.html.erb +40 -0
  128. data/app/views/authentication/failed.js.erb +3 -0
  129. data/app/views/authentication/new.html.erb +21 -0
  130. data/app/views/index/index.html.erb +0 -0
  131. data/app/views/layouts/admin.html.erb +23 -0
  132. data/app/views/layouts/admin/_breadcrumbs.html.erb +8 -0
  133. data/app/views/layouts/admin/_footer.html.erb +10 -0
  134. data/app/views/layouts/admin/_header.html.erb +18 -0
  135. data/app/views/layouts/admin/header/_logo.html.erb +3 -0
  136. data/app/views/layouts/application/_footer.html.erb +8 -0
  137. data/app/views/layouts/application/_header.html.erb +9 -0
  138. data/app/views/layouts/application/header/_authentication.html.erb +13 -0
  139. data/app/views/my/index/index.html.erb +0 -0
  140. data/app/views/my/profiles/closed.html.erb +12 -0
  141. data/app/views/my/profiles/new.html.erb +17 -0
  142. data/app/views/my/profiles/new/_form.html.erb +147 -0
  143. data/app/views/shared/_breadcrumbs.html.erb +8 -0
  144. data/app/views/shared/_cookie_notification.html.erb +4 -0
  145. data/app/views/shared/_flash_messages.html.erb +7 -0
  146. data/app/views/shared/_meta_texts.html.erb +31 -0
  147. data/app/views/shared/_nothing_found.html.erb +1 -0
  148. data/app/views/shared/_pagination.jbuilder +15 -0
  149. data/app/views/shared/admin/_list.html.erb +19 -0
  150. data/app/views/shared/admin/_list_with_priority.html.erb +19 -0
  151. data/app/views/shared/admin/_toggleable.html.erb +8 -0
  152. data/app/views/shared/entity/_list_of_errors.html.erb +7 -0
  153. data/app/views/shared/forms/errors.js.erb +5 -0
  154. data/config/initializers/carrierwave.rb +27 -0
  155. data/config/initializers/pluralization.rb +2 -0
  156. data/config/locales/biovision-ru.yml +90 -0
  157. data/config/locales/components-ru.yml +81 -0
  158. data/config/locales/track-ru.yml +40 -0
  159. data/config/locales/users-ru.yml +130 -0
  160. data/config/routes.rb +75 -0
  161. data/db/migrate/20191228000000_create_biovision_components.rb +72 -0
  162. data/db/migrate/20200224000000_create_track_component.rb +59 -0
  163. data/db/migrate/20200224000010_create_users_component.rb +189 -0
  164. data/db/migrate/20200404000000_create_simple_images.rb +54 -0
  165. data/lib/biovision.rb +9 -0
  166. data/lib/biovision/base_methods.rb +167 -0
  167. data/lib/biovision/engine.rb +40 -0
  168. data/lib/biovision/version.rb +5 -0
  169. data/lib/tasks/biovision_tasks.rake +4 -0
  170. metadata +392 -0
@@ -0,0 +1,53 @@
1
+ @import "biovision/default";
2
+
3
+ :root {
4
+ --font-size-xxxl: #{$font-size-xxxl};
5
+ --font-size-xxl: #{$font-size-xxl};
6
+ --font-size-xl: #{$font-size-xl};
7
+ --font-size-large: #{$font-size-large};
8
+ --font-size-increased: #{$font-size-increased};
9
+ --font-size-normal: #{$font-size-normal};
10
+ --font-size-decreased: #{$font-size-decreased};
11
+ --font-size-small: #{$font-size-small};
12
+ --font-size-xs: #{$font-size-xs};
13
+
14
+ --font-family-main: #{$font-family-main};
15
+ --font-family-heading: #{$font-family-heading};
16
+
17
+ --spacer-s: #{$spacer-s};
18
+ --spacer-xxxs: .2rem;
19
+ --spacer-xxs: calc(var(--spacer-s) / 4);
20
+ --spacer-xs: calc(var(--spacer-s) / 2);
21
+ --spacer-m: calc(var(--spacer-s) * 2);
22
+ --spacer-l: calc(var(--spacer-s) * 3);
23
+ --spacer-xl: calc(var(--spacer-s) * 4);
24
+ --spacer-xxl: calc(var(--spacer-s) * 6);
25
+
26
+ --text-color-primary: #{$text-color-primary};
27
+ --text-color-secondary: #{$text-color-secondary};
28
+ --text-color-heading: #{$text-color-heading};
29
+
30
+ --text-color-inverted-primary: #{$text-color-inverted-primary};
31
+ --text-color-inverted-secondary: #{$text-color-inverted-secondary};
32
+ --text-color-inverted-heading: #{$text-color-inverted-heading};
33
+
34
+ --border-color-primary: #{$border-color-primary};
35
+ --border-color-secondary: #{$border-color-secondary};
36
+ --border-primary: #{$border-primary};
37
+ --border-secondary: #{$border-secondary};
38
+
39
+ --block-shadow: #{$block-shadow};
40
+
41
+ --link-color: #{$link-color};
42
+ --link-color-visited: #{$link-color-visited};
43
+ --link-color-active: #{$link-color-active};
44
+ --link-color-hover: #{$link-color-hover};
45
+
46
+ --content-width: #{$content-width};
47
+ --content-width-min: #{$content-width-min};
48
+
49
+ --input-border: #{$input-border};
50
+ --input-border-focus: #{$input-border-focus};
51
+ --input-border-invalid: #{$input-border-invalid};
52
+ --input-border-invalid-focus: #{$input-border-invalid-focus};
53
+ }
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Administrative part of agents
4
+ class Admin::AgentsController < AdminController
5
+ # get /admin/agents
6
+ def index
7
+ @collection = Agent.page_for_administration(current_page)
8
+ end
9
+
10
+ private
11
+
12
+ def component_class
13
+ Biovision::Components::TrackComponent
14
+ end
15
+ end
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Handling components
4
+ class Admin::ComponentsController < AdminController
5
+ before_action :set_handler, except: :index
6
+ skip_before_action :verify_authenticity_token, only: :ckeditor
7
+
8
+ # get /admin/components
9
+ def index
10
+ @collection = BiovisionComponent.list_for_administration
11
+ end
12
+
13
+ # get /admin/components/:slug
14
+ def show
15
+ error = 'Viewing component is not allowed'
16
+ handle_http_401(error) unless @handler.allow?
17
+ end
18
+
19
+ # get /admin/components/:slug/settings
20
+ def settings
21
+ error = 'Viewing settings is not allowed'
22
+ handle_http_401(error) unless @handler.allow?('settings')
23
+ end
24
+
25
+ # patch /admin/components/:slug/settings
26
+ def update_settings
27
+ if @handler.allow?('settings')
28
+ new_settings = params.dig(:component, :settings).permit!
29
+ @handler.settings = new_settings.to_h
30
+ flash[:success] = t('.success')
31
+ redirect_to(admin_component_settings_path(slug: params[:slug]))
32
+ else
33
+ handle_http_401('Changing settings is not allowed')
34
+ end
35
+ end
36
+
37
+ # patch /admin/components/:slug/parameters
38
+ def update_parameter
39
+ if @handler.allow?('settings')
40
+ slug = param_from_request(:key, :slug).downcase
41
+ value = param_from_request(:key, :value)
42
+
43
+ @handler[slug] = value
44
+ end
45
+
46
+ head :no_content
47
+ end
48
+
49
+ # delete /admin/components/:slug/parameters/:parameter_slug
50
+ def delete_parameter
51
+ if @handler.allow?('settings')
52
+ @handler.component.parameters.delete(params[:parameter_slug])
53
+ @handler.component.save
54
+ end
55
+
56
+ head :no_content
57
+ end
58
+
59
+ # get /admin/components/:slug/privileges
60
+ def privileges
61
+ error = 'Viewing privileges is not allowed'
62
+ handle_http_401(error) unless @handler.administrator?
63
+ end
64
+
65
+ # patch /admin/components/:slug/privileges
66
+ def update_privileges
67
+ if @handler.administrator?
68
+ user = User.find_by(id: params[:user_id])
69
+
70
+ if user.nil?
71
+ handle_http_404('Cannot find user') if user.nil?
72
+ else
73
+ @entity = @handler.user_link!(true)
74
+ end
75
+ else
76
+ handle_http_401('Updating privileges is not allowed')
77
+ end
78
+ end
79
+
80
+ # put /admin/components/:slug/administrators/:user_id
81
+ def add_administrator
82
+ if @handler.administrator?
83
+ @handler.user = User.find_by(id: params[:user_id])
84
+ @handler.privilege_handler.administrator!
85
+ end
86
+
87
+ head :no_content
88
+ end
89
+
90
+ # put /admin/components/:slug/administrators/:user_id
91
+ def remove_administrator
92
+ if @handler.administrator?
93
+ @handler.user = User.find_by(id: params[:user_id])
94
+ @handler.privilege_handler.not_administrator!
95
+ end
96
+
97
+ head :no_content
98
+ end
99
+
100
+ # put /admin/components/:slug/users/:user_id/privileges/:privilege_slug
101
+ def add_privilege
102
+ if @handler.administrator?
103
+ @handler.user = User.find_by(id: params[:user_id])
104
+ @handler.privilege_handler.add_privilege(params[:privilege_slug])
105
+ end
106
+
107
+ head :no_content
108
+ end
109
+
110
+ # put /admin/components/:slug/users/:user_id/privileges/:privilege_slug
111
+ def remove_privilege
112
+ if @handler.administrator?
113
+ @handler.user = User.find_by(id: params[:user_id])
114
+ @handler.privilege_handler.remove_privilege(params[:privilege_slug])
115
+ end
116
+
117
+ head :no_content
118
+ end
119
+
120
+ # get /admin/components/:slug/images
121
+ def images
122
+ list = SimpleImage.in_component(@handler.component).list_for_administration
123
+ @collection = @handler.allow? ? list.page(current_page) : []
124
+ end
125
+
126
+ def create_image
127
+ if @handler.allow?
128
+ @entity = @handler.component.simple_images.new(image_parameters)
129
+ if @entity.save
130
+ render 'image', formats: :json
131
+ else
132
+ form_processed_with_error(:new_image)
133
+ end
134
+ else
135
+ handle_http_401('Uploading images is not allowed for current user')
136
+ end
137
+ end
138
+
139
+ # post /admin/components/:slug/ckeditor
140
+ def ckeditor
141
+ parameters = {
142
+ image: params[:upload],
143
+ biovision_component: @handler.component
144
+ }.merge(owner_for_entity(true))
145
+
146
+ @entity = SimpleImage.create!(parameters)
147
+
148
+ render json: {
149
+ uploaded: 1,
150
+ fileName: File.basename(@entity.image.path),
151
+ url: @entity.image.medium_url
152
+ }
153
+ end
154
+
155
+ private
156
+
157
+ def set_handler
158
+ slug = params[:slug]
159
+ @handler = Biovision::Components::BaseComponent.handler(slug, current_user)
160
+ end
161
+
162
+ def restrict_access
163
+ return if current_user&.super_user?
164
+
165
+ links_exist = BiovisionComponentUser.where(user: current_user).exists?
166
+ handle_http_401('User has no component privileges') unless links_exist
167
+ end
168
+
169
+ def image_parameters
170
+ permitted = SimpleImage.entity_parameters
171
+ params.require(:simple_image).permit(permitted)
172
+ permitted.merge(owner_for_entity(true))
173
+ end
174
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Administrative home page
4
+ class Admin::IndexController < AdminController
5
+ # get /admin
6
+ def index
7
+ return if Biovision::Components::BaseComponent.privileged?(current_user)
8
+
9
+ handle_http_401
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Administrative part of ip_addresses
4
+ class Admin::IpAddressesController < AdminController
5
+ # get /admin/ip_addresses
6
+ def index
7
+ @collection = IpAddress.page_for_administration(current_page)
8
+ end
9
+
10
+ private
11
+
12
+ def component_class
13
+ Biovision::Components::TrackComponent
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Common administrative controller
4
+ class AdminController < ApplicationController
5
+ before_action :restrict_access
6
+
7
+ protected
8
+
9
+ def restrict_access
10
+ error = t('admin.errors.unauthorized.message')
11
+
12
+ handle_http_401(error) unless component_handler.allow?
13
+ end
14
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Authentication with form and OAuth
4
+ class AuthenticationController < ApplicationController
5
+ include Authentication
6
+
7
+ before_action :redirect_authenticated_user, except: %i[new destroy]
8
+ before_action :set_foreign_site, only: :auth_callback
9
+
10
+ # get /login
11
+ def new
12
+ end
13
+
14
+ # post /login
15
+ def create
16
+ handler = Biovision::Components::UsersComponent[find_user]
17
+ if handler.authenticate(params[:password], tracking_for_entity)
18
+ auth_success(handler.user)
19
+ else
20
+ auth_failed
21
+ end
22
+ end
23
+
24
+ # delete /logout
25
+ def destroy
26
+ deactivate_token if current_user
27
+
28
+ redirect_to root_path
29
+ end
30
+
31
+ # get /auth/:provider/callback
32
+ def auth_callback
33
+ data = request.env['omniauth.auth']
34
+ user = @foreign_site.authenticate(data, tracking_for_entity)
35
+ create_token_for_user(user) unless user.banned?
36
+
37
+ redirect_to my_path
38
+ end
39
+
40
+ private
41
+
42
+ def component_class
43
+ Biovision::Components::UsersComponent
44
+ end
45
+
46
+ def set_foreign_site
47
+ @foreign_site = ForeignSite[params[:provider]]
48
+
49
+ handle_http_503('Cannot set foreign site') if @foreign_site.nil?
50
+ end
51
+
52
+ def find_user
53
+ login = param_from_request(:login).downcase
54
+ user = User.find_by(slug: login)
55
+
56
+ # Try to authenticate by email, if login does not match anything
57
+ if user.nil? && login.index('@').to_i.positive?
58
+ user = User.with_email(login).first
59
+ end
60
+
61
+ user
62
+ end
63
+
64
+ # @param [User] user
65
+ def auth_success(user)
66
+ create_token_for_user(user)
67
+
68
+ from = param_from_request(:from)
69
+ next_page = from =~ %r{\A/[^/]} ? from : my_path
70
+ render js: "document.location.href = '#{next_page}'"
71
+ end
72
+
73
+ def auth_failed
74
+ @form_id = param_from_request(:form_id)
75
+ @error = t('authentication.create.failed')
76
+
77
+ render 'failed', formats: :js
78
+ end
79
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Adds methods for user authentication
4
+ module Authentication
5
+ extend ActiveSupport::Concern
6
+
7
+ def redirect_authenticated_user
8
+ redirect_to my_path unless current_user.nil?
9
+ end
10
+
11
+ # @param [User] user
12
+ def create_token_for_user(user)
13
+ forced_user = User.find_by(id: user.primary_id)
14
+ user = forced_user unless forced_user.nil?
15
+
16
+ token = user.tokens.create!(tracking_for_entity)
17
+
18
+ cookies['token'] = {
19
+ value: token.cookie_pair,
20
+ expires: 1.year.from_now,
21
+ domain: :all,
22
+ httponly: true
23
+ }
24
+ end
25
+
26
+ def deactivate_token
27
+ token = Token.find_by(token: cookies['token'].split(':').last)
28
+ token&.update(active: false)
29
+ pop_token
30
+ end
31
+
32
+ def pop_token
33
+ if cookies['pt']
34
+ cookies['token'] = {
35
+ value: cookies['pt'],
36
+ expires: 1.year.from_now,
37
+ domain: :all,
38
+ httponly: true
39
+ }
40
+ cookies.delete 'pt', domain: :all
41
+ else
42
+ cookies.delete 'token', domain: :all
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Front page
4
+ class IndexController < ApplicationController
5
+ # get /
6
+ def index
7
+ end
8
+ end
@@ -0,0 +1,2 @@
1
+ class My::ConfirmationsController < ApplicationController
2
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Main page for user
4
+ class My::IndexController < ApplicationController
5
+ # get /my
6
+ def index
7
+ end
8
+ end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Managing profile for current user
4
+ class My::ProfilesController < ApplicationController
5
+ include Authentication
6
+
7
+ before_action :redirect_authorized_user, only: %i[new create]
8
+ before_action :restrict_anonymous_access, except: %i[check new create]
9
+
10
+ # post /my/profile/check
11
+ def check
12
+ @entity = User.new(creation_parameters)
13
+ end
14
+
15
+ # get /my/profile/new
16
+ def new
17
+ @entity = User.new
18
+
19
+ render :closed unless component_handler.settings['registration_open']
20
+ end
21
+
22
+ # post /my/profile
23
+ def create
24
+ if params[:agree]
25
+ redirect_to root_path, alert: t('.are_you_bot')
26
+ else
27
+ create_user
28
+ end
29
+ end
30
+
31
+ # get /my/profile
32
+ def show
33
+ end
34
+
35
+ # get /my/profile/edit
36
+ def edit
37
+ end
38
+
39
+ # patch /my/profile
40
+ def update
41
+ @entity = current_user
42
+ if @entity.update(user_parameters)
43
+ flash[:notice] = t('.success')
44
+ form_processed_ok(my_path)
45
+ else
46
+ form_processed_with_error(:edit)
47
+ end
48
+ end
49
+
50
+ protected
51
+
52
+ def component_class
53
+ Biovision::Components::UsersComponent
54
+ end
55
+
56
+ def redirect_authorized_user
57
+ redirect_to my_path if current_user.is_a?(User)
58
+ end
59
+
60
+ def create_user
61
+ code = Code.active.find_by(body: param_from_request(:code))
62
+ @entity = component_handler.register_user(creation_parameters, code)
63
+
64
+ if @entity.persisted?
65
+ create_token_for_user(@entity)
66
+ cookies.delete('r', domain: :all)
67
+
68
+ redirect_after_creation
69
+ else
70
+ form_processed_with_error(:new)
71
+ end
72
+ end
73
+
74
+ def creation_parameters
75
+ parameters = params.require(:user).permit(User.new_profile_parameters)
76
+ parameters.merge!(tracking_for_entity)
77
+ if cookies['r']
78
+ parameters[:inviter] = User.find_by(referral_link: cookies['r'])
79
+ end
80
+
81
+ parameters
82
+ end
83
+
84
+ def user_parameters
85
+ sensitive = sensitive_parameters
86
+ editable = User.profile_parameters + sensitive
87
+ parameters = params.require(:user).permit(editable)
88
+ new_data = @entity.data.merge(profile: profile_parameters)
89
+
90
+ filter_parameters(parameters.merge(data: new_data), sensitive)
91
+ end
92
+
93
+ def sensitive_parameters
94
+ if current_user.authenticate params[:password].to_s
95
+ User.sensitive_parameters
96
+ else
97
+ []
98
+ end
99
+ end
100
+
101
+ def profile_parameters
102
+ permitted = UserProfileHandler.allowed_parameters
103
+ dirty = params.require(:user_profile).permit(permitted)
104
+ UserProfileHandler.clean_parameters(dirty)
105
+ end
106
+
107
+ # @param [Hash] parameters
108
+ # @param [Array] sensitive
109
+ def filter_parameters(parameters, sensitive)
110
+ sensitive.each { |sp| parameters.except! sp if sp.blank? }
111
+ if parameters.key?(:email) && parameters[:email] != current_user.email
112
+ parameters[:email_confirmed] = false
113
+ end
114
+ if parameters.key?(:phone) && parameters[:phone] != current_user.phone
115
+ parameters[:phone_confirmed] = false
116
+ end
117
+
118
+ parameters
119
+ end
120
+
121
+ def redirect_after_creation
122
+ return_path = cookies['return_path'].to_s
123
+ return_path = my_profile_path unless return_path[0] == '/'
124
+ cookies.delete 'return_path', domain: :all
125
+
126
+ form_processed_ok(return_path)
127
+ end
128
+ end