From 00a155b89626276f5bbc8497b5170aa7c91dd1d3 Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Tue, 3 Sep 2024 16:59:53 +0200 Subject: [PATCH] add password complexity for instructeur, user and password change --- .../activate_account_form_component.html.haml | 15 +++++++++------ app/models/user.rb | 4 ---- app/views/devise/passwords/edit.html.haml | 11 ++++------- app/views/users/registrations/new.html.haml | 11 ++++++----- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/app/components/instructeurs/activate_account_form_component/activate_account_form_component.html.haml b/app/components/instructeurs/activate_account_form_component/activate_account_form_component.html.haml index 83c8155ce..731380dc4 100644 --- a/app/components/instructeurs/activate_account_form_component/activate_account_form_component.html.haml +++ b/app/components/instructeurs/activate_account_form_component/activate_account_form_component.html.haml @@ -11,13 +11,16 @@ .fr-fieldset__element %p.fr-text--sm= t('utils.mandatory_champs') - .fr-fieldset__element= render Dsfr::InputComponent.new(form: f, attribute: :email, input_type: :email_field, opts: { disabled: :disabled, class: 'fr-input-group--disabled', value: t('.email_disabled') }) + .fr-fieldset__element + = render Dsfr::InputComponent.new(form: f, attribute: :email, input_type: :email_field, opts: { disabled: :disabled, class: 'fr-input-group--disabled' }) - .fr-fieldset__element= render Dsfr::InputComponent.new(form: f, attribute: :password, input_type: :password_field, opts: { autocomplete: 'current-password' }) + .fr-fieldset__element + = render Dsfr::InputComponent.new(form: f, attribute: :password, input_type: :password_field, + opts: { autofocus: 'true', autocomplete: 'new-password', data: { controller: 'turbo-input', turbo_input_url_value: show_password_complexity_path }}) + + #password_complexity + = render PasswordComplexityComponent.new = f.hidden_field :reset_password_token, value: params[:token] - .fr-fieldset__element - .fr-btns-group--right.fr-btns-group.fr-btns-group--inline.fr-btns-group.fr-btns-group--inline - %ul - %li= f.submit t('.submit'), class: 'fr-mt-2v fr-btn fr-btn' + = f.submit t('.submit'), id: 'submit-password', class: "fr-btn fr-btn--lg fr-mt-2w", data: { disable_with: t('views.users.passwords.edit.submit_loading') } diff --git a/app/models/user.rb b/app/models/user.rb index 4936fac90..e6a659e43 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -44,10 +44,6 @@ class User < ApplicationRecord # plug our custom validation a la devise (same options) https://github.com/heartcombo/devise/blob/main/lib/devise/models/validatable.rb#L30 validates :email, strict_email: true, allow_blank: true, if: :devise_will_save_change_to_email? - def validate_password_complexity? - administrateur? - end - # Override of Devise::Models::Confirmable#send_confirmation_instructions def send_confirmation_instructions unless @raw_confirmation_token diff --git a/app/views/devise/passwords/edit.html.haml b/app/views/devise/passwords/edit.html.haml index 008f56ce7..ce2608d77 100644 --- a/app/views/devise/passwords/edit.html.haml +++ b/app/views/devise/passwords/edit.html.haml @@ -18,14 +18,11 @@ .fr-fieldset__element = render Dsfr::InputComponent.new(form: f, attribute: :password, input_type: :password_field, - opts: { autofocus: 'true', autocomplete: 'new-password', minlength: PASSWORD_MIN_LENGTH, data: { controller: populated_resource.validate_password_complexity? ? 'turbo-input' : false, turbo_input_url_value: show_password_complexity_path }}) do |c| + opts: { autofocus: 'true', autocomplete: 'new-password', minlength: PASSWORD_MIN_LENGTH, data: { controller: 'turbo-input', turbo_input_url_value: show_password_complexity_path }}) do |c| - c.with_describedby do - - if populated_resource.validate_password_complexity? - %div{ id: c.describedby_id } - #password_complexity - = render PasswordComplexityComponent.new - - else - = render partial: "devise/password_rules", locals: { id: c.describedby_id } + %div{ id: c.describedby_id } + #password_complexity + = render PasswordComplexityComponent.new .fr-fieldset__element = render Dsfr::InputComponent.new(form: f, attribute: :password_confirmation, input_type: :password_field, opts: { autocomplete: 'new-password' }) diff --git a/app/views/users/registrations/new.html.haml b/app/views/users/registrations/new.html.haml index 62a30b357..512c1e716 100644 --- a/app/views/users/registrations/new.html.haml +++ b/app/views/users/registrations/new.html.haml @@ -18,9 +18,10 @@ .fr-fieldset__element= render Dsfr::InputComponent.new(form: f, attribute: :email, input_type: :email_field, opts: { autocomplete: 'email', autofocus: true }) .fr-fieldset__element - = render Dsfr::InputComponent.new(form: f, attribute: :password, input_type: :password_field, opts: { autocomplete: 'new-password', minlength: PASSWORD_MIN_LENGTH }) do |c| - - c.with_describedby do - = render partial: "devise/password_rules", locals: { id: c.describedby_id } + = render Dsfr::InputComponent.new(form: f, attribute: :password, input_type: :password_field, + opts: { autofocus: 'true', autocomplete: 'new-password', data: { controller: 'turbo-input', turbo_input_url_value: show_password_complexity_path }}) - %ul.fr-btns-group - %li= f.submit t('views.shared.account.create'), class: "fr-btn" + #password_complexity + = render PasswordComplexityComponent.new + + = f.submit t('views.shared.account.create'), id: 'submit-password', class: "fr-btn fr-btn--lg fr-mt-2w", data: { disable_with: t('views.users.passwords.edit.submit_loading') }