diff --git a/app/controllers/auth/confirmations_controller.rb b/app/controllers/auth/confirmations_controller.rb new file mode 100644 index 000000000..4b6a37372 --- /dev/null +++ b/app/controllers/auth/confirmations_controller.rb @@ -0,0 +1,9 @@ +class Auth::ConfirmationsController < Devise::ConfirmationsController + def create + super + end + + def show + super + end +end diff --git a/app/mailers/devise_notify_mailer.rb b/app/mailers/devise_notify_mailer.rb index 3d44cbec2..0a260dc3d 100644 --- a/app/mailers/devise_notify_mailer.rb +++ b/app/mailers/devise_notify_mailer.rb @@ -13,7 +13,7 @@ class DeviseNotifyMailer < Devise::Mailer ) end - def reset_password_instructions(record, token, _opts = {}) + def personalisation(record, token) url = public_send("edit_#{record.class.name.underscore}_password_url") personalisation = { name: record.name || record.email, @@ -21,13 +21,24 @@ class DeviseNotifyMailer < Devise::Mailer organisation: record.respond_to?(:organisation) ? record.organisation.name : "", link: "#{url}?reset_password_token=#{token}", } - send_email(record.email, record.reset_password_notify_template, personalisation) end - # def confirmation_instructions(record, token, _opts = {}) - # super - # end - # + def reset_password_instructions(record, token, _opts = {}) + send_email( + record.email, + record.reset_password_notify_template, + personalisation(record, token) + ) + end + + def confirmation_instructions(record, token, _opts = {}) + send_email( + record.email, + record.confirmable_template, + personalisation(record, token) + ) + end + # def unlock_instructions(record, token, opts = {}) # super # end diff --git a/app/models/user.rb b/app/models/user.rb index 6cb41585b..5e8f0f627 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,8 +1,8 @@ class User < ApplicationRecord # Include default devise modules. Others available are: - # :confirmable, :timeoutable and :omniauthable + # :omniauthable devise :database_authenticatable, :recoverable, :rememberable, :validatable, - :trackable, :lockable, :two_factor_authenticatable + :trackable, :lockable, :two_factor_authenticatable, :confirmable, :timeoutable belongs_to :organisation has_many :owned_case_logs, through: :organisation @@ -66,10 +66,14 @@ class User < ApplicationRecord MFA_TEMPLATE_ID = "6bdf5ee1-8e01-4be1-b1f9-747061d8a24c".freeze RESET_PASSWORD_TEMPLATE_ID = "2c410c19-80a7-481c-a531-2bcb3264f8e6".freeze - SET_PASSWORD_TEMPLATE_ID = "257460a6-6616-4640-a3f9-17c3d73d9e91".freeze + CONFIRMABLE_TEMPLATE_ID = "257460a6-6616-4640-a3f9-17c3d73d9e91".freeze def reset_password_notify_template - last_sign_in_at ? RESET_PASSWORD_TEMPLATE_ID : SET_PASSWORD_TEMPLATE_ID + RESET_PASSWORD_TEMPLATE_ID + end + + def confirmable_template + CONFIRMABLE_TEMPLATE_ID end def need_two_factor_authentication?(_request) diff --git a/app/views/devise/confirmations/new.html.erb b/app/views/devise/confirmations/new.html.erb index fe57a4a06..1b9ca13ea 100644 --- a/app/views/devise/confirmations/new.html.erb +++ b/app/views/devise/confirmations/new.html.erb @@ -1,15 +1,32 @@ -
Enter your email address to get a new invitation link.
- <%= f.govuk_email_field :email, - label: { text: "Email address" }, - autocomplete: "email", - spellcheck: "false", - value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> + <%= f.govuk_email_field :email, + label: { text: "Email address" }, + autocomplete: "email", + spellcheck: "false", + value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> - <%= f.govuk_submit "Resend confirmation instructions" %> + <%= f.govuk_submit "Send email" %> +