From 8ddc369fa21b08961da235abc83114372a9c4deb Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Tue, 12 Oct 2021 14:31:56 +0200 Subject: [PATCH] wip devise --- Gemfile | 1 + Gemfile.lock | 2 + app/assets/javascripts/admin.js | 3 +- app/assets/javascripts/application.js | 3 ++ app/models/language.rb | 2 + app/models/user/with_authentication.rb | 2 - app/views/devise/confirmations/new.html.erb | 4 +- app/views/devise/passwords/edit.html.erb | 17 +++++++-- app/views/devise/passwords/new.html.erb | 2 +- app/views/devise/registrations/new.html.erb | 5 ++- .../two_factor_authentication/show.html.erb | 37 ++++++++++--------- app/views/devise/unlocks/new.html.erb | 4 +- app/views/layouts/devise.html.erb | 3 ++ config/locales/en.yml | 32 ++++++++++++---- config/locales/fr.yml | 32 ++++++++++++---- 15 files changed, 101 insertions(+), 48 deletions(-) diff --git a/Gemfile b/Gemfile index ef1ba74ec..b9c56883d 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,7 @@ gem 'rails' gem 'rails-i18n' gem 'devise' gem 'devise-i18n' +gem 'i18n_data' gem 'cancancan' gem 'simple_form' gem 'simple_form_password_with_hints' diff --git a/Gemfile.lock b/Gemfile.lock index 74184be15..1f4173929 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -382,6 +382,7 @@ DEPENDENCIES enum_help figaro front_matter_parser + i18n_data image_processing jbuilder jquery-rails @@ -402,6 +403,7 @@ DEPENDENCIES simple-navigation simple_form simple_form_password_with_hints + sort_alphabetical spring two_factor_authentication! tzinfo-data diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js index 3e5e3ac51..ab6a73603 100644 --- a/app/assets/javascripts/admin.js +++ b/app/assets/javascripts/admin.js @@ -1,5 +1,4 @@ //= require jquery3 //= require jquery_ujs -//= require appstack/app - //= require simple_form_password_with_hints +//= require appstack/app diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index fb2627661..1721c5386 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -1,2 +1,5 @@ //= require popper //= require bootstrap-sprockets +//= require jquery3 +//= require jquery_ujs +//= require simple_form_password_with_hints diff --git a/app/models/language.rb b/app/models/language.rb index 8e707747d..ef16060ba 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -15,6 +15,8 @@ class Language < ApplicationRecord validates_presence_of :iso_code validates_uniqueness_of :iso_code + default_scope { order(name: :asc) } + def to_s "#{name}" end diff --git a/app/models/user/with_authentication.rb b/app/models/user/with_authentication.rb index 1ddf9a019..9b611de45 100644 --- a/app/models/user/with_authentication.rb +++ b/app/models/user/with_authentication.rb @@ -19,8 +19,6 @@ module User::WithAuthentication validate :password_complexity validates :mobile_phone, format: { with: /\A\+[0-9]+\z/ }, allow_blank: true - - before_validation :adjust_mobile_phone, :sanitize_fields def self.find_for_authentication(warden_conditions) diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb index 4e9d64195..76da94e61 100644 --- a/app/views/devise/confirmations/new.html.erb +++ b/app/views/devise/confirmations/new.html.erb @@ -1,4 +1,4 @@ -<h2><%= t(".resend_confirmation_instructions") %></h2> +<h2 class="text-center"><%= t(".resend_confirmation_instructions") %></h2> <%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> <%= f.error_notification %> @@ -12,7 +12,7 @@ input_html: { autocomplete: "email" } %> </div> - <div class="form-actions"> + <div class="form-actions text-center mt-3"> <%= f.button :submit, t(".resend_confirmation_instructions"), class: 'btn btn-lg btn-primary' %> </div> <% end %> diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb index c9edddabd..6b6834e5d 100644 --- a/app/views/devise/passwords/edit.html.erb +++ b/app/views/devise/passwords/edit.html.erb @@ -1,4 +1,4 @@ -<h2><%= t(".change_your_password") %></h2> +<h2 class="text-center"><%= t(".change_your_password") %></h2> <%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> <%= f.error_notification %> @@ -8,18 +8,29 @@ <div class="form-inputs"> <%= f.input :password, + as: :password_with_hints, label: t(".new_password"), required: true, autofocus: true, - hint: (t('devise.shared.minimum_password_length', count: @minimum_password_length) if @minimum_password_length), + allow_password_uncloaking: true, + validators: { + length: Devise.password_length.first, + uppercase_char: true, + lowercase_char: true, + numeric_char: true, + special_char: Rails.application.config.allowed_special_chars + }, input_html: { autocomplete: "new-password" } %> <%= f.input :password_confirmation, + as: :password_with_sync, label: t(".confirm_new_password"), required: true, + allow_password_uncloaking: true, + compare_with_field: :password, input_html: { autocomplete: "new-password" } %> </div> - <div class="form-actions"> + <div class="form-actions text-center mt-3"> <%= f.button :submit, t(".change_my_password"), class: 'btn btn-lg btn-primary' %> </div> <% end %> diff --git a/app/views/devise/passwords/new.html.erb b/app/views/devise/passwords/new.html.erb index d261dd729..8889103c5 100644 --- a/app/views/devise/passwords/new.html.erb +++ b/app/views/devise/passwords/new.html.erb @@ -10,7 +10,7 @@ input_html: { autocomplete: "email" } %> </div> - <div class="form-actions"> + <div class="form-actions text-center mt-3"> <%= f.button :submit, t(".send_me_reset_password_instructions"), class: 'btn btn-lg btn-primary' %> </div> <% end %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 7edbe797c..759226799 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,4 +1,4 @@ -<h2><%= t(".sign_up") %></h2> +<h2 class="text-center"><%= t(".sign_up") %></h2> <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= f.error_notification %> @@ -23,10 +23,11 @@ input_html: { autocomplete: "new-password" } %> <%= f.association :language, required: true, + label_method: lambda { |l| I18nData.languages(I18n.locale.to_s.upcase)[l.iso_code.to_s.upcase].capitalize }, include_blank: 'Sélectionnez une langue' %> </div> - <div class="form-actions"> + <div class="form-actions text-center mt-3"> <%= f.button :submit, t(".sign_up"), class: 'btn btn-lg btn-primary' %> </div> <% end %> diff --git a/app/views/devise/two_factor_authentication/show.html.erb b/app/views/devise/two_factor_authentication/show.html.erb index 4c730c362..676eb5979 100644 --- a/app/views/devise/two_factor_authentication/show.html.erb +++ b/app/views/devise/two_factor_authentication/show.html.erb @@ -1,44 +1,45 @@ -<div class="text-center"> - <p class="mb-4"> - <% if resource.direct_otp %> +<h2 class="text-center"> + <% if resource.direct_otp %> <%= t('devise.two_factor_authentication.enter_code_direct_otp') %> - <% else %> + <% else %> <%= t('devise.two_factor_authentication.enter_code_totp') %> - <% end %> - </p> + <% end %> +</h2> + <%= simple_form_for(resource, url: user_two_factor_authentication_path, html: { method: :put, class: 'my-3' }) do |f| %> <%= f.error_notification %> - <div class="form-inputs mb-3"> + <div class="form-inputs"> <div class="form-group required"> <div class="row"> <div class="col-md-4 offset-md-4"> <%= text_field_tag :code, '', - type: 'tel', - pattern: '\d*', - required: true, - autofocus: true, - autocomplete: 'off', - class: 'form-control string text-center required'%> + type: 'tel', + pattern: '\d*', + required: true, + autofocus: true, + autocomplete: 'off', + class: 'form-control string text-center required'%> </div> </div> </div> </div> - <div class="form-actions form-actions--center mb-4"> + <div class="form-actions text-center mt-3"> <%= f.button :submit, t('validate'), class: "btn btn-lg btn-primary" %> </div> <% end %> +<div class="text-center mt-2"> <% if resource.direct_otp %> - <p><%= link_to t('devise.two_factor_authentication.resend_code'), [:resend_code, resource_name, :two_factor_authentication] %></p> + <p><%= link_to t('devise.two_factor_authentication.resend_code'), [:resend_code, resource_name, :two_factor_authentication] %></p> <% else %> - <p><%= link_to t('devise.two_factor_authentication.send_code_instead'), [:resend_code, resource_name, :two_factor_authentication] %></p> + <p><%= link_to t('devise.two_factor_authentication.send_code_instead'), [:resend_code, resource_name, :two_factor_authentication] %></p> <% end %> <% unless resource.mobile_phone.blank? # when phone is blank default code method is already :email so we don't need another link %> - <p><%= link_to t('devise.two_factor_authentication.send_email_code'), [:resend_code, resource_name, :two_factor_authentication, delivery_method: :email] %></p> + <p><%= link_to t('devise.two_factor_authentication.send_email_code'), [:resend_code, resource_name, :two_factor_authentication, delivery_method: :email] %></p> <% end %> - <p><%= link_to t('devise.shared.links.sign_out'), destroy_user_session_path, class: "btn btn-lg btn-danger" %></p> + <p><%= link_to t('devise.shared.links.sign_out'), destroy_user_session_path, method: :delete, class: "btn btn-lg btn-danger" %></p> </div> diff --git a/app/views/devise/unlocks/new.html.erb b/app/views/devise/unlocks/new.html.erb index 79af1af7f..8ba6447b4 100644 --- a/app/views/devise/unlocks/new.html.erb +++ b/app/views/devise/unlocks/new.html.erb @@ -1,4 +1,4 @@ -<h2><%= t(".resend_unlock_instructions") %></h2> +<h2 class="text-center"><%= t(".resend_unlock_instructions") %></h2> <%= simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> <%= f.error_notification %> @@ -11,7 +11,7 @@ input_html: { autocomplete: "email" } %> </div> - <div class="form-actions"> + <div class="form-actions text-center mt-3"> <%= f.button :submit, t(".resend_unlock_instructions"), class: 'btn btn-lg btn-primary' %> </div> <% end %> diff --git a/app/views/layouts/devise.html.erb b/app/views/layouts/devise.html.erb index 834a33ea7..df3736443 100644 --- a/app/views/layouts/devise.html.erb +++ b/app/views/layouts/devise.html.erb @@ -14,6 +14,9 @@ <div class="main d-flex justify-content-center w-100"> <main class="content d-flex p-0"> <div class="container d-flex flex-column"> + <% unless notice.blank? %><div class="alert alert-success mt-2" role="alert"><div class="alert-message"><%= notice.html_safe %></div></div><% end %> + <% unless alert.blank? %><div class="alert alert-danger mt-2" role="alert"><div class="alert-message"><%= alert.html_safe %></div></div><% end %> + <div class="row h-100"> <div class="col-sm-10 col-md-8 col-lg-6 mx-auto d-table h-100"> <div class="d-table-cell align-middle"> diff --git a/config/locales/en.yml b/config/locales/en.yml index 941e35100..56dec7625 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,14 @@ en: activerecord: + attributes: + user: + email: Email + first_name: First name + language: Favourite language + last_name: Last name + mobile_phone: Mobile phone + researcher: Researcher profile + role: Role models: university: language: @@ -16,14 +25,6 @@ en: public: Public public_or_private: Public/private zipcode: Zipcode - user: - email: Email - first_name: First name - language: Favourite language - last_name: Last name - mobile_phone: Mobile phone - researcher: Researcher profile - role: Role one: User other: Users one: University @@ -32,6 +33,9 @@ en: dashboard: Dashboard delete: Delete devise: + failure: + invalid: "Invalid email or password." + not_found_in_database: "Invalid email or password." mailer: two_factor_authentication: subject: "Two-factor authentication code" @@ -49,6 +53,18 @@ en: send_email_code: 'Send me a code via email' success: "" text_html: "Your two-factor authentication code for %{university} is %{code}<br>It will expire in 5 minutes." + sessions: + signed_in: '' + two_factor_authentication: + 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_totp: "Enter the code from your Google Authenticator app" + max_login_attempts_reached: "You're account has been locked for security reasons.<br />Please contact an administrator." + resend_code: "Resend Code" + send_code_instead: "Send me a code instead" + send_email_code: 'Send me a code via email' + success: "" edit: Edit false: No home: Home diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 0758a3567..1ee02d4dd 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1,5 +1,14 @@ fr: activerecord: + attributes: + user: + email: Email + first_name: Prénom + language: Langue préférée + last_name: Nom + mobile_phone: Téléphone portable + researcher: Profil de chercheur + role: Rôle models: university: language: @@ -15,14 +24,6 @@ fr: private: Etablissement privé public: Public public_or_private: Public/privé - user: - email: Email - first_name: Prénom - language: Langue préférée - last_name: Nom - mobile_phone: Téléphone portable - researcher: Profil de chercheur - role: Rôle zipcode: Code postal one: Utilisateur other: Utilisateurs @@ -32,6 +33,9 @@ fr: dashboard: Tableau de bord delete: Supprimer devise: + failure: + invalid: "Email ou mot de passe incorrect." + not_found_in_database: "Email ou mot de passe incorrect." mailer: two_factor_authentication_code: subject: "Code d'authentification à deux facteurs" @@ -49,6 +53,18 @@ fr: send_email_code: 'Envoyer le code par email' success: "" text_html: "Votre code d'authentification pour %{university} est %{code}<br>Il expirera dans 5 minutes." + sessions: + signed_in: '' + two_factor_authentication: + 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_totp: "Entrez le code de votre appli Google Authenticator" + 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" + send_code_instead: "Envoyez-moi plutôt un code" + send_email_code: 'Envoyer le code par email' + success: "" edit: Modifier false: Non home: Accueil -- GitLab