mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Removed separate reset/forced-reset emails and updated email copy
refs https://github.com/TryGhost/Ghost/pull/11790 - reduced complexity by sticking to one email for both normal reset and forced reset (locked staff accounts) - exposed `siteTitle` for use in any email templates - updated email copy to be suitable for both types of password reset
This commit is contained in:
parent
7b0efa34a4
commit
0eec876cb1
8 changed files with 17 additions and 104 deletions
|
@ -108,11 +108,7 @@ module.exports = {
|
|||
return auth.passwordreset.generateToken(frame.data.passwordreset[0].email, api.settings);
|
||||
})
|
||||
.then((token) => {
|
||||
if (frame.data.required) {
|
||||
return auth.passwordreset.sendRequiredResetNotification(token, api.mail);
|
||||
} else {
|
||||
return auth.passwordreset.sendResetNotification(token, api.mail);
|
||||
}
|
||||
return auth.passwordreset.sendResetNotification(token, api.mail);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -48,8 +48,7 @@ const session = {
|
|||
await api.authentication.generateResetToken({
|
||||
passwordreset: [{
|
||||
email: object.username
|
||||
}],
|
||||
required: true
|
||||
}]
|
||||
}, frame.options.context);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,11 +108,7 @@ module.exports = {
|
|||
return auth.passwordreset.generateToken(frame.data.passwordreset[0].email, api.settings);
|
||||
})
|
||||
.then((token) => {
|
||||
if (frame.data.required) {
|
||||
return auth.passwordreset.sendRequiredResetNotification(token, api.mail);
|
||||
} else {
|
||||
return auth.passwordreset.sendResetNotification(token, api.mail);
|
||||
}
|
||||
return auth.passwordreset.sendResetNotification(token, api.mail);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -48,8 +48,7 @@ const session = {
|
|||
await api.authentication.generateResetToken({
|
||||
passwordreset: [{
|
||||
email: object.username
|
||||
}],
|
||||
required: true
|
||||
}]
|
||||
}, frame.options.context);
|
||||
}
|
||||
|
||||
|
|
|
@ -121,11 +121,14 @@ function doReset(options, tokenParts, settingsAPI) {
|
|||
|
||||
async function sendResetNotification(data, mailAPI) {
|
||||
const adminUrl = urlUtils.urlFor('admin', true);
|
||||
const resetUrl = urlUtils.urlJoin(adminUrl, 'reset', security.url.encodeBase64(data.resetToken), '/');
|
||||
const resetToken = security.url.encodeBase64(data.resetToken);
|
||||
const resetUrl = urlUtils.urlJoin(adminUrl, 'reset', resetToken, '/');
|
||||
const resetLink = urlUtils.urlJoin(adminUrl, 'reset', `${resetToken.slice(0, 5)}...`);
|
||||
|
||||
const content = await mail.utils.generateContent({
|
||||
data: {
|
||||
resetUrl: resetUrl
|
||||
resetUrl,
|
||||
resetLink
|
||||
},
|
||||
template: 'reset-password'
|
||||
});
|
||||
|
@ -145,37 +148,10 @@ async function sendResetNotification(data, mailAPI) {
|
|||
return mailAPI.send(payload, {context: {internal: true}});
|
||||
}
|
||||
|
||||
async function sendRequiredResetNotification(data, mailAPI) {
|
||||
const adminUrl = urlUtils.urlFor('admin', true);
|
||||
const resetUrl = urlUtils.urlJoin(adminUrl, 'reset', security.url.encodeBase64(data.resetToken), '/');
|
||||
|
||||
const content = await mail.utils.generateContent({
|
||||
data: {
|
||||
resetUrl: resetUrl
|
||||
},
|
||||
template: 'reset-password-required'
|
||||
});
|
||||
|
||||
const payload = {
|
||||
mail: [{
|
||||
message: {
|
||||
to: data.email,
|
||||
subject: i18n.t('common.api.authentication.mail.resetPasswordRequired'),
|
||||
html: content.html,
|
||||
text: content.text
|
||||
},
|
||||
options: {}
|
||||
}]
|
||||
};
|
||||
|
||||
return mailAPI.send(payload, {context: {internal: true}});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateToken,
|
||||
extractTokenParts,
|
||||
protectBruteForce,
|
||||
doReset,
|
||||
sendResetNotification,
|
||||
sendRequiredResetNotification
|
||||
sendResetNotification
|
||||
};
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd">
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
|
||||
</head>
|
||||
<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" style="-webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; background: #ffffff; color: #808284; font-family: sans-serif; font-size: 15px; line-height: 1.5; margin: 0; width: 100%;">
|
||||
|
||||
<table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#ffffff">
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" width="100%">
|
||||
|
||||
<table class="main-wrapper" width="600" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#ffffff">
|
||||
<tr>
|
||||
<td class="cell" width="100%">
|
||||
|
||||
<div class="wrapper" style="-moz-border-radius: 3px; -webkit-border-radius: 3px; border: #e5e3d8 1px solid; border-radius: 3px; margin: 2%; padding: 5% 8%;">
|
||||
<table class="content" width="100%" cellpadding="0" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td class="content-cell" width="100%">
|
||||
|
||||
<!-- START OF EMAIL CONTENT -->
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;"><strong>Hello!</strong></p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;">For security, it's necessary to reset your password on <a href="{{ siteUrl }}" style="color: #5ba4e5;">{{ siteUrl }}</a>.</p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;">Please follow the link below to complete the process:<br><br> <a href="{{ resetUrl }}" style="color: #5ba4e5;">Click here to reset your password</a></p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;"><i>Alternatively please visit your site's admin area and follow the forgot password process.</i></p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;">Ghost</p>
|
||||
<!-- END OF EMAIL CONTENT -->
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="container" style="padding: 0 4%;">
|
||||
<table class="footer" width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td class="footer-cell" align="right" style="color: #888888; font-family: sans-serif; font-size: 11px; line-height: 1.3; padding: 0 0 20px 0;">
|
||||
Sent by <a href="{{siteUrl}}" style="color: #5ba4e5;">{{siteUrl}}</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -21,11 +21,10 @@
|
|||
<td class="content-cell" width="100%">
|
||||
|
||||
<!-- START OF EMAIL CONTENT -->
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;"><strong>Hello!</strong></p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;">A request has been made to reset your password on <a href="{{ siteUrl }}" style="color: #5ba4e5;">{{ siteUrl }}</a>.</p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;">Please follow the link below to reset your password:<br><br> <a href="{{ resetUrl }}" style="color: #5ba4e5;">Click here to reset your password</a></p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;"><i>If you did not request a password reset, it's safe to ignore this email.</i></p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;">Ghost</p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;"><strong>Hey there!</strong></p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;">You can use this link to create a new password for your account on <strong>{{siteTitle}}</strong>:</p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;"><a href="{{resetUrl}}" style="color: #5ba4e5;">{{resetLink}}</a></p>
|
||||
<p style="color: #808284; font-family: sans-serif; font-size: 15px; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0 0 1.5em 0;">If you have any trouble, you should contact your site administrator for help.</p>
|
||||
<!-- END OF EMAIL CONTENT -->
|
||||
|
||||
</td>
|
||||
|
|
|
@ -3,13 +3,15 @@ const fs = require('fs-extra');
|
|||
const path = require('path');
|
||||
const htmlToText = require('html-to-text');
|
||||
const urlUtils = require('../../lib/url-utils');
|
||||
const settingsCache = require('../settings/cache');
|
||||
const templatesDir = path.resolve(__dirname, '..', 'mail', 'templates');
|
||||
|
||||
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
||||
|
||||
exports.generateContent = function generateContent(options) {
|
||||
const defaults = {
|
||||
siteUrl: urlUtils.urlFor('home', true)
|
||||
siteUrl: urlUtils.urlFor('home', true),
|
||||
siteTitle: settingsCache.get('title')
|
||||
};
|
||||
|
||||
const data = _.defaults(defaults, options.data);
|
||||
|
|
Loading…
Reference in a new issue