debian-mirror-gitlab/app/controllers/concerns/confirm_email_warning.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
module ConfirmEmailWarning
2023-05-08 21:46:49 +05:30
include Gitlab::Utils::StrongMemoize
2019-10-12 21:52:04 +05:30
extend ActiveSupport::Concern
included do
2020-01-01 13:55:28 +05:30
before_action :set_confirm_warning, if: :show_confirm_warning?
2019-10-12 21:52:04 +05:30
end
protected
2020-01-01 13:55:28 +05:30
def show_confirm_warning?
2023-05-27 22:25:52 +05:30
html_request? && request.get? && Gitlab::CurrentSettings.email_confirmation_setting_soft?
2020-01-01 13:55:28 +05:30
end
2019-10-12 21:52:04 +05:30
def set_confirm_warning
return unless current_user
return if current_user.confirmed?
2023-03-17 16:20:25 +05:30
flash.now[:warning] = format(
confirm_warning_message,
2023-05-08 21:46:49 +05:30
email: email_to_display,
2019-10-12 21:52:04 +05:30
resend_link: view_context.link_to(_('Resend it'), user_confirmation_path(user: { email: email }), method: :post),
update_link: view_context.link_to(_('Update it'), profile_path)
2023-03-17 16:20:25 +05:30
).html_safe
end
private
2023-05-08 21:46:49 +05:30
def email
current_user.unconfirmed_email || current_user.email
end
strong_memoize_attr :email
2023-03-17 16:20:25 +05:30
def confirm_warning_message
_("Please check your email (%{email}) to verify that you own this address and unlock the power of CI/CD. Didn't receive it? %{resend_link}. Wrong email address? %{update_link}.")
2019-10-12 21:52:04 +05:30
end
2023-05-08 21:46:49 +05:30
def email_to_display
html_escape(email)
end
2019-10-12 21:52:04 +05:30
end