Confirmation Emails: Add way to resend (#287)

* Add way to resend confirmation email.

* Resend confirmation email if user sets it to the same as pending

* I10n: No pending email change
This commit is contained in:
Dylan Corrales
2025-11-04 17:11:26 -05:00
committed by GitHub
parent 6f1b651b80
commit 2064d7e374
5 changed files with 22 additions and 2 deletions

View File

@@ -2,6 +2,14 @@ class UsersController < ApplicationController
before_action :set_user
before_action :ensure_admin, only: %i[reset reset_with_sample_data]
def resend_confirmation_email
if @user.resend_confirmation_email
redirect_to settings_profile_path, notice: t(".success")
else
redirect_to settings_profile_path, alert: t("no_pending_change")
end
end
def update
@user = Current.user

View File

@@ -45,7 +45,6 @@ class User < ApplicationRecord
def initiate_email_change(new_email)
return false if new_email == email
return false if new_email == unconfirmed_email
if Rails.application.config.app_mode.self_hosted? && !Setting.require_email_confirmation
update(email: new_email)
@@ -59,6 +58,15 @@ class User < ApplicationRecord
end
end
def resend_confirmation_email
if pending_email_change?
EmailConfirmationMailer.with(user: self).confirmation_email.deliver_later
true
else
false
end
end
def request_impersonation_for(user_id)
impersonated = User.find(user_id)
impersonator_support_sessions.create!(impersonated: impersonated)

View File

@@ -9,7 +9,7 @@
<% if @user.unconfirmed_email.present? %>
<p class="mt-2 text-sm text-gray-600">
You have requested to change your email to <%= @user.unconfirmed_email %>. Please go to your email and confirm for the change to take effect.
You have requested to change your email to <%= @user.unconfirmed_email %>. Please go to your email and confirm for the change to take effect. If you haven't received the email, please check your spam folder, or <%= link_to "request a new confirmation email", resend_confirmation_email_user_path(@user), class: "hover:underline text-secondary" %>.
</p>
<% end %>

View File

@@ -8,6 +8,9 @@ en:
email_change_initiated: Please check your new email address for confirmation
instructions.
success: Your profile has been updated.
resend_confirmation_email:
success: A new confirmation email is queued to be sent.
no_pending_change: No email change is currently pending!
reset:
success: Your account has been reset. Data will be deleted in the background in some time.
unauthorized: You are not authorized to perform this action

View File

@@ -53,6 +53,7 @@ Rails.application.routes.draw do
delete :reset, on: :member
delete :reset_with_sample_data, on: :member
patch :rule_prompt_settings, on: :member
get :resend_confirmation_email, on: :member
end
resource :onboarding, only: :show do