From 4dc6149530f57e76324c9d4437b77217b706b27f Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Sat, 6 Sep 2025 11:10:45 +0300 Subject: [PATCH] add reset password link --- app/controllers/passwords_controller.rb | 6 ++++++ app/controllers/users_controller.rb | 1 + .../users_send_reset_password_controller.rb | 2 +- app/views/profile/index.html.erb | 4 ++-- app/views/users/_form.html.erb | 10 +++++++++- config/locales/i18n.yml | 19 ++++++++++++------- spec/system/profile_settings_spec.rb | 5 ++++- spec/system/team_settings_spec.rb | 1 - 8 files changed, 35 insertions(+), 13 deletions(-) diff --git a/app/controllers/passwords_controller.rb b/app/controllers/passwords_controller.rb index 5ae3ff32..60de5b12 100644 --- a/app/controllers/passwords_controller.rb +++ b/app/controllers/passwords_controller.rb @@ -20,4 +20,10 @@ class PasswordsController < Devise::PasswordsController Current.user = resource end end + + private + + def after_resetting_password_path_for(_) + new_session_path(resource_name) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index da60da91..39cbc223 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -30,6 +30,7 @@ class UsersController < ApplicationController return render turbo_stream: turbo_stream.replace(:modal, template: 'users/new'), status: :unprocessable_content end + @user.password = SecureRandom.hex if @user.password.blank? @user.role = User::ADMIN_ROLE unless role_valid?(@user.role) if @user.save diff --git a/app/controllers/users_send_reset_password_controller.rb b/app/controllers/users_send_reset_password_controller.rb index e75695af..f6a8af82 100644 --- a/app/controllers/users_send_reset_password_controller.rb +++ b/app/controllers/users_send_reset_password_controller.rb @@ -14,7 +14,7 @@ class UsersSendResetPasswordController < ApplicationController @user.send_reset_password_instructions redirect_back fallback_location: settings_users_path, - notice: I18n.t('you_will_receive_an_email_with_password_reset_instructions_in_a_few_minutes') + notice: I18n.t('an_email_with_password_reset_instructions_has_been_sent') end end end diff --git a/app/views/profile/index.html.erb b/app/views/profile/index.html.erb index 38461675..c5422b00 100644 --- a/app/views/profile/index.html.erb +++ b/app/views/profile/index.html.erb @@ -57,7 +57,7 @@ <%= form_for current_user, url: update_password_settings_profile_index_path, method: :patch, html: { autocomplete: 'off' } do |f| %> <%= f.label :password, t('new_password'), class: 'label' %> <%= f.password_field :password, autocomplete: 'off', class: 'base-input peer w-full', required: true %> -
+
<%= f.label :password_confirmation, t('confirm_password'), class: 'label' %> <%= f.password_field :password_confirmation, autocomplete: 'off', class: 'base-input' %> @@ -67,7 +67,7 @@ <%= f.password_field :current_password, autocomplete: 'current-password', class: 'base-input' %> <% if Accounts.can_send_emails?(current_account) %> - <%= t('dont_remember_your_current_password_click_here_to_reset_it_html', link: new_user_password_url) %> + <%= t('dont_remember_your_current_password_click_here_to_reset_it_html') %> <% end %>
diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 19b9f0f2..5ceaeabc 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -13,11 +13,16 @@
<%= f.label :email, t('email'), class: 'label' %> <%= f.email_field :email, required: true, class: 'base-input' %> + <% if user.persisted? && Accounts.can_send_emails?(current_account) %> + + <%= t('click_here_to_send_a_reset_password_email_html') %> + + <% end %>
<% if user.new_record? && !Docuseal.multitenant? %>
<%= f.label :password, t('password'), class: 'label' %> - <%= f.password_field :password, required: true, class: 'base-input' %> + <%= f.password_field :password, class: 'base-input' %>
<% end %> <% if f.object != current_user %> @@ -37,3 +42,6 @@ <%= f.button button_title, class: 'base-button' %>
<% end %> +<% if user.persisted? %> + <%= button_to nil, user_send_reset_password_path(user), id: 'resend_password_button', method: :put, class: 'hidden', data: { turbo_confirm: t('are_you_sure_'), turbo_frame: :_top } %> +<% end %> diff --git a/config/locales/i18n.yml b/config/locales/i18n.yml index 07604244..18da4440 100644 --- a/config/locales/i18n.yml +++ b/config/locales/i18n.yml @@ -27,6 +27,7 @@ en: &en enabled: Enabled disabled: Disabled party: Party + click_here_to_send_a_reset_password_email_html: ' to send a reset password email.' edit_order: Edit Order expirable_file_download_links: Expirable file download links invite_form_fields: Invite form fields @@ -46,7 +47,7 @@ en: &en pending_by_me: Pending by me partially_completed: Partially completed require_phone_2fa_to_open: Require phone 2FA to open - the_sender_has_requested_a_two_factor_authentication_via_one_time_password_sent_to_your_html: The sender has requested a two factor authentication via one time password sent to your %{phone} phone number. + the_sender_has_requested_a_two_factor_authentication_via_one_time_password_sent_to_your_html: The sender has requested two-factor authentication via a one-time password sent to your %{phone} phone number. send_verification_code: Send verification code code_has_been_resent: Code has been re-sent invalid_code: Invalid code @@ -803,7 +804,7 @@ en: &en wrong_password: Wrong password. current_password: Current password dont_remember_your_current_password_click_here_to_reset_it_html: 'Don''t remember your current password? to reset it.' - you_will_receive_an_email_with_password_reset_instructions_in_a_few_minutes: You will receive an email with password reset instructions in a few minutes. + an_email_with_password_reset_instructions_has_been_sent: An email with password reset instructions has been sent. submission_sources: api: API bulk: Bulk Send @@ -1693,7 +1694,7 @@ es: &es wrong_password: Contraseña incorrecta. current_password: Contraseña actual dont_remember_your_current_password_click_here_to_reset_it_html: '¿No recuerdas tu contraseña actual? para restablecerla.' - you_will_receive_an_email_with_password_reset_instructions_in_a_few_minutes: Recibirás un correo electrónico con las instrucciones para restablecer tu contraseña en unos minutos. + an_email_with_password_reset_instructions_has_been_sent: Se enviará un correo electrónico con las instrucciones para restablecer tu contraseña en unos minutos. submission_sources: api: API bulk: Envío masivo @@ -1800,6 +1801,7 @@ es: &es range_without_total: "%{from}-%{to} eventos" it: &it + click_here_to_send_a_reset_password_email_html: ' per inviare una email per reimpostare la password.' enabled: Abilitato disabled: Disabilitato expirable_file_download_links: Link di download di file con scadenza @@ -2583,7 +2585,7 @@ it: &it wrong_password: Password errata. current_password: Password attuale dont_remember_your_current_password_click_here_to_reset_it_html: 'Non ricordi la tua password attuale? per reimpostarla.' - you_will_receive_an_email_with_password_reset_instructions_in_a_few_minutes: Riceverai un'email con le istruzioni per reimpostare la password entro pochi minuti. + an_email_with_password_reset_instructions_has_been_sent: Un'email con le istruzioni per reimpostare la password ti è stata inviata e arriverà entro pochi minuti. submission_sources: api: API bulk: Invio massivo @@ -2690,6 +2692,7 @@ it: &it range_without_total: "%{from}-%{to} eventi" fr: &fr + click_here_to_send_a_reset_password_email_html: ' pour envoyer un e-mail de réinitialisation du mot de passe.' enabled: Activé disabled: Désactivé expirable_file_download_links: Liens de téléchargement de fichiers expirables @@ -3476,7 +3479,7 @@ fr: &fr wrong_password: Mot de passe incorrect. current_password: Mot de passe actuel dont_remember_your_current_password_click_here_to_reset_it_html: 'Vous ne vous souvenez plus de votre mot de passe actuel ? pour le réinitialiser.' - you_will_receive_an_email_with_password_reset_instructions_in_a_few_minutes: Vous recevrez un e-mail avec les instructions de réinitialisation de votre mot de passe dans quelques minutes. + an_email_with_password_reset_instructions_has_been_sent: Un e-mail contenant les instructions pour réinitialiser votre mot de passe vous sera envoyé dans quelques minutes. submission_sources: api: API bulk: Envoi en masse @@ -3583,6 +3586,7 @@ fr: &fr range_without_total: "%{from} à %{to} événements" pt: &pt + click_here_to_send_a_reset_password_email_html: ' para enviar um e-mail de redefinição de senha.' enabled: Ativado disabled: Desativado expirable_file_download_links: Links de download de arquivos com expiração @@ -4367,7 +4371,7 @@ pt: &pt wrong_password: Senha incorreta. current_password: Senha atual dont_remember_your_current_password_click_here_to_reset_it_html: 'Não se lembra da sua senha atual? para redefini-la.' - you_will_receive_an_email_with_password_reset_instructions_in_a_few_minutes: Você receberá um e-mail com as instruções para redefinir sua senha em alguns minutos. + an_email_with_password_reset_instructions_has_been_sent: Um e-mail com instruções para redefinir sua senha será enviado em alguns minutos. submission_sources: api: API bulk: Envio em massa @@ -4474,6 +4478,7 @@ pt: &pt range_without_total: "%{from}-%{to} eventos" de: &de + click_here_to_send_a_reset_password_email_html: ', um eine E-Mail zum Zurücksetzen des Passworts zu senden.' enabled: Aktiviert disabled: Deaktiviert expirable_file_download_links: Ablaufbare Datei-Download-Links @@ -5258,7 +5263,7 @@ de: &de wrong_password: Falsches Passwort. current_password: Aktuelles Passwort dont_remember_your_current_password_click_here_to_reset_it_html: 'Sie erinnern sich nicht an Ihr aktuelles Passwort? , um es zurückzusetzen.' - you_will_receive_an_email_with_password_reset_instructions_in_a_few_minutes: Sie erhalten in wenigen Minuten eine E-Mail mit Anweisungen zum Zurücksetzen Ihres Passworts. + an_email_with_password_reset_instructions_has_been_sent: Eine E-Mail mit Anweisungen zum Zurücksetzen Ihres Passworts wurde Ihnen in wenigen Minuten zugesendet. submission_sources: api: API bulk: Massenversand diff --git a/spec/system/profile_settings_spec.rb b/spec/system/profile_settings_spec.rb index b7dc5691..9cce6088 100644 --- a/spec/system/profile_settings_spec.rb +++ b/spec/system/profile_settings_spec.rb @@ -5,6 +5,9 @@ RSpec.describe 'Profile Settings' do before do sign_in(user) + + allow(Accounts).to receive(:can_send_emails?).and_return(true) + visit settings_profile_index_path end @@ -79,7 +82,7 @@ RSpec.describe 'Profile Settings' do find('label', text: 'Click here').click end - expect(page).to have_content('You will receive an email with password reset instructions in a few minutes.') + expect(page).to have_content('An email with password reset instructions has been sent.') email = ActionMailer::Base.deliveries.last reset_password_url = email.body diff --git a/spec/system/team_settings_spec.rb b/spec/system/team_settings_spec.rb index 01ce568f..693f31df 100644 --- a/spec/system/team_settings_spec.rb +++ b/spec/system/team_settings_spec.rb @@ -115,7 +115,6 @@ RSpec.describe 'Team Settings' do fill_in 'First name', with: 'Adam' fill_in 'Last name', with: 'Meier' fill_in 'Email', with: 'adam.meier@example.com' - fill_in 'Password', with: 'new_password' expect do click_button 'Submit'