diff --git a/ghost/magic-link/index.js b/ghost/magic-link/index.js
index 35ca9dd60e..1dd8cfc164 100644
--- a/ghost/magic-link/index.js
+++ b/ghost/magic-link/index.js
@@ -14,20 +14,30 @@ module.exports = MagicLink;
* defaultGetText
*
* @param {URL} url - The url which will trigger sign in flow
+ * @param {string} type - The type of email to send e.g. signin, signup
* @returns {string} text - The text content of an email to send
*/
-function defaultGetText(url) {
- return `Click here to sign in ${url}`;
+function defaultGetText(url, type) {
+ let msg = 'sign in';
+ if (type === 'signup') {
+ msg = 'confirm your email address';
+ }
+ return `Click here to ${msg} ${url}`;
}
/**
* defaultGetHTML
*
* @param {URL} url - The url which will trigger sign in flow
+ * @param {string} type - The type of email to send e.g. signin, signup
* @returns {string} HTML - The HTML content of an email to send
*/
-function defaultGetHTML(url) {
- return `Click here to sign in`;
+function defaultGetHTML(url, type) {
+ let msg = 'sign in';
+ if (type === 'signup') {
+ msg = 'confirm your email address';
+ }
+ return `Click here to ${msg}`;
}
/**
@@ -38,7 +48,7 @@ function defaultGetHTML(url) {
* @param {MailTransporter} options.transporter
* @param {RsaPublicKey} options.publicKey
* @param {RsaPrivateKey} options.privateKey
- * @param {(token: JSONWebToken) => URL} options.getSigninURL
+ * @param {(token: JSONWebToken, type: string) => URL} options.getSigninURL
* @param {typeof defaultGetText} [options.getText]
* @param {typeof defaultGetHTML} [options.getHTML]
*/
@@ -60,6 +70,7 @@ function MagicLink(options) {
* @param {object} options
* @param {string} options.email - The email to send magic link to
* @param {object} options.user - The user object to associate with the magic link
+ * @param {string=} [options.type='signin'] - The type to be passed to the url and content generator functions
* @returns {Promise<{token: JSONWebToken, info: SentMessageInfo}>}
*/
MagicLink.prototype.sendMagicLink = async function sendMagicLink(options) {
@@ -73,12 +84,14 @@ MagicLink.prototype.sendMagicLink = async function sendMagicLink(options) {
expiresIn: '10m'
});
- const url = this.getSigninURL(token);
+ const type = options.type || 'signin';
+
+ const url = this.getSigninURL(token, type);
const info = await this.transporter.sendMail({
to: options.email,
- text: this.getText(url),
- html: this.getHTML(url)
+ text: this.getText(url, type),
+ html: this.getHTML(url, type)
});
return {token, info};
diff --git a/ghost/magic-link/test/index.test.js b/ghost/magic-link/test/index.test.js
index e16b77ef74..6e2a183e83 100644
--- a/ghost/magic-link/test/index.test.js
+++ b/ghost/magic-link/test/index.test.js
@@ -22,7 +22,7 @@ describe('MagicLink', function () {
});
describe('#sendMagicLink', function () {
- it('Sends an email to the user with a link generated from getSigninURL(token)', async function () {
+ it('Sends an email to the user with a link generated from getSigninURL(token, type)', async function () {
const options = {
publicKey,
privateKey,
@@ -39,12 +39,13 @@ describe('MagicLink', function () {
email: 'test@example.com',
user: {
id: 420
- }
+ },
+ type: 'blazeit'
};
const {token} = await service.sendMagicLink(args);
should.ok(options.getSigninURL.calledOnce);
- should.ok(options.getSigninURL.firstCall.calledWithExactly(token));
+ should.ok(options.getSigninURL.firstCall.calledWithExactly(token, 'blazeit'));
should.ok(options.transporter.sendMail.calledOnce);
should.equal(options.transporter.sendMail.firstCall.args[0].to, args.email);