From 04c14f97fa8d125f5c9a61e06d5e187dc923d84f Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Mon, 18 Oct 2021 16:44:38 +0200
Subject: [PATCH] unlock from admin

---
 .../users/registrations_controller.rb         |  2 +-
 app/views/admin/users/_lock.html.erb          | 20 +++++++++++--------
 app/views/devise/registrations/new.html.erb   |  1 +
 config/locales/en.yml                         |  4 ++++
 config/locales/fr.yml                         |  4 ++++
 5 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb
index c13527e25..f77babf2f 100644
--- a/app/controllers/users/registrations_controller.rb
+++ b/app/controllers/users/registrations_controller.rb
@@ -31,7 +31,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
   end
 
   def configure_sign_up_params
-    devise_parameter_sanitizer.permit(:sign_up, keys: [:language_id, :first_name, :last_name, :picture, :picture_infos, :picture_delete])
+    devise_parameter_sanitizer.permit(:sign_up, keys: [:mobile_phone, :language_id, :first_name, :last_name, :picture, :picture_infos, :picture_delete])
   end
 
   def configure_account_update_params
diff --git a/app/views/admin/users/_lock.html.erb b/app/views/admin/users/_lock.html.erb
index 02a9f27e9..7e0e3b166 100644
--- a/app/views/admin/users/_lock.html.erb
+++ b/app/views/admin/users/_lock.html.erb
@@ -1,17 +1,21 @@
 <% if @user.max_login_attempts? %>
   <div class="alert alert-danger">
-    This user account is currently <i>locked</i> due to too many MFA attempts.
-    <%= link_to  'Unlock it now!', unlock_admin_user_path(@user), method: :patch, class: 'alert-link' if can?(:update, @user) %>
+    <div class="alert-message">
+      <%= t('devise.two_factor_authentication.admin_locked_mfa_html') %>
+      <%= link_to t('devise.two_factor_authentication.admin_unlock'), unlock_admin_user_path(@user), method: :patch, class: 'alert-link' if can?(:update, @user) %>
+    </div>
   </div>
 <% end %>
 
 <% if @user.access_locked? %>
   <div class="alert alert-danger">
-    This user account is currently <i>locked</i>.
-    <% if [:time, :both].include?(Rails.configuration.devise.unlock_strategy) %>
-      <% distance = distance_of_time_in_words(@user.locked_at + Rails.configuration.devise.unlock_in - Time.now.utc) %>
-      <%= "It will unlock automatically in <i>#{distance}</i>.".html_safe %>
-    <% end %>
-    <%= link_to  'Unlock it now!', unlock_admin_user_path(@user), method: :patch, class: 'alert-link' if can?(:update, @user) %>
+    <div class="alert-message">
+      <%= t('devise.two_factor_authentication.admin_locked_html') %>
+      <% if [:time, :both].include?(Rails.configuration.devise.unlock_strategy) %>
+        <% distance = distance_of_time_in_words(@user.locked_at + Rails.configuration.devise.unlock_in - Time.now.utc) %>
+        <%= t('devise.two_factor_authentication.admin_unlock_in_html', distance: distance) %>
+      <% end %>
+      <%= link_to t('devise.two_factor_authentication.admin_unlock'), unlock_admin_user_path(@user), method: :patch, class: 'alert-link' if can?(:update, @user) %>
+    </div>
   </div>
 <% end %>
diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb
index 5aa32d831..0fed15704 100644
--- a/app/views/devise/registrations/new.html.erb
+++ b/app/views/devise/registrations/new.html.erb
@@ -39,6 +39,7 @@
                   allow_password_uncloaking: true,
                   compare_with_field: :password,
                   input_html: { autocomplete: "new-password" } %>
+      <%= f.input :mobile_phone %>
       <%= f.input :picture,
                         as: :single_deletable_file,
                         input_html: { accept: '.jpg,.jpeg,.png' },
diff --git a/config/locales/en.yml b/config/locales/en.yml
index e3f26967a..14d7fd4cd 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -52,6 +52,10 @@ en:
       links:
         sign_out: "Sign out"
     two_factor_authentication:
+      admin_locked_html: This user account is currently <i>locked</i>.
+      admin_locked_mfa_html: This user account is currently <i>locked</i> due to too many MFA attempts.
+      admin_unlock_in_html: It will unlock automatically in <i>%{distance}</i>.
+      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"
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index 30df3c05d..07e5a9d02 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -52,6 +52,10 @@ fr:
       links:
         sign_out: "Se déconnecter"
     two_factor_authentication:
+      admin_locked_html: Ce compte utilisateur est actuellement <i>verrouillé</i>.
+      admin_locked_mfa_html: Ce compte utilisateur est actuellement <i>verrouillé</i> à cause de tentatives de MFA excessives.
+      admin_unlock_in_html: Il se débloquera automatiquement dans <i>%{distance}</i>.
+      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é"
-- 
GitLab