-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Up until now we were using the standard default devise emails which are very generic and very plain. Prettify and rework the emails sent by devise, including signup confirmation, password reset, and a few of others. Include some branding and improved wording. Uses the bootstrap-mailer gem to produce email compatible html because that is very hard apparently. Uses haml instead of erb since that's how we like to do it. (Actually I'm not 100% certain all these emails are used but I've updated them all anyhow. Should aim to review the devise config and maybe test the account locking, the change email address, and the change password mechanism soon to confirm it all works and to see how the emails look in the real world.) Closes #3 (...which is currently the oldest open issue, created in Jan 2021)
- Loading branch information
1 parent
6ea7d6e
commit a82093f
Showing
23 changed files
with
240 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# See also test/mailers/previews/devise_bootstrap_mailer_preview | ||
# Based on https://github.com/bootstrap-email/bootstrap-email/issues/41 | ||
# | ||
class DeviseBootstrapMailer < Devise::Mailer | ||
|
||
layout 'bootstrap-mailer' | ||
default template_path: 'devise/mailer' | ||
|
||
def devise_mail(record, action, opts = {}, &block) | ||
initialize_from_record(record) | ||
|
||
@email_title = email_title_for(action) | ||
|
||
# Use bootstrap mail | ||
make_bootstrap_mail(headers_for(action, opts.merge(to: record.pretty_email)), &block) | ||
end | ||
|
||
private | ||
|
||
# See docker/bundle/ruby/3.1.0/gems/devise-4.8.1/lib/devise/mailers/helpers.rb | ||
# (IIUC the more correct way to change the email subject wording would be to | ||
# create an I18n locale file but let's save that for another day.) | ||
|
||
# Save the method from the base class so we can use it below | ||
alias_method :orig_subject_for, :subject_for | ||
|
||
def email_title_for(action) | ||
orig_subject_for(action). | ||
sub(/Changed$/, "change notification"). | ||
sub(/^Confirmation/, "Signup confirmation") | ||
end | ||
|
||
def subject_for(action) | ||
"Tiddlyhost #{email_title_for(action).downcase}" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
%p.pt-2 | ||
=link_to link_text, link_url, class: "btn btn-success", style: "font-weight: bold;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
%p | ||
Hi #{@resource.short_name}, | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
%p.pt-4 | ||
%small | ||
Your Tiddlyhost account email address is <b>#{@resource.email}</b>. |
5 changes: 0 additions & 5 deletions
5
rails/app/views/devise/mailer/confirmation_instructions.html.erb
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
rails/app/views/devise/mailer/confirmation_instructions.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
=render 'salutation' | ||
|
||
%p | ||
Welcome to Tiddlyhost! | ||
|
||
%p | ||
To complete the signup process please confirm your account | ||
email address by clicking 'Confirm account' below. | ||
|
||
=render 'button_link', link_text: 'Confirm account', link_url: confirmation_url(@resource, confirmation_token: @token) | ||
|
||
=render 'show_email' | ||
|
||
%p.pt-5 | ||
%small.text-gray-600 | ||
You received this email because you or someone submitted the | ||
=link_to 'Tiddlyhost sign up', "#{Settings.main_site_url}/users/sign_up", target: "_blank" | ||
form using this email address. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-if @resource&.unconfirmed_email? | ||
%p | ||
This is a notification to inform you that your Tiddlyhost account email address | ||
is being changed from <b>#{@resource.email}</b> to <b>#{@resource.unconfirmed_email}</b>. | ||
|
||
%p | ||
A confirmation from the new email address is required to verify the change. | ||
|
||
-else | ||
%p | ||
This is a notification to inform you that that your Tiddlyhost account email address | ||
has been successfully changed to <b>#{@resource.email}</b>. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
%p | ||
This is a notification to inform you that that your Tiddlyhost account | ||
password has been successfully changed. |
8 changes: 0 additions & 8 deletions
8
rails/app/views/devise/mailer/reset_password_instructions.html.erb
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
rails/app/views/devise/mailer/reset_password_instructions.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
=render 'salutation' | ||
|
||
%p | ||
You can set a new Tiddlyhost account password by clicking 'Change password' below. | ||
|
||
=render 'button_link', link_text: 'Change password', link_url: edit_password_url(@resource, reset_password_token: @token) | ||
|
||
=render 'show_email' | ||
|
||
%p.pt-4 | ||
%small | ||
If you didn't request a password reset please ignore this email. | ||
|
||
%p.pt-5 | ||
%small.text-gray-600 | ||
You received this email because you or someone submitted the | ||
=link_to 'Forgot password?', "#{Settings.main_site_url}/users/password/new", target: "_blank" | ||
form using this email address. |
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
rails/app/views/devise/mailer/unlock_instructions.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
=render 'salutation' | ||
|
||
%p | ||
Your Tiddlyhost account has been locked due to an excessive number of unsuccessful login attempts. | ||
|
||
%p | ||
To unlock your account click the 'Unlock account' link below. | ||
|
||
=render 'button_link', link_text: 'Unlock account', link_url: unlock_url(@resource, unlock_token: @token) | ||
|
||
=render 'show_email' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<%# | ||
# | ||
# This will be converted into email friendly html with tables and inlined styles. | ||
# The email content is defined under app/views/devise/mailer. | ||
# | ||
# See also: | ||
# - https://bootstrapemail.com/ | ||
# - app/mailers/devise_bootstrap_mailer.rb | ||
# - test/mailers/previews/devise_bootstrap_mailer_preview.rb | ||
# - http://tiddlyhost.local:3333/rails/mailers/devise_bootstrap_mailer | ||
# - or https://tiddlyhost.local/rails/mailers/devise_bootstrap_mailer | ||
# | ||
-%> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html lang="en"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<meta name="x-apple-disable-message-reformatting"> | ||
<meta http-equiv="x-ua-compatible" content="ie=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="format-detection" content="telephone=no, date=no, address=no, email=no"> | ||
</head> | ||
<body class="bg-light"> | ||
<div class="container"> | ||
<div class="card my-10"> | ||
<div class="card-header" style="background-color: #3c60b9; color: white; height: 2.5em;" class="navbar nav bg-gradient"> | ||
<%= link_to Settings.main_site_url, target: '_blank' do %> | ||
<%= image_tag("email-banner", style: "display: inline; height: 100%;") %> | ||
<% end %> | ||
</div> | ||
<div class="card-body"> | ||
<% if @email_title.present? %><h1 class="h3 mb-2 mt-2"><%= @email_title %></h1><% end %> | ||
<div class="space-y-3 p-2 pt-5"> | ||
<%= yield %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require "test_helper" | ||
|
||
class DeviseBootstrapMailerTest < ActionMailer::TestCase | ||
|
||
def setup | ||
@user = users(:bobby) | ||
@token = 'abc123' | ||
end | ||
|
||
test 'smoke test' do | ||
{ | ||
confirmation_instructions: [@user, @token], | ||
reset_password_instructions: [@user, @token], | ||
unlock_instructions: [@user, @token], | ||
email_changed: [@user], | ||
password_change: [@user], | ||
|
||
}.each do |email_type, params| | ||
email = DeviseBootstrapMailer.send(email_type, *params) | ||
assert_emails 1 do | ||
email.deliver_later | ||
end | ||
|
||
assert_equal [@user.email], email.to | ||
assert_match /Tiddlyhost /, email.subject | ||
assert_match '<div class="card-header" style=', email.body.encoded | ||
end | ||
end | ||
|
||
end |
34 changes: 34 additions & 0 deletions
34
rails/test/mailers/previews/devise_bootstrap_mailer_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# To preview emails: | ||
# - http://tiddlyhost.local:3333/rails/mailers/devise_bootstrap_mailer | ||
# - or https://tiddlyhost.local/rails/mailers/devise_bootstrap_mailer | ||
# | ||
class DeviseBootstrapMailerPreview < ActionMailer::Preview | ||
|
||
def initialize(params = {}) | ||
@user = User.first | ||
@token = 'abc123' | ||
super | ||
end | ||
|
||
def confirmation_instructions | ||
DeviseBootstrapMailer.confirmation_instructions(@user, @token) | ||
end | ||
|
||
def reset_password_instructions | ||
DeviseBootstrapMailer.reset_password_instructions(@user, @token) | ||
end | ||
|
||
def unlock_instructions | ||
DeviseBootstrapMailer.unlock_instructions(@user, @token) | ||
end | ||
|
||
def email_changed | ||
DeviseBootstrapMailer.email_changed(@user) | ||
end | ||
|
||
def password_change | ||
DeviseBootstrapMailer.password_change(@user) | ||
end | ||
|
||
end |