diff --git a/Gemfile.lock b/Gemfile.lock index 1d0265d8fc1277cb5150d76a8e1de49099dbe081..c6465bb47d02e0e5971332c39d37a189375dcc67 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,9 +9,9 @@ GIT GIT remote: https://github.com/noesya/two_factor_authentication.git - revision: 18a9b69da420d588cd997df20b1c91f6bd08c41f + revision: cdabe19b43c10e1265cc6e92ac545c20841638cf specs: - two_factor_authentication (2.2.3) + two_factor_authentication (3.0.1) devise encryptor rails (>= 3.1.1) @@ -89,8 +89,8 @@ GEM autoprefixer-rails (10.4.7.0) execjs (~> 2) aws-eventstream (1.2.0) - aws-partitions (1.621.0) - aws-sdk-core (3.135.0) + aws-partitions (1.624.0) + aws-sdk-core (3.138.0) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.525.0) aws-sigv4 (~> 1.1) @@ -197,7 +197,7 @@ GEM ffi (1.15.5) figaro (1.2.0) thor (>= 0.14.0, < 2) - font-awesome-sass (6.1.2) + font-awesome-sass (6.2.0) sassc (~> 2.0) front_matter_parser (1.0.1) gdpr (1.2.3) @@ -237,7 +237,7 @@ GEM js_cookie_rails (2.2.0) railties (>= 3.1) json (2.6.2) - jwt (2.4.1) + jwt (2.5.0) kamifusen (1.11.2) image_processing rails @@ -301,7 +301,7 @@ GEM multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - octokit (5.3.0) + octokit (5.4.0) faraday (>= 1, < 3) sawyer (~> 0.9) omniauth (2.1.0) @@ -359,7 +359,7 @@ GEM thor (~> 1.0) rake (13.0.6) randexp (0.1.7) - rb-fsevent (0.11.1) + rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) regexp_parser (2.5.0) diff --git a/app/assets/javascripts/admin/plugins/summernote.js b/app/assets/javascripts/admin/plugins/summernote.js index 38f2cf166fd46ca3a4329ee4586a10dd5024e7db..99cbf9a1005a7598418aa04c45c5c1ff9ede935e 100644 --- a/app/assets/javascripts/admin/plugins/summernote.js +++ b/app/assets/javascripts/admin/plugins/summernote.js @@ -8,7 +8,7 @@ $(function () { toolbar: [ ['font', ['bold', 'italic']], ['position', ['superscript', 'subscript']], - ['insert', ['link']], + ['insert', ['link', 'unlink']], ['view', ['codeview']] ], followingToolbar: true, @@ -20,7 +20,7 @@ $(function () { ['font', ['bold', 'italic']], ['position', ['superscript', 'subscript']], ['para', ['ul', 'ol']], - ['insert', ['link']], + ['insert', ['link', 'unlink']], ['view', ['codeview']] ], followingToolbar: true, @@ -40,7 +40,7 @@ $(function () { ['position', ['superscript', 'subscript']], ['para', ['ul', 'ol']], ['table', ['table']], - ['insert', ['link', 'picture', 'video']], + ['insert', ['link', 'unlink', 'picture', 'video']], ['view', ['codeview']] ], styleTags: [ diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 621f531fc6adc57e5084a69b87d6838f4304c780..de7c091e874ffbef4836ffccd4c679ba9dd95634 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -41,4 +41,12 @@ module ApplicationHelper .gsub('https://www.twitter.com/', 'https://twitter.com/') .gsub('https://twitter.com/', '') end + + def masked_email(string) + string.gsub(/(?<=.{2}).*@.*(?=\S{2})/, '****@****') + end + + def masked_phone(string) + string.gsub(/(?<=.{3}).+(?=.{2})/, '*******') + end end diff --git a/app/models/communication/block/template/contact.rb b/app/models/communication/block/template/contact.rb index b298da6c9c4c4159e26efd0e3dddce754f1e76d9..4ddd562dd364aa1bf7c343c2058d87d427b20253 100644 --- a/app/models/communication/block/template/contact.rb +++ b/app/models/communication/block/template/contact.rb @@ -1,5 +1,6 @@ class Communication::Block::Template::Contact < Communication::Block::Template::Base + has_component :description, :rich_text has_component :name, :string has_component :address, :text has_component :zipcode, :string diff --git a/app/models/user.rb b/app/models/user.rb index ee8e99f437f8767ad2cf4ffe352c06d4d73742e4..5beb59b86894660878943b89e3e573a7c165d264 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,6 +9,7 @@ # current_sign_in_at :datetime # current_sign_in_ip :string # direct_otp :string +# direct_otp_delivery_method :string # direct_otp_sent_at :datetime # email :string default(""), not null, indexed => [university_id] # encrypted_otp_secret_key :string indexed diff --git a/app/models/user/with_authentication.rb b/app/models/user/with_authentication.rb index 586a347fe30c3035b8d0f69ff90ec07c45333caf..4a7a5ee0cb060b89f2e70c381dfe767e10f44fba 100644 --- a/app/models/user/with_authentication.rb +++ b/app/models/user/with_authentication.rb @@ -38,8 +38,8 @@ module User::WithAuthentication true end - def send_two_factor_authentication_code(code, options = {}) - if mobile_phone.blank? || options.dig(:delivery_method) == :email + def send_two_factor_authentication_code(code, delivery_method) + if mobile_phone.blank? || delivery_method == :email send_devise_notification(:two_factor_authentication_code, code, {}) else Sendinblue::SmsService.send_mfa_code(self, code) diff --git a/app/views/admin/communication/blocks/components/image/_preview.html.erb b/app/views/admin/communication/blocks/components/image/_preview.html.erb index 82f354a478c81c499a9a62f8f76184459dae490b..e3088f599613d5e52c8ee268faf03129a5823001 100644 --- a/app/views/admin/communication/blocks/components/image/_preview.html.erb +++ b/app/views/admin/communication/blocks/components/image/_preview.html.erb @@ -2,4 +2,15 @@ blob = component.blob return unless blob %> -<%= kamifusen_tag blob, width: 600, class: 'img-fluid mb-1' %> + +<section class="block-image"> + <div class="container"> + <div class="block-content"> + <%= kamifusen_tag blob, width: 600, class: 'img-fluid mb-1' %> + <figcaption> + <%= component.template.credit if component.template.credit.present? %> + </figcaption> + </figure> + </div> + </div> +</section> diff --git a/app/views/admin/communication/blocks/templates/contact/_edit.html.erb b/app/views/admin/communication/blocks/templates/contact/_edit.html.erb index e9a904fa5343b482ef80051a6341f4cb2fca2e40..0da97e4049eba2b564c6c931cd28faeff8039dad 100644 --- a/app/views/admin/communication/blocks/templates/contact/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/contact/_edit.html.erb @@ -1,3 +1,8 @@ +<div class="row"> + <div class="col-xl-6"> + <%= block_component_edit :description %> + </div> +</div> <div class="row mb-4"> <div class="col-md-6 col-xl-4"> <div class="card"> @@ -6,7 +11,7 @@ </div> <div class="card-body"> <%= block_component_edit :name %> - <%= block_component_edit :address, rows: 1 %> + <%= block_component_edit :address %> <div class="row"> <div class="col-md-4"> <%= block_component_edit :zipcode %> @@ -35,7 +40,6 @@ <input type="tel" class="form-control" placeholder="<%= t '.phones.placeholder' %>" - maxlength="12" v-model="data.phone_numbers[index]"> <a class="btn text-danger" v-on:click="data.phone_numbers.splice(index, 1)"> <i class="fas fa-times"></i> diff --git a/app/views/admin/communication/blocks/templates/contact/_preview.html.erb b/app/views/admin/communication/blocks/templates/contact/_preview.html.erb index 83caa0c2ce3df20e345e15d82769f4081f084032..579b9f6d22b5581c9ab0d68d43c9711a4076d050 100644 --- a/app/views/admin/communication/blocks/templates/contact/_preview.html.erb +++ b/app/views/admin/communication/blocks/templates/contact/_preview.html.erb @@ -1,10 +1,13 @@ -<p><%= block_component_preview :name %></p> -<div> - <%= block_component_preview :address %> - <%= block_component_preview :zipcode %> - <%= block_component_preview :city %> - <%= block_component_preview :country %> -</div> +<%= block_component_preview :description %> +<p> + <%= block_component_preview :name %><br> + <% if @block.template.address.present? %> + <%= @block.template.address %><br> + <% end %> + <%= block_component_preview :zipcode %> + <%= block_component_preview :city %> + <%= block_component_preview :country %> +</p> <table class="table"> <% @block.template.elements.each do |element| %> <tr> diff --git a/app/views/admin/communication/blocks/templates/contact/_static.html.erb b/app/views/admin/communication/blocks/templates/contact/_static.html.erb index 68fb64850456a932aeebdec56580854d96929fa5..16c95afe197a835858b7c865e9bfc85c1c68f305 100644 --- a/app/views/admin/communication/blocks/templates/contact/_static.html.erb +++ b/app/views/admin/communication/blocks/templates/contact/_static.html.erb @@ -1,5 +1,10 @@ +<%= block_component_static :description %> <%= block_component_static :name %> -<%= block_component_static :address %> + address: +<%= block_component_static :address, depth: 4 %> +<%= block_component_static :zipcode, depth: 4 %> +<%= block_component_static :city, depth: 4 %> +<%= block_component_static :country, depth: 4 %> <%= block_component_static :phone_numbers %> <%= block_component_static :emails %> timetable: diff --git a/app/views/devise/two_factor_authentication/show.html.erb b/app/views/devise/two_factor_authentication/show.html.erb index cab70e54f297c8d0a8a74decdd10f0bdc4145916..5a9fca5a6ce8c5a726a0b1a33829551479098c16 100644 --- a/app/views/devise/two_factor_authentication/show.html.erb +++ b/app/views/devise/two_factor_authentication/show.html.erb @@ -1,10 +1,14 @@ -<h2> +<h4> <% if resource.direct_otp %> - <%= t('devise.two_factor_authentication.enter_code_direct_otp') %> + <% if resource.direct_otp_delivery_method == 'mobile_phone' %> + <%= t('devise.two_factor_authentication.enter_code_direct_otp_mobile_phone', phone: masked_phone(resource.mobile_phone)) %> + <% else %> + <%= t('devise.two_factor_authentication.enter_code_direct_otp_email', mail: masked_email(resource.email)) %> + <% end %> <% else %> <%= t('devise.two_factor_authentication.enter_code_totp') %> <% end %> -</h2> +</h4> <%= simple_form_for(resource, url: user_two_factor_authentication_path, html: { method: :put, class: 'my-3' }) do |f| %> <div class="row"> @@ -38,7 +42,7 @@ method: :delete, class: "btn btn-danger float-end" %> <%= f.button :submit, - t('validate'), + t('devise.two_factor_authentication.validate'), class: "btn btn-primary" %> </div> </div> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 43f86bae1fca1f2a794e6a55bc662262e88e97e2..b4f03422224b7a22a19f1f28131dd6bd691206c5 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -210,6 +210,9 @@ en: country: label: Country placeholder: Enter the country + description: + label: Description + placeholder: Enter description here element: title: label: Day diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 29a758f331e22bbcec281fbe53fa58dc4aebabb2..171268b0657ab43b04a76ae2e6892f94913fa89b 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -210,6 +210,9 @@ fr: country: label: Pays placeholder: Entrer le nom du pays + description: + label: Description + placeholder: Entrer la description element: title: label: Jour diff --git a/config/locales/en.yml b/config/locales/en.yml index 81d8721d041f8b765046598b0036baaf8552c619..7f6a99253679252925f544c788425e7385ab7eb0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -143,7 +143,8 @@ en: admin_unlock: Unlock it now! attempt_failed: "Invalid Code" code_has_been_sent: "Your authentication code has been sent." - enter_code_direct_otp: "Enter the code that was sent to you" + enter_code_direct_otp_email: "Enter the code that was sent to you on your email %{mail}" + enter_code_direct_otp_mobile_phone: "Enter the code that was sent to you on your mobile phone %{phone}" enter_code_totp: "Enter the code from your authentication application" max_login_attempts_reached: "You're account has been locked for security reasons.<br />Please contact an administrator." resend_code: "Resend Code" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 50fb3b6871d3b6ce0bb66b5c6b686cbb5ac089d3..25cb07d8a32032e3ccc8e21a9f0fd2e53a01489a 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -146,7 +146,8 @@ fr: admin_unlock: Le débloquer ! attempt_failed: "Code invalide" code_has_been_sent: "Un code d'authentification vient de vous être envoyé." - enter_code_direct_otp: "Entrez le code qui vous a été envoyé" + enter_code_direct_otp_email: "Entrez le code qui vous a été envoyé sur votre mail %{mail}" + enter_code_direct_otp_mobile_phone: "Entrez le code qui vous a été envoyé sur votre mobile %{phone}" enter_code_totp: "Entrez le code de votre application d'authentification" max_login_attempts_reached: "Votre compte a été bloqué pour des raisons de sécurité.<br />Veuillez contacter un administrateur." resend_code: "Renvoyer le code" diff --git a/db/migrate/20220901160808_add_two_factor_fields_to_users.rb b/db/migrate/20220901160808_add_two_factor_fields_to_users.rb new file mode 100644 index 0000000000000000000000000000000000000000..4b5e910274272ace6dabd0716b2018d895bb43b6 --- /dev/null +++ b/db/migrate/20220901160808_add_two_factor_fields_to_users.rb @@ -0,0 +1,5 @@ +class AddTwoFactorFieldsToUsers < ActiveRecord::Migration[6.1] + def change + add_column :users, :direct_otp_delivery_method, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 5f9451178ec0ad09927a24371f27380cdebae8af..feaba49d28a37e6055e23429c5cbdd401a9b617e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_08_02_151713) do +ActiveRecord::Schema.define(version: 2022_09_01_160808) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -794,6 +794,7 @@ ActiveRecord::Schema.define(version: 2022_08_02_151713) do t.datetime "totp_timestamp" t.string "session_token" t.string "picture_url" + t.string "direct_otp_delivery_method" t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email", "university_id"], name: "index_users_on_email_and_university_id", unique: true t.index ["encrypted_otp_secret_key"], name: "index_users_on_encrypted_otp_secret_key", unique: true