Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Confirmation Emails: Add way to resend (#287)

Dylan Corrales2064d7e37432
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 87beba71c9..067abbd253 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -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
diff --git a/app/models/user.rb b/app/models/user.rb
index a3ca25adad..b62ab8b612 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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)
diff --git a/app/views/settings/profiles/show.html.erb b/app/views/settings/profiles/show.html.erb
index 2e78beec9a..f9f4077f01 100644
--- a/app/views/settings/profiles/show.html.erb
+++ b/app/views/settings/profiles/show.html.erb
@@ -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 %>
diff --git a/config/locales/views/users/en.yml b/config/locales/views/users/en.yml
index 44ab2ff8a6..48528761c0 100644
--- a/config/locales/views/users/en.yml
+++ b/config/locales/views/users/en.yml
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index fbdecead05..1f8f2d0da7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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