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
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Components
|
5
|
+
module Users
|
6
|
+
# Validating instances of User
|
7
|
+
module Validation
|
8
|
+
def validate
|
9
|
+
return if user.nil?
|
10
|
+
|
11
|
+
prepare_screen_name if user.new_record?
|
12
|
+
|
13
|
+
validate_email
|
14
|
+
validate_phone
|
15
|
+
validate_screen_name unless user.data[User::FLAG_SKIP_SCREEN_NAME]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def prepare_screen_name
|
21
|
+
use_uuid = false
|
22
|
+
use_uuid = email_as_login! if email_as_login?
|
23
|
+
use_uuid = phone_as_login! if phone_as_login?
|
24
|
+
|
25
|
+
user.screen_name = user.uuid if use_uuid
|
26
|
+
end
|
27
|
+
|
28
|
+
def email_as_login!
|
29
|
+
key = Biovision::Components::UsersComponent::SETTING_EMAIL_AS_LOGIN
|
30
|
+
user.data[key] = true
|
31
|
+
end
|
32
|
+
|
33
|
+
def phone_as_login!
|
34
|
+
key = Biovision::Components::UsersComponent::SETTING_PHONE_AS_LOGIN
|
35
|
+
user.data[key] = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_phone
|
39
|
+
user.errors.add(:phone, :blank) if require_phone? && user.phone.blank?
|
40
|
+
|
41
|
+
normalize_phone_format unless user.phone.blank?
|
42
|
+
validate_phone_format unless user.phone.blank?
|
43
|
+
end
|
44
|
+
|
45
|
+
def normalize_phone_format
|
46
|
+
has_plus = user.phone.strip[0] == '+'
|
47
|
+
normalized_phone = user.phone.gsub(/\D/, '')
|
48
|
+
normalized_phone[0] = '7' if !has_plus && normalized_phone[0] == '8'
|
49
|
+
|
50
|
+
user.phone = "+#{normalized_phone}" unless normalized_phone.blank?
|
51
|
+
end
|
52
|
+
|
53
|
+
# @see https://ru.wikipedia.org/wiki/MSISDN
|
54
|
+
def validate_phone_format
|
55
|
+
return if user.phone =~ /\+\d{11,15}/
|
56
|
+
|
57
|
+
user.errors.add(:phone, :invalid)
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_email
|
61
|
+
user.errors.add(:email, :blank) if require_email? && user.email.blank?
|
62
|
+
|
63
|
+
validate_email_format unless user.email.blank?
|
64
|
+
end
|
65
|
+
|
66
|
+
def validate_email_format
|
67
|
+
too_long = user.email.to_s.length > User::EMAIL_LIMIT
|
68
|
+
pattern_matches = (user.email.to_s =~ User::EMAIL_PATTERN)
|
69
|
+
|
70
|
+
user.errors.add(:email, :invalid) if too_long || !pattern_matches
|
71
|
+
end
|
72
|
+
|
73
|
+
def validate_screen_name
|
74
|
+
pattern = User::SLUG_PATTERN
|
75
|
+
|
76
|
+
return if user.screen_name =~ pattern
|
77
|
+
|
78
|
+
user.errors.add(:screen_name, :invalid)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -5,42 +5,105 @@ module Biovision
|
|
5
5
|
# Handling users
|
6
6
|
class UsersComponent < BaseComponent
|
7
7
|
include Users::Authentication
|
8
|
+
include Users::Validation
|
9
|
+
include Users::Codes
|
10
|
+
include Users::FlagHelpers
|
8
11
|
|
12
|
+
CODE_EMAIL_CONFIRMATION = 'email_confirmation'
|
13
|
+
CODE_INVITATION = 'invitation'
|
14
|
+
CODE_PHONE_CONFIRMATION = 'phone_confirmation'
|
15
|
+
CODE_RECOVERY = 'recovery'
|
16
|
+
METRIC_AUTH_FAILURE = 'users.auth.failure.hit'
|
9
17
|
METRIC_NEW_USER = 'users.new_user.hit'
|
18
|
+
METRIC_REGISTRATION_BOT = 'users.registration.bot.hit'
|
19
|
+
METRIC_USED_INVITATION = 'users.used_invitation.hit'
|
20
|
+
SETTING_BOUNCE_COUNT = 'bounce_count'
|
21
|
+
SETTING_BOUNCE_TIMEOUT = 'bounce_timeout'
|
22
|
+
SETTING_CONFIRM_EMAIL = 'confirm_email'
|
23
|
+
SETTING_CONFIRM_PHONE = 'confirm_phone'
|
24
|
+
SETTING_EMAIL_AS_LOGIN = 'email_as_login'
|
25
|
+
SETTING_INVITE_COUNT = 'invite_count'
|
26
|
+
SETTING_INVITE_ONLY = 'invite_only'
|
27
|
+
SETTING_OPEN = 'registration_open'
|
28
|
+
SETTING_PHONE_AS_LOGIN = 'phone_as_login'
|
29
|
+
SETTING_REQUIRE_EMAIL = 'require_email'
|
30
|
+
SETTING_REQUIRE_PHONE = 'require_phone'
|
31
|
+
SETTING_USE_INVITES = 'use_invites'
|
32
|
+
SETTING_USE_PHONE = 'use_phone'
|
33
|
+
|
34
|
+
def self.dependent_models
|
35
|
+
[
|
36
|
+
Notification, Code, BiovisionComponentUser, UserLanguage,
|
37
|
+
LoginAttempt, Token, User
|
38
|
+
]
|
39
|
+
end
|
10
40
|
|
11
41
|
def self.settings_flags
|
12
|
-
|
13
|
-
|
14
|
-
|
42
|
+
[
|
43
|
+
SETTING_OPEN, SETTING_EMAIL_AS_LOGIN, SETTING_CONFIRM_EMAIL,
|
44
|
+
SETTING_CONFIRM_PHONE, SETTING_PHONE_AS_LOGIN, SETTING_REQUIRE_EMAIL,
|
45
|
+
SETTING_REQUIRE_PHONE, SETTING_INVITE_ONLY, SETTING_USE_INVITES,
|
46
|
+
SETTING_USE_PHONE
|
15
47
|
]
|
16
48
|
end
|
17
49
|
|
18
50
|
def self.settings_numbers
|
19
|
-
|
51
|
+
[SETTING_INVITE_COUNT, SETTING_BOUNCE_COUNT, SETTING_BOUNCE_TIMEOUT]
|
52
|
+
end
|
53
|
+
|
54
|
+
# @param [User] user
|
55
|
+
def self.created_user(user)
|
56
|
+
BiovisionComponent.active.pluck(:slug).each do |slug|
|
57
|
+
handler = Biovision::Components::BaseComponent.handler_class(slug)
|
58
|
+
handler.handle_new_user(user) if handler.respond_to?(:handle_new_user)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param [User] user
|
63
|
+
def self.handle_new_user(user)
|
64
|
+
handler = new(BiovisionComponent[slug], user)
|
65
|
+
|
66
|
+
return unless handler.use_invites?
|
67
|
+
|
68
|
+
parameters = {
|
69
|
+
user: user,
|
70
|
+
quantity: handler.settings[SETTING_INVITE_COUNT].to_i
|
71
|
+
}
|
72
|
+
|
73
|
+
code = handler.component.codes.new(parameters)
|
74
|
+
code.code_type = CODE_INVITATION
|
75
|
+
code.save
|
20
76
|
end
|
21
77
|
|
22
78
|
# @param [Hash] parameters
|
23
|
-
# @param [Code] code
|
24
|
-
def register_user(parameters, code)
|
79
|
+
# @param [Code|nil] code
|
80
|
+
def register_user(parameters, code = nil)
|
25
81
|
handler = Users::RegistrationHandler.new(self)
|
26
82
|
handler.handle(parameters, code)
|
27
83
|
end
|
28
84
|
|
29
|
-
# @param [
|
30
|
-
|
31
|
-
|
85
|
+
# @param [Hash] user_data
|
86
|
+
# @param [Hash] profile_data
|
87
|
+
def create_user(user_data, profile_data)
|
88
|
+
handler = Users::ProfileHandler.new(self)
|
89
|
+
handler.create(user_data, profile_data)
|
90
|
+
handler.user
|
32
91
|
end
|
33
92
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
93
|
+
# @param [User] user
|
94
|
+
# @param [Hash] user_data
|
95
|
+
# @param [Hash] profile_data
|
96
|
+
def update_user(user, user_data, profile_data)
|
97
|
+
handler = Users::ProfileHandler.new(self)
|
98
|
+
handler.user = user
|
99
|
+
handler.update(user_data, profile_data)
|
100
|
+
end
|
101
|
+
|
102
|
+
# @param [String|Symbol] attribute_name
|
103
|
+
def attribute(attribute_name)
|
104
|
+
return nil if user.nil?
|
105
|
+
|
106
|
+
user.attributes[attribute_name.to_s]
|
44
107
|
end
|
45
108
|
end
|
46
109
|
end
|
@@ -20,7 +20,7 @@ module Biovision
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.slug
|
23
|
-
to_s.demodulize.underscore.gsub('_notifier', '')
|
23
|
+
to_s.demodulize.to_s.underscore.gsub('_notifier', '')
|
24
24
|
end
|
25
25
|
|
26
26
|
# @param [String] slug
|
@@ -56,7 +56,7 @@ module Biovision
|
|
56
56
|
def check_and_notify(id, type)
|
57
57
|
return if check_chain(id, type).exists?
|
58
58
|
|
59
|
-
notify({id: id, type: type})
|
59
|
+
notify({ id: id, type: type })
|
60
60
|
end
|
61
61
|
|
62
62
|
# @param [Integer] id
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Biovision
|
4
|
+
module Notifiers
|
5
|
+
# Notification mapper for contact component
|
6
|
+
class ContactNotifier < BaseNotifier
|
7
|
+
TYPE_FEEDBACK_MESSAGE = 'feedback_message'
|
8
|
+
|
9
|
+
# @param [Integer] message_id
|
10
|
+
def new_feedback_message(message_id)
|
11
|
+
check_and_notify(message_id, TYPE_FEEDBACK_MESSAGE)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Helper for canonizing and transliterating strings
|
4
|
+
class Canonizer
|
5
|
+
# Keys are not latin letters
|
6
|
+
TRANSLITERATION_MAP = {
|
7
|
+
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e',
|
8
|
+
'ё' => 'yo', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k',
|
9
|
+
'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r',
|
10
|
+
'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'kh', 'ц' => 'c',
|
11
|
+
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'shh', 'ъ' => '', 'ы' => 'y', 'ь' => '',
|
12
|
+
'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
|
13
|
+
'å' => 'ao', 'ä' => 'ae', 'ö' => 'oe', 'é' => 'e'
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
# @param [String] text
|
17
|
+
def self.transliterate(text)
|
18
|
+
pattern = Regexp.new "[#{TRANSLITERATION_MAP.keys.join}]"
|
19
|
+
result = text.to_s.downcase.gsub(pattern, TRANSLITERATION_MAP)
|
20
|
+
|
21
|
+
a = /[^-a-z0-9_]/ # non-allowed characters will be replaced with dash
|
22
|
+
b = /\A[-_]*([-a-z0-9_]*[a-z0-9]+)[-_]*\z/ # chop leading and trailing dash
|
23
|
+
result.gsub(a, '-').gsub(b, '\1').gsub(/--+/, '-').gsub(/-+\z/, '')
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param [String] input
|
27
|
+
def self.canonize(input)
|
28
|
+
lowered = input.to_s.downcase.strip
|
29
|
+
canonized = lowered.gsub(/[^a-zа-я0-9ё]/, '')
|
30
|
+
canonized.empty? ? lowered : canonized
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [String] input
|
34
|
+
def self.urlize(input)
|
35
|
+
lowered = input.to_s.downcase.squish
|
36
|
+
lowered.gsub(/[^a-zа-я0-9ё]/, '-').gsub(/-+\z/, '')
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
# Optimizing uploaded images
|
5
|
+
module ImageOptim
|
6
|
+
DEFAULT_OPTIONS = {
|
7
|
+
skip_missing_workers: true,
|
8
|
+
advpng: false,
|
9
|
+
gifsicle: false,
|
10
|
+
jhead: false,
|
11
|
+
jpegrecompress: false,
|
12
|
+
jpegtran: false,
|
13
|
+
pngcrush: false,
|
14
|
+
pngout: false,
|
15
|
+
pngquant: false,
|
16
|
+
svgo: false,
|
17
|
+
jpegoptim: { max_quality: 75 },
|
18
|
+
optipng: { level: 4 }
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
def optimize(options = {})
|
22
|
+
image_optim = ::ImageOptim.new(optimizer_options(options))
|
23
|
+
image_optim.optimize_image!(current_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def optimizer_options(options)
|
29
|
+
DEFAULT_OPTIONS.deep_merge(options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Mailer for sending codes to users
|
4
|
+
class CodeSender < ApplicationMailer
|
5
|
+
# Email confirmation code
|
6
|
+
#
|
7
|
+
# @param [Integer] code_id
|
8
|
+
def email(code_id)
|
9
|
+
@code = Code.find_by(id: code_id)
|
10
|
+
return if @code.nil?
|
11
|
+
|
12
|
+
user = @code.user
|
13
|
+
|
14
|
+
return if user.email.blank? || user.email_confirmed?
|
15
|
+
|
16
|
+
mail to: user.email
|
17
|
+
end
|
18
|
+
|
19
|
+
# Password reset code
|
20
|
+
#
|
21
|
+
# @param [Integer] code_id
|
22
|
+
def password(code_id)
|
23
|
+
@code = Code.find_by(id: code_id)
|
24
|
+
|
25
|
+
return if @code.nil? || @code.user.email.blank?
|
26
|
+
|
27
|
+
mail to: @code.user.email
|
28
|
+
end
|
29
|
+
end
|
data/app/models/agent.rb
CHANGED
@@ -14,16 +14,21 @@ class BiovisionComponent < ApplicationRecord
|
|
14
14
|
include FlatPriority
|
15
15
|
include RequiredUniqueSlug
|
16
16
|
|
17
|
+
SLUG_LIMIT = 250
|
18
|
+
SLUG_PATTERN_HTML = '^[a-zA-Z][-a-zA-Z0-9_]+[a-zA-Z0-9]$'
|
19
|
+
|
17
20
|
has_many :biovision_component_users, dependent: :delete_all
|
18
21
|
has_many :simple_images, dependent: :destroy
|
22
|
+
has_many :codes, dependent: :delete_all
|
19
23
|
|
24
|
+
scope :active, -> { where(active: true) }
|
20
25
|
scope :list_for_administration, -> { ordered_by_priority }
|
21
26
|
|
22
27
|
# Find component by slug
|
23
28
|
#
|
24
|
-
# @param [String] slug
|
29
|
+
# @param [String|Class] slug
|
25
30
|
def self.[](slug)
|
26
|
-
find_by(slug: slug)
|
31
|
+
find_by(slug: slug.respond_to?(:slug) ? slug.slug : slug)
|
27
32
|
end
|
28
33
|
|
29
34
|
# @param [String] slug
|
@@ -42,4 +47,19 @@ class BiovisionComponent < ApplicationRecord
|
|
42
47
|
def privileges
|
43
48
|
biovision_component_users.recent
|
44
49
|
end
|
50
|
+
|
51
|
+
# @param [User] user
|
52
|
+
# @param [String] type
|
53
|
+
# @param [Integer] quantity
|
54
|
+
def find_or_create_code(user, type, quantity = 1)
|
55
|
+
code = codes.owned_by(user).with_type(type).active.first
|
56
|
+
|
57
|
+
if code.nil?
|
58
|
+
code = codes.new(user: user, quantity: quantity)
|
59
|
+
code.code_type = type
|
60
|
+
code.save
|
61
|
+
end
|
62
|
+
|
63
|
+
code
|
64
|
+
end
|
45
65
|
end
|
data/app/models/browser.rb
CHANGED
data/app/models/code.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Code for users
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# Attributes:
|
6
6
|
# agent_id [Agent], optional
|
7
7
|
# biovision_component_id [BiovisionComponent]
|
@@ -20,18 +20,19 @@ class Code < ApplicationRecord
|
|
20
20
|
QUANTITY_RANGE = (0..32_767).freeze
|
21
21
|
|
22
22
|
belongs_to :biovision_component
|
23
|
-
belongs_to :user
|
23
|
+
belongs_to :user, optional: true
|
24
24
|
|
25
25
|
after_initialize :generate_body
|
26
26
|
|
27
27
|
before_validation :sanitize_quantity
|
28
28
|
|
29
29
|
validates_presence_of :body
|
30
|
-
validates_uniqueness_of :body
|
30
|
+
validates_uniqueness_of :body, unless: :phone?
|
31
31
|
validates_length_of :body, maximum: BODY_LIMIT
|
32
32
|
|
33
33
|
scope :recent, -> { order('id desc') }
|
34
34
|
scope :active, -> { where('quantity > 0') }
|
35
|
+
scope :with_type, ->(v) { where("data->>'type' = ?", v) unless v.blank? }
|
35
36
|
scope :list_for_administration, -> { recent }
|
36
37
|
|
37
38
|
# @param [Integer] page
|
@@ -39,12 +40,12 @@ class Code < ApplicationRecord
|
|
39
40
|
list_for_administration.page(page)
|
40
41
|
end
|
41
42
|
|
42
|
-
def self.entity_parameters
|
43
|
-
%i[body
|
43
|
+
def self.entity_parameters(*)
|
44
|
+
%i[body quantity]
|
44
45
|
end
|
45
46
|
|
46
|
-
def self.creation_parameters
|
47
|
-
entity_parameters + %i[user_id
|
47
|
+
def self.creation_parameters(*)
|
48
|
+
entity_parameters + %i[user_id biovision_component_id]
|
48
49
|
end
|
49
50
|
|
50
51
|
def activated?
|
@@ -55,13 +56,35 @@ class Code < ApplicationRecord
|
|
55
56
|
quantity.positive?
|
56
57
|
end
|
57
58
|
|
59
|
+
# @param [String] type_name
|
60
|
+
def type?(type_name)
|
61
|
+
code_type == type_name.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
def code_type
|
65
|
+
data['type'].to_s
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param [String] new_type
|
69
|
+
def code_type=(new_type)
|
70
|
+
data['type'] = new_type.to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
def phone?
|
74
|
+
type?(Biovision::Components::UsersComponent::CODE_PHONE_CONFIRMATION)
|
75
|
+
end
|
76
|
+
|
58
77
|
private
|
59
78
|
|
60
79
|
def generate_body
|
61
80
|
return unless body.nil?
|
62
81
|
|
63
|
-
|
64
|
-
|
82
|
+
if phone?
|
83
|
+
number = SecureRandom.random_number(0xffff_ffff_ffff_ffff)
|
84
|
+
self.body = number.to_s(36).scan(/.{4}/).join('-').upcase
|
85
|
+
else
|
86
|
+
self.body = SecureRandom.random_number(1_000_000).to_s.rjust(6, '0')
|
87
|
+
end
|
65
88
|
end
|
66
89
|
|
67
90
|
def sanitize_quantity
|