biovision 0.0.200518.1 → 0.1.210414.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +60 -18
- data/app/assets/images/biovision/icons/back.svg +19 -0
- data/app/assets/images/biovision/icons/create.svg +19 -0
- data/app/assets/images/biovision/icons/destroy.svg +12 -0
- data/app/assets/images/biovision/icons/dropdown.svg +3 -0
- data/app/assets/images/biovision/icons/edit.svg +22 -0
- data/app/assets/images/biovision/icons/gear.svg +11 -0
- data/app/assets/images/biovision/icons/return.svg +25 -0
- data/app/assets/images/biovision/icons/world.svg +11 -0
- data/app/assets/stylesheets/biovision/admin/components.scss +3 -1
- data/app/assets/stylesheets/biovision/admin/components/users.scss +16 -0
- data/app/assets/stylesheets/biovision/admin/layout.scss +6 -17
- data/app/assets/stylesheets/biovision/biovision.scss +42 -1
- data/app/assets/stylesheets/biovision/components.scss +6 -0
- data/app/assets/stylesheets/biovision/components/breadcrumbs.scss +13 -0
- data/app/assets/stylesheets/biovision/components/buttons.scss +130 -0
- data/app/assets/stylesheets/biovision/components/forms.scss +162 -1
- data/app/assets/stylesheets/biovision/components/lists.scss +6 -7
- data/app/assets/stylesheets/biovision/{biovision → components}/messages.scss +9 -0
- data/app/assets/stylesheets/biovision/components/pagination.scss +34 -0
- data/app/assets/stylesheets/biovision/components/simple_image.scss +112 -0
- data/app/assets/stylesheets/biovision/components/toggleable.scss +71 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components.scss +2 -3
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users.scss +2 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/form_tabs.scss +101 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/components/users/profile.scss +77 -0
- data/app/assets/stylesheets/biovision/themes/default_theme/layout.scss +2 -16
- data/app/controllers/admin/components_controller.rb +9 -19
- data/app/controllers/admin/dynamic_blocks_controller.rb +15 -0
- data/app/controllers/admin/dynamic_pages_controller.rb +15 -0
- data/app/controllers/admin/navigation_groups_controller.rb +14 -0
- data/app/controllers/admin/users_controller.rb +70 -0
- data/app/controllers/admin_controller.rb +3 -2
- data/app/controllers/authentication_controller.rb +6 -34
- data/app/controllers/concerns/authentication.rb +12 -12
- data/app/controllers/concerns/crud_entities.rb +132 -0
- data/app/controllers/concerns/entity_priority.rb +10 -0
- data/app/controllers/concerns/toggleable_entity.rb +31 -0
- data/app/controllers/contact_controller.rb +49 -0
- data/app/controllers/fallback_controller.rb +12 -0
- data/app/controllers/index_controller.rb +1 -0
- data/app/controllers/legal_controller.rb +14 -0
- data/app/controllers/my/components_controller.rb +5 -0
- data/app/controllers/my/confirmations_controller.rb +44 -0
- data/app/controllers/my/index_controller.rb +8 -0
- data/app/controllers/my/profiles_controller.rb +31 -16
- data/app/controllers/profile_controller.rb +12 -0
- data/app/controllers/users_controller.rb +61 -0
- data/app/helpers/biovision_helper.rb +171 -0
- data/app/helpers/simple_image_helper.rb +125 -0
- data/app/jobs/application_job.rb +7 -0
- data/app/jobs/send_phone_confirmation_job.rb +16 -0
- data/app/lib/biovision/components/base/component_parameters.rb +44 -0
- data/app/lib/biovision/components/base/component_privileges.rb +65 -0
- data/app/lib/biovision/components/base/component_settings.rb +32 -0
- data/app/lib/biovision/components/base/privilege_handler.rb +79 -0
- data/app/lib/biovision/components/base_component.rb +51 -54
- data/app/lib/biovision/components/contact_component.rb +22 -0
- data/app/lib/biovision/components/content_component.rb +28 -0
- data/app/lib/biovision/components/track_component.rb +3 -0
- data/app/lib/biovision/components/users/authentication.rb +15 -7
- data/app/lib/biovision/components/users/codes.rb +104 -0
- data/app/lib/biovision/components/users/flag_helpers.rb +72 -0
- data/app/lib/biovision/components/users/profile_handler.rb +111 -1
- data/app/lib/biovision/components/users/registration_handler.rb +40 -52
- data/app/lib/biovision/components/users/validation.rb +83 -0
- data/app/lib/biovision/components/users_component.rb +82 -19
- data/app/lib/biovision/notifiers/base_notifier.rb +2 -2
- data/app/lib/biovision/notifiers/contact_notifier.rb +15 -0
- data/app/lib/canonizer.rb +38 -0
- data/app/lib/carrier_wave/image_optim.rb +32 -0
- data/app/mailers/code_sender.rb +29 -0
- data/app/models/agent.rb +4 -0
- data/app/models/biovision_component.rb +22 -2
- data/app/models/browser.rb +1 -1
- data/app/models/code.rb +32 -9
- data/app/models/concerns/has_simple_image.rb +9 -0
- data/app/models/concerns/meta_texts.rb +25 -5
- data/app/models/concerns/tree_structure.rb +72 -0
- data/app/models/contact_method.rb +47 -0
- data/app/models/contact_type.rb +27 -0
- data/app/models/dynamic_block.rb +43 -0
- data/app/models/dynamic_page.rb +71 -0
- data/app/models/feedback_message.rb +59 -0
- data/app/models/feedback_response.rb +50 -0
- data/app/models/group.rb +48 -0
- data/app/models/language.rb +4 -0
- data/app/models/navigation_group.rb +33 -0
- data/app/models/navigation_group_page.rb +23 -0
- data/app/models/role.rb +56 -0
- data/app/models/role_group.rb +13 -0
- data/app/models/simple_image.rb +22 -8
- data/app/models/simple_image_tag.rb +1 -1
- data/app/models/token.rb +4 -4
- data/app/models/user.rb +94 -26
- data/app/models/user_group.rb +20 -0
- data/app/models/user_role.rb +19 -0
- data/app/uploaders/simple_file_uploader.rb +27 -0
- data/app/uploaders/simple_image_uploader.rb +20 -0
- data/app/views/admin/agents/index.html.erb +0 -2
- data/app/views/admin/components/_image.jbuilder +18 -0
- data/app/views/admin/components/_list.html.erb +1 -1
- data/app/views/admin/components/entity/_links.html.erb +1 -1
- data/app/views/admin/components/image.jbuilder +1 -0
- data/app/views/admin/components/images.jbuilder +4 -0
- data/app/views/admin/components/links/_content.html.erb +9 -0
- data/app/views/admin/components/links/_users.html.erb +1 -8
- data/app/views/admin/components/links/extra/_content.html.erb +0 -0
- data/app/views/admin/components/privileges/_links.html.erb +0 -18
- data/app/views/admin/components/settings/_new_parameter.html.erb +4 -2
- data/app/views/admin/components/settings/_parameters.html.erb +8 -2
- data/app/views/admin/components/settings/_settings.html.erb +1 -1
- data/app/views/admin/components/update_privileges.jbuilder +21 -0
- data/app/views/admin/dynamic_blocks/_form.html.erb +16 -0
- data/app/views/admin/dynamic_blocks/_nav_item.html.erb +6 -0
- data/app/views/admin/dynamic_blocks/entity/_in_list.html.erb +10 -0
- data/app/views/admin/dynamic_blocks/index.html.erb +15 -0
- data/app/views/admin/dynamic_blocks/show.html.erb +23 -0
- data/app/views/admin/dynamic_pages/_form.html.erb +21 -0
- data/app/views/admin/dynamic_pages/_nav_item.html.erb +6 -0
- data/app/views/admin/dynamic_pages/entity/_in_list.html.erb +15 -0
- data/app/views/admin/dynamic_pages/index.html.erb +15 -0
- data/app/views/admin/dynamic_pages/show.html.erb +28 -0
- data/app/views/admin/ip_addresses/index.html.erb +0 -2
- data/app/views/admin/navigation_groups/_form.html.erb +15 -0
- data/app/views/admin/navigation_groups/_nav_item.html.erb +6 -0
- data/app/views/admin/navigation_groups/entity/_in_list.html.erb +12 -0
- data/app/views/admin/navigation_groups/index.html.erb +15 -0
- data/app/views/admin/navigation_groups/show.html.erb +20 -0
- data/app/views/admin/unauthorized.html.erb +2 -5
- data/app/views/admin/users/_form.html.erb +81 -0
- data/app/views/admin/users/_nav_item.html.erb +6 -0
- data/app/views/admin/users/entity/_fields.html.erb +53 -0
- data/app/views/admin/users/entity/_in_list.html.erb +38 -0
- data/app/views/admin/users/entity/_profile.html.erb +26 -0
- data/app/views/admin/users/entity/in_list/_additional_data.html.erb +0 -0
- data/app/views/admin/users/index.html.erb +15 -0
- data/app/views/admin/users/show.html.erb +44 -0
- data/app/views/application/forbidden.html.erb +9 -0
- data/app/views/application/forbidden.jbuilder +4 -0
- data/app/views/application/not_found.html.erb +9 -0
- data/app/views/application/not_found.jbuilder +4 -0
- data/app/views/application/unauthorized.html.erb +16 -0
- data/app/views/application/unauthorized.jbuilder +4 -0
- data/app/views/authentication/new.html.erb +2 -8
- data/app/views/components/content/_dynamic_page.html.erb +21 -0
- data/app/views/components/users/_form_tabs.html.erb +31 -0
- data/app/views/components/users/_join_form.html.erb +192 -0
- data/app/views/components/users/_login_form.html.erb +45 -0
- data/app/views/components/users/form/_image.html.erb +17 -0
- data/app/views/components/users/form/_profile_data.html.erb +54 -0
- data/app/views/contact/_form.html.erb +108 -0
- data/app/views/contact/create_feedback_message.js.erb +1 -0
- data/app/views/contact/feedback.html.erb +13 -0
- data/app/views/contact/index.html.erb +16 -0
- data/app/views/fallback/show.html.erb +6 -0
- data/app/views/layouts/admin.html.erb +1 -1
- data/app/views/layouts/admin/_footer.html.erb +1 -1
- data/app/views/layouts/application/header/_authentication.html.erb +1 -1
- data/app/views/legal/privacy.html.erb +5 -0
- data/app/views/legal/tos.html.erb +5 -0
- data/app/views/my/confirmations/show.html.erb +62 -0
- data/app/views/my/index/index.html.erb +33 -0
- data/app/views/my/profiles/_form.html.erb +10 -0
- data/app/views/my/profiles/check.jbuilder +4 -0
- data/app/views/my/profiles/edit.html.erb +14 -0
- data/app/views/my/profiles/form/_basic_parameters.html.erb +9 -0
- data/app/views/my/profiles/form/_sensitive_parameters.html.erb +68 -0
- data/app/views/my/profiles/new.html.erb +6 -8
- data/app/views/my/profiles/show.html.erb +23 -0
- data/app/views/shared/_flash_messages.html.erb +1 -1
- data/app/views/shared/_list_of_errors.html.erb +7 -0
- data/app/views/shared/admin/_breadcrumbs.html.erb +8 -0
- data/app/views/shared/admin/_list.html.erb +4 -4
- data/app/views/shared/admin/_list_with_priority.html.erb +4 -4
- data/app/views/shared/admin/_priority.html.erb +5 -0
- data/app/views/shared/admin/_toggle.html.erb +11 -0
- data/app/views/shared/entity/_formatted_text_field.html.erb +10 -0
- data/app/views/shared/entity/_image.html.erb +31 -0
- data/app/views/shared/entity/_language.html.erb +6 -0
- data/app/views/shared/entity/_linked_entity.html.erb +6 -0
- data/app/views/shared/entity/_meta_texts.html.erb +16 -0
- data/app/views/shared/entity/_metadata.html.erb +18 -0
- data/app/views/shared/entity/_parent.html.erb +6 -0
- data/app/views/shared/entity/_priority.html.erb +4 -0
- data/app/views/shared/entity/_raw_text_field.html.erb +10 -0
- data/app/views/shared/entity/_simple_image.html.erb +10 -0
- data/app/views/shared/entity/_slug.html.erb +6 -0
- data/app/views/shared/entity/_text_field.html.erb +6 -0
- data/app/views/shared/entity/_text_fields.html.erb +9 -0
- data/app/views/shared/entity/_timestamps.html.erb +13 -0
- data/app/views/shared/entity/_tree_caches.html.erb +12 -0
- data/app/views/shared/entity/_uuid.html.erb +4 -0
- data/app/views/shared/entity/edit.html.erb +21 -0
- data/app/views/shared/entity/new.html.erb +16 -0
- data/app/views/shared/forms/_entity_flags.html.erb +15 -0
- data/app/views/shared/forms/_field.html.erb +46 -0
- data/app/views/shared/forms/_fields.html.erb +3 -0
- data/app/views/shared/forms/_language.html.erb +40 -0
- data/app/views/shared/forms/_meta_texts.html.erb +27 -0
- data/app/views/shared/forms/_priority.html.erb +13 -0
- data/app/views/shared/forms/_simple_image.html.erb +39 -0
- data/app/views/shared/forms/_state_container.html.erb +7 -0
- data/app/views/shared/forms/_text_area.html.erb +25 -0
- data/app/views/shared/forms/_text_field.html.erb +24 -0
- data/app/views/shared/forms/_text_fields.html.erb +3 -0
- data/app/views/shared/forms/check.jbuilder +4 -0
- data/app/views/shared/forms/errors.jbuilder +3 -0
- data/app/views/shared/forms/simple_image/_browse.html.erb +14 -0
- data/app/views/shared/forms/simple_image/_load_image.html.erb +38 -0
- data/app/views/shared/my/_list.html.erb +19 -0
- data/app/views/shared/my/_list_with_priority.html.erb +19 -0
- data/app/views/users/_profile.html.erb +30 -0
- data/app/views/users/profile/_data.html.erb +20 -0
- data/app/views/users/show.html.erb +21 -0
- data/config/locales/biovision-ru.yml +58 -0
- data/config/locales/components-ru.yml +30 -2
- data/config/locales/contact-ru.yml +106 -0
- data/config/locales/content-ru.yml +103 -0
- data/config/locales/users-ru.yml +117 -3
- data/config/routes.rb +70 -50
- data/db/migrate/20191228000000_create_biovision_components.rb +4 -5
- data/db/migrate/20200224000000_create_track_component.rb +7 -8
- data/db/migrate/20200224000010_create_users_component.rb +15 -43
- data/db/migrate/20200404000000_create_simple_images.rb +3 -3
- data/db/migrate/20200529000000_create_content_component.rb +74 -0
- data/db/migrate/20210401000000_create_contact_component.rb +95 -0
- data/db/migrate/20210405000000_create_acl.rb +74 -0
- data/lib/biovision/base_methods.rb +18 -10
- data/lib/biovision/engine.rb +8 -13
- data/lib/biovision/version.rb +1 -1
- metadata +186 -20
- data/app/assets/images/biovision/placeholders/user.svg +0 -15
- data/app/helpers/users_helper.rb +0 -11
- data/app/lib/biovision/components/component_settings.rb +0 -30
- data/app/lib/biovision/components/privilege_handler.rb +0 -77
- data/app/lib/biovision/components/users/code_handler.rb +0 -23
- data/app/models/foreign_site.rb +0 -34
- data/app/models/foreign_user.rb +0 -21
- data/app/uploaders/user_image_uploader.rb +0 -58
- data/app/views/admin/components/privileges/_privilege_flag.html.erb +0 -28
- data/app/views/authentication/_form.html.erb +0 -40
- data/app/views/authentication/failed.js.erb +0 -3
- data/app/views/my/profiles/new/_form.html.erb +0 -147
- data/app/views/shared/admin/_toggleable.html.erb +0 -8
@@ -11,18 +11,20 @@ module Biovision
|
|
11
11
|
let_user_in?
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
private
|
15
15
|
|
16
16
|
def let_user_in?
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if user.nil? || user.banned?
|
18
|
+
register_failure && false
|
19
|
+
else
|
20
|
+
too_many_attempts? ? (log_attempt && false) : try_password
|
21
|
+
end
|
20
22
|
end
|
21
23
|
|
22
24
|
def too_many_attempts?
|
23
|
-
timeout = settings[
|
24
|
-
limit = settings[
|
25
|
-
LoginAttempt.owned_by(user).since(timeout).count > limit
|
25
|
+
timeout = settings[self.class::SETTING_BOUNCE_TIMEOUT].to_i.abs
|
26
|
+
limit = settings[self.class::SETTING_BOUNCE_COUNT].to_i
|
27
|
+
LoginAttempt.owned_by(user).since(timeout.minutes.ago).count > limit
|
26
28
|
end
|
27
29
|
|
28
30
|
def log_attempt
|
@@ -35,12 +37,18 @@ module Biovision
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def count_attempt
|
40
|
+
register_failure
|
38
41
|
log_attempt
|
39
42
|
return unless too_many_attempts?
|
40
43
|
|
41
44
|
notifier = Biovision::Notifiers::UsersNotifier.new(user)
|
42
45
|
notifier.new_login_attempt(@track)
|
43
46
|
end
|
47
|
+
|
48
|
+
def register_failure
|
49
|
+
metric = Biovision::Components::UsersComponent::METRIC_AUTH_FAILURE
|
50
|
+
register_metric(metric)
|
51
|
+
end
|
44
52
|
end
|
45
53
|
end
|
46
54
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Users
|
6
|
+
# Handling user-related codes
|
7
|
+
module Codes
|
8
|
+
# @param [Code] code
|
9
|
+
# @param [String] code_type
|
10
|
+
def valid_code?(code, code_type)
|
11
|
+
return false if code.nil? || code.biovision_component != @component
|
12
|
+
|
13
|
+
code.type?(code_type) && code.active?
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [Code] code
|
17
|
+
def valid_email_confirmation?(code)
|
18
|
+
return false if code.nil? || code.biovision_component != @component
|
19
|
+
return false unless code.active?
|
20
|
+
|
21
|
+
code_type = self.class::CODE_EMAIL_CONFIRMATION
|
22
|
+
code.type?(code_type) && code.data['email'] == user.email
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [Code] code
|
26
|
+
def valid_invitation?(code)
|
27
|
+
valid_code?(code, self.class::CODE_INVITATION)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [Code] code
|
31
|
+
def valid_recovery?(code)
|
32
|
+
valid_code?(code, self.class::CODE_RECOVERY)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param [User] user
|
36
|
+
def create_email_confirmation(user)
|
37
|
+
code_type = self.class::CODE_EMAIL_CONFIRMATION
|
38
|
+
code = @component.codes.new(user: user, code_type: code_type)
|
39
|
+
code.data['email'] = user.email
|
40
|
+
code.save
|
41
|
+
code
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param [User] user
|
45
|
+
def create_phone_confirmation(user)
|
46
|
+
code_type = self.class::CODE_PHONE_CONFIRMATION
|
47
|
+
code = @component.codes.new(user: user, code_type: code_type)
|
48
|
+
code.data['phone'] = user.phone
|
49
|
+
code.save
|
50
|
+
code
|
51
|
+
end
|
52
|
+
|
53
|
+
# @param [User] user
|
54
|
+
def send_email_confirmation(user)
|
55
|
+
code_type = self.class::CODE_EMAIL_CONFIRMATION
|
56
|
+
codes = @component.codes.active.owned_by(user).with_type(code_type)
|
57
|
+
code = codes.find_by("data->>'email' = ?", user.email)
|
58
|
+
code = create_email_confirmation(user) if code.nil?
|
59
|
+
|
60
|
+
CodeSender.email(code.id).deliver_later
|
61
|
+
end
|
62
|
+
|
63
|
+
# @param [User] user
|
64
|
+
def send_phone_confirmation(user)
|
65
|
+
code_type = self.class::CODE_PHONE_CONFIRMATION
|
66
|
+
codes = @component.codes.active.owned_by(user).with_type(code_type)
|
67
|
+
code = codes.find_by("data->>'phone' = ?", user.email)
|
68
|
+
code = create_phone_confirmation(user) if code.nil?
|
69
|
+
|
70
|
+
SendPhoneConfirmationJob.perform_later(code.id)
|
71
|
+
end
|
72
|
+
|
73
|
+
# @param [Code] code
|
74
|
+
def activate_email_confirmation(code)
|
75
|
+
return unless valid_email_confirmation?(code)
|
76
|
+
|
77
|
+
code.user.update(email_confirmed: true)
|
78
|
+
end
|
79
|
+
|
80
|
+
# @param [Code] code
|
81
|
+
# @param [User] user
|
82
|
+
def activate_invitation(code, user)
|
83
|
+
return if code.nil? || !code.active? || user.nil?
|
84
|
+
|
85
|
+
code.decrement!(:quantity)
|
86
|
+
user.update(inviter_id: code.user_id)
|
87
|
+
|
88
|
+
register_metric(self.class::METRIC_USED_INVITATION)
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param [User] user
|
92
|
+
def create_invitations_for_user(user)
|
93
|
+
quantity = settings[self.class::SETTING_INVITE_COUNT].to_i
|
94
|
+
|
95
|
+
return if quantity < 1
|
96
|
+
|
97
|
+
code = @component.codes.new(user: user, quantity: quantity)
|
98
|
+
code.code_type = self.class::CODE_INVITATION
|
99
|
+
code.save
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Users
|
6
|
+
# Helper methods for checking user flags
|
7
|
+
module FlagHelpers
|
8
|
+
def needs_email_confirmation?
|
9
|
+
return false if user&.email_confirmed?
|
10
|
+
|
11
|
+
confirm_email? && !user.email.blank?
|
12
|
+
end
|
13
|
+
|
14
|
+
def needs_phone_confirmation?
|
15
|
+
return false if user&.phone_confirmed?
|
16
|
+
|
17
|
+
confirm_phone? && !user.phone.blank?
|
18
|
+
end
|
19
|
+
|
20
|
+
def registration_open?
|
21
|
+
key = Biovision::Components::UsersComponent::SETTING_OPEN
|
22
|
+
settings[key]
|
23
|
+
end
|
24
|
+
|
25
|
+
def email_as_login?
|
26
|
+
key = Biovision::Components::UsersComponent::SETTING_EMAIL_AS_LOGIN
|
27
|
+
settings[key]
|
28
|
+
end
|
29
|
+
|
30
|
+
def phone_as_login?
|
31
|
+
key = Biovision::Components::UsersComponent::SETTING_PHONE_AS_LOGIN
|
32
|
+
settings[key]
|
33
|
+
end
|
34
|
+
|
35
|
+
def require_email?
|
36
|
+
key = Biovision::Components::UsersComponent::SETTING_REQUIRE_EMAIL
|
37
|
+
settings[key] || email_as_login?
|
38
|
+
end
|
39
|
+
|
40
|
+
def require_phone?
|
41
|
+
key = Biovision::Components::UsersComponent::SETTING_REQUIRE_PHONE
|
42
|
+
settings[key] || phone_as_login?
|
43
|
+
end
|
44
|
+
|
45
|
+
def confirm_email?
|
46
|
+
key = Biovision::Components::UsersComponent::SETTING_CONFIRM_EMAIL
|
47
|
+
settings[key]
|
48
|
+
end
|
49
|
+
|
50
|
+
def confirm_phone?
|
51
|
+
key = Biovision::Components::UsersComponent::SETTING_CONFIRM_PHONE
|
52
|
+
settings[key]
|
53
|
+
end
|
54
|
+
|
55
|
+
def invite_only?
|
56
|
+
key = Biovision::Components::UsersComponent::SETTING_INVITE_ONLY
|
57
|
+
settings[key]
|
58
|
+
end
|
59
|
+
|
60
|
+
def use_invites?
|
61
|
+
key = Biovision::Components::UsersComponent::SETTING_USE_INVITES
|
62
|
+
settings[key] || invite_only?
|
63
|
+
end
|
64
|
+
|
65
|
+
def use_phone?
|
66
|
+
key = Biovision::Components::UsersComponent::SETTING_USE_PHONE
|
67
|
+
settings[key]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -5,8 +5,118 @@ module Biovision
|
|
5
5
|
module Users
|
6
6
|
# Handling user profiles
|
7
7
|
class ProfileHandler
|
8
|
+
GENDERS = { 0 => 'female', 1 => 'male', 2 => 'other' }.freeze
|
9
|
+
|
8
10
|
attr_accessor :user
|
11
|
+
|
12
|
+
# @param [Biovision::Components::UsersComponent] component
|
13
|
+
def initialize(component)
|
14
|
+
@component = component
|
15
|
+
end
|
16
|
+
|
17
|
+
# List of attributes that can be used in user profile
|
18
|
+
#
|
19
|
+
# Change this method in decorators for other values
|
20
|
+
def self.allowed_parameters
|
21
|
+
%w[gender name patronymic surname about]
|
22
|
+
end
|
23
|
+
|
24
|
+
# List of parameters to be used in controllers for create/update
|
25
|
+
def self.permitted_for_request
|
26
|
+
allowed_parameters.map do |key|
|
27
|
+
key.respond_to?(:to_h) ? [[key.shift, key]].to_h : key
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Normalize profile parameters for storage
|
32
|
+
#
|
33
|
+
# Makes consistent format of profile hash.
|
34
|
+
#
|
35
|
+
# @param [Hash] input
|
36
|
+
def self.clean_parameters(input)
|
37
|
+
return {} unless input.respond_to?(:key?)
|
38
|
+
|
39
|
+
output = normalized_parameters(input)
|
40
|
+
(allowed_parameters - output.keys).each do |parameter|
|
41
|
+
if parameter.respond_to?(:shift)
|
42
|
+
key = parameter.shift
|
43
|
+
output[key] = array_value(input[key].to_h, parameter)
|
44
|
+
else
|
45
|
+
output[parameter] = scalar_value(input, parameter)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
output
|
49
|
+
end
|
50
|
+
|
51
|
+
# @param [Hash] input
|
52
|
+
# @param [String] key
|
53
|
+
def self.scalar_value(input, key)
|
54
|
+
input.key?(key) ? input[key].to_s : nil
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [Hash] input
|
58
|
+
# @param [Array] keys
|
59
|
+
def self.array_value(input, keys)
|
60
|
+
keys.each.map { |key| [key, scalar_value(input, key)] }.to_h
|
61
|
+
end
|
62
|
+
|
63
|
+
# @param [Integer|nil] gender_id
|
64
|
+
def self.gender(gender_id)
|
65
|
+
prefix = 'activerecord.attributes.user_profile.genders'
|
66
|
+
gender_key = gender_id.blank? ? '' : gender_id.to_i
|
67
|
+
postfix = GENDERS[gender_key] || 'not_set'
|
68
|
+
I18n.t("#{prefix}.#{postfix}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.genders_for_select
|
72
|
+
default_key = 'activerecord.attributes.user_profile.genders.not_set'
|
73
|
+
genders = [[I18n.t(default_key), '']]
|
74
|
+
genders + GENDERS.keys.map { |k| [gender(k), k] }
|
75
|
+
end
|
76
|
+
|
77
|
+
# Format parameters that have more restrictions than just "string" type
|
78
|
+
#
|
79
|
+
# Change this method in decorator to add other fields with type
|
80
|
+
# enumerable, integer, etc.
|
81
|
+
#
|
82
|
+
# @param [Hash] input
|
83
|
+
def self.normalized_parameters(input)
|
84
|
+
{ gender: clean_gender(input['gender']) }
|
85
|
+
end
|
86
|
+
|
87
|
+
# Restrict gender to only available values
|
88
|
+
#
|
89
|
+
# Defined gender is stored as integer.
|
90
|
+
#
|
91
|
+
# @param [Integer] input
|
92
|
+
def self.clean_gender(input)
|
93
|
+
gender_key = input.blank? ? nil : input.to_i
|
94
|
+
GENDERS.key?(gender_key) ? gender_key : nil
|
95
|
+
end
|
96
|
+
|
97
|
+
# @param [Hash] profile_data
|
98
|
+
def profile=(profile_data)
|
99
|
+
user.profile = self.class.clean_parameters(profile_data).to_h
|
100
|
+
end
|
101
|
+
|
102
|
+
# @param [Hash] user_data
|
103
|
+
# @param [Hash] profile_data
|
104
|
+
def create(user_data, profile_data)
|
105
|
+
self.user = User.new(user_data)
|
106
|
+
self.profile = profile_data
|
107
|
+
Biovision::Components::UsersComponent.created_user(user) if user.save
|
108
|
+
user
|
109
|
+
end
|
110
|
+
|
111
|
+
# @param [Hash] user_data
|
112
|
+
# @param [Hash] profile_data
|
113
|
+
def update(user_data, profile_data)
|
114
|
+
return if user.nil?
|
115
|
+
|
116
|
+
self.profile = profile_data
|
117
|
+
user.update(user_data)
|
118
|
+
end
|
9
119
|
end
|
10
120
|
end
|
11
121
|
end
|
12
|
-
end
|
122
|
+
end
|
@@ -5,48 +5,44 @@ module Biovision
|
|
5
5
|
module Users
|
6
6
|
# Handling user registration
|
7
7
|
class RegistrationHandler
|
8
|
+
attr_reader :user
|
9
|
+
|
8
10
|
# @param [Biovision::Components::UsersComponent] component
|
9
11
|
def initialize(component)
|
10
12
|
@component = component
|
11
13
|
end
|
12
14
|
|
15
|
+
# @param [Hash] parameters
|
16
|
+
# @param [Code|nil] Code
|
13
17
|
def handle(parameters, code = nil)
|
14
18
|
@user = User.new(parameters)
|
15
|
-
@user.screen_name = @user.email if email_as_login?
|
16
19
|
@user.super_user = 1 if User.count < 1
|
17
|
-
@
|
20
|
+
@user.code = code
|
21
|
+
@code = code
|
18
22
|
|
19
|
-
use_invites? ? use_code : persist_user
|
20
|
-
persist_user if @component.valid?(@user)
|
23
|
+
@component.use_invites? ? use_code : persist_user
|
21
24
|
|
22
25
|
@user
|
23
26
|
end
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@
|
31
|
-
|
32
|
-
|
33
|
-
def use_invites?
|
34
|
-
@component.settings['use_invites'] || invite_only?
|
35
|
-
end
|
36
|
-
|
37
|
-
def confirm_email?
|
38
|
-
@component.settings['confirm_email']
|
28
|
+
# @param [Hash] parameters
|
29
|
+
# @param [Code|nil] Code
|
30
|
+
def check(parameters, code = nil)
|
31
|
+
@user = User.new(parameters)
|
32
|
+
@user.code = code
|
33
|
+
@user.valid?
|
34
|
+
add_code_error unless acceptable_code?
|
39
35
|
end
|
40
36
|
|
41
|
-
def
|
42
|
-
@component.
|
37
|
+
def open?
|
38
|
+
@component.registration_open?
|
43
39
|
end
|
44
40
|
|
45
|
-
def
|
46
|
-
@
|
41
|
+
def valid?
|
42
|
+
@user.errors.blank?
|
47
43
|
end
|
48
44
|
|
49
|
-
|
45
|
+
private
|
50
46
|
|
51
47
|
def persist_user
|
52
48
|
return unless @user.save
|
@@ -54,44 +50,36 @@ module Biovision
|
|
54
50
|
metric = Biovision::Components::UsersComponent::METRIC_NEW_USER
|
55
51
|
@component.register_metric(metric)
|
56
52
|
|
57
|
-
|
53
|
+
Biovision::Components::UsersComponent.created_user(@user)
|
54
|
+
handle_codes
|
58
55
|
end
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
if @manager.valid? || (@manager.code.nil? && !invite_only?)
|
63
|
-
persist_user
|
64
|
-
else
|
65
|
-
error = I18n.t('biovision.components.users.messages.invalid_code')
|
66
|
-
|
67
|
-
# Add "invalid code" error to other model errors, if any
|
68
|
-
@user.valid?
|
69
|
-
@user.errors.add(:code, error)
|
70
|
-
end
|
57
|
+
def valid_invitation?
|
58
|
+
@component.valid_invitation?(@code)
|
71
59
|
end
|
72
60
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
CodeSender.email(code.id).deliver_later
|
77
|
-
end
|
61
|
+
def acceptable_code?
|
62
|
+
valid_invitation? || (@code.nil? && !@component.invite_only?)
|
63
|
+
end
|
78
64
|
|
79
|
-
|
65
|
+
# Check invitation code and persist user if it's valid
|
66
|
+
def use_code
|
67
|
+
acceptable_code? ? persist_user : add_code_error
|
68
|
+
end
|
80
69
|
|
81
|
-
|
82
|
-
|
70
|
+
def add_code_error
|
71
|
+
@user.valid?
|
72
|
+
@user.errors.add(:code, :invalid)
|
83
73
|
end
|
84
74
|
|
85
|
-
|
86
|
-
|
87
|
-
|
75
|
+
def handle_codes
|
76
|
+
@component.send_email_confirmation(@user) if @component.confirm_email?
|
77
|
+
@component.send_phone_confirmation(@user) if @component.confirm_phone?
|
78
|
+
|
79
|
+
return unless @component.use_invites?
|
88
80
|
|
89
|
-
|
90
|
-
|
91
|
-
user: @user,
|
92
|
-
quantity: quantity
|
93
|
-
}
|
94
|
-
Code.create(parameters)
|
81
|
+
@component.activate_invitation(@code, @user) if valid_invitation?
|
82
|
+
@component.create_invitations_for_user(@user)
|
95
83
|
end
|
96
84
|
end
|
97
85
|
end
|