Browse Source
* Use Notify rather than Gmail for devise emails * Remove Devise mailer views * Use real account template IDspull/246/head
baarkerlounger
3 years ago
committed by
GitHub
16 changed files with 118 additions and 60 deletions
@ -0,0 +1,49 @@
|
||||
class DeviseNotifyMailer < Devise::Mailer |
||||
require "notifications/client" |
||||
|
||||
RESET_PASSWORD_TEMPLATE_ID = "2c410c19-80a7-481c-a531-2bcb3264f8e6".freeze |
||||
SET_PASSWORD_TEMPLATE_ID = "257460a6-6616-4640-a3f9-17c3d73d9e91".freeze |
||||
|
||||
def notify_client |
||||
@notify_client ||= ::Notifications::Client.new(ENV["GOVUK_NOTIFY_API_KEY"]) |
||||
end |
||||
|
||||
def host |
||||
@host ||= ENV["APP_HOST"] |
||||
end |
||||
|
||||
def send_email(email, template_id, personalisation) |
||||
notify_client.send_email( |
||||
email_address: email, |
||||
template_id: template_id, |
||||
personalisation: personalisation, |
||||
) |
||||
end |
||||
|
||||
def reset_password_instructions(record, token, _opts = {}) |
||||
template_id = record.last_sign_in_at ? RESET_PASSWORD_TEMPLATE_ID : SET_PASSWORD_TEMPLATE_ID |
||||
personalisation = { |
||||
name: record.name, |
||||
email: record.email, |
||||
organisation: record.organisation.name, |
||||
link: "https://#{host}/users/password/edit?reset_password_token=#{token}", |
||||
} |
||||
send_email(record.email, template_id, personalisation) |
||||
end |
||||
|
||||
# def confirmation_instructions(record, token, _opts = {}) |
||||
# super |
||||
# end |
||||
# |
||||
# def unlock_instructions(record, token, opts = {}) |
||||
# super |
||||
# end |
||||
# |
||||
# def email_changed(record, opts = {}) |
||||
# super |
||||
# end |
||||
# |
||||
# def password_change(record, opts = {}) |
||||
# super |
||||
# end |
||||
end |
@ -1,8 +0,0 @@
|
||||
<p>Hello <%= @resource.email %>!</p> |
||||
|
||||
<p>Someone has requested a link to change your password. You can do this through the link below.</p> |
||||
|
||||
<p><%= govuk_link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p> |
||||
|
||||
<p>If you didn't request this, please ignore this email.</p> |
||||
<p>Your password won't change until you access the link above and create a new one.</p> |
@ -1,6 +0,0 @@
|
||||
<p>Hello <%= @resource.name %>!</p> |
||||
|
||||
<p>An account has been created for you to submit CORE data on behalf of <%= @resource.organisation.name %>.</p> |
||||
|
||||
<p>Your username is <%= @resource.email %>, use the link below to set your password. |
||||
<p><%= govuk_link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p> |
@ -1,5 +0,0 @@
|
||||
<p>Welcome <%= @email %>!</p> |
||||
|
||||
<p>You can confirm your account email through the link below:</p> |
||||
|
||||
<p><%= govuk_link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p> |
@ -1,7 +0,0 @@
|
||||
<p>Hello <%= @email %>!</p> |
||||
|
||||
<% if @resource.try(:unconfirmed_email?) %> |
||||
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p> |
||||
<% else %> |
||||
<p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p> |
||||
<% end %> |
@ -1,3 +0,0 @@
|
||||
<p>Hello <%= @resource.email %>!</p> |
||||
|
||||
<p>We're contacting you to notify you that your password has been changed.</p> |
@ -1,5 +0,0 @@
|
||||
<% if @resource.last_sign_in_at.nil? %> |
||||
<%= render partial: "password_change_initial" %> |
||||
<% else %> |
||||
<%= render partial: "password_change_forgotten" %> |
||||
<% end %> |
@ -1,7 +0,0 @@
|
||||
<p>Hello <%= @resource.email %>!</p> |
||||
|
||||
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p> |
||||
|
||||
<p>Click the link below to unlock your account:</p> |
||||
|
||||
<p><%= govuk_link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p> |
@ -1,12 +1,18 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe "password_reset", type: :request do |
||||
RSpec.describe UsersController, type: :request do |
||||
let(:user) { FactoryBot.create(:user) } |
||||
let(:unauthorised_user) { FactoryBot.create(:user) } |
||||
let(:headers) { { "Accept" => "text/html" } } |
||||
let(:page) { Capybara::Node::Simple.new(response.body) } |
||||
let(:new_value) { "new test name" } |
||||
let(:params) { { id: user.id, user: { name: new_value } } } |
||||
let(:notify_client) { double(Notifications::Client) } |
||||
|
||||
before do |
||||
allow_any_instance_of(DeviseNotifyMailer).to receive(:notify_client).and_return(notify_client) |
||||
allow(notify_client).to receive(:send_email).and_return(true) |
||||
end |
||||
|
||||
context "a not signed in user" do |
||||
describe "#show" do |
Loading…
Reference in new issue