diff --git a/Gemfile b/Gemfile index 7084e1e3e..f818540a3 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,8 @@ gem "bootsnap", ">= 1.4.4", require: false gem "govuk-components" # GOV UK component form builder DSL gem "govuk_design_system_formbuilder" +# GOV UK Notify +gem "notifications-ruby-client" # Turbo and Stimulus gem "hotwire-rails" # Soft delete ActiveRecords objects diff --git a/Gemfile.lock b/Gemfile.lock index a3ce16ddf..dc88dd12b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -186,6 +186,7 @@ GEM thor (>= 0.14, < 2.0) json-schema (2.8.1) addressable (>= 2.4) + jwt (2.3.0) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -234,6 +235,8 @@ GEM racc (~> 1.4) nokogiri (1.13.1-x86_64-linux) racc (~> 1.4) + notifications-ruby-client (5.3.0) + jwt (>= 1.5, < 3) orm_adapter (0.5.0) overcommit (0.58.0) childprocess (>= 0.6.3, < 5) @@ -435,6 +438,7 @@ DEPENDENCIES hotwire-rails json-schema listen (~> 3.3) + notifications-ruby-client overcommit (>= 0.37.0) pg (~> 1.1) postcodes_io diff --git a/app/mailers/notify_devise_mailer.rb b/app/mailers/notify_devise_mailer.rb new file mode 100644 index 000000000..d38bb9e0b --- /dev/null +++ b/app/mailers/notify_devise_mailer.rb @@ -0,0 +1,15 @@ +class NotifyDeviseMailer < Devise::Mailer + require 'notifications/client' + + def reset_password_instructions(record, token, opts = {}) + client = ::Notifications::Client.new(ENV["GOVUK_NOTIFY_API_KEY"]) + client.send_email( + email_address: record.email, + template_id: "8f1dea41-60e8-4aa2-a23b-f3a751a7438f", + personalisation: { + email: record.email, + link: "#{ENV['host']}/users/password/edit?reset_password_token=#{token}" + } + ) + end +end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 49866c93b..4cd8d8e0b 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -24,10 +24,11 @@ Devise.setup do |config| # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = ENV["CORE_EMAIL_USERNAME"] + # config.mailer_sender = ENV["CORE_EMAIL_USERNAME"] # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' + config.mailer = "NotifyDeviseMailer" # Configure the parent class responsible to send e-mails. # config.parent_mailer = 'ActionMailer::Base'