0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Updated use of magic-link module to pass subject

no-issue

This takes advantage of magic-links smaller tokens
This commit is contained in:
Fabien O'Carroll 2019-10-11 11:29:11 +07:00
parent 4c4d5aab91
commit 47ed334597
2 changed files with 17 additions and 13 deletions

View file

@ -27,9 +27,7 @@ describe('MagicLink', function () {
const args = {
email: 'test@example.com',
user: {
id: 420
},
subject: '420',
type: 'blazeit'
};
const {token} = await service.sendMagicLink(args);
@ -37,6 +35,15 @@ describe('MagicLink', function () {
should.ok(options.getSigninURL.calledOnce);
should.ok(options.getSigninURL.firstCall.calledWithExactly(token, 'blazeit'));
should.ok(options.getText.calledOnce);
should.ok(options.getText.firstCall.calledWithExactly('FAKEURL', 'blazeit', 'test@example.com'));
should.ok(options.getHTML.calledOnce);
should.ok(options.getHTML.firstCall.calledWithExactly('FAKEURL', 'blazeit', 'test@example.com'));
should.ok(options.getSubject.calledOnce);
should.ok(options.getSubject.firstCall.calledWithExactly('blazeit'));
should.ok(options.transporter.sendMail.calledOnce);
should.equal(options.transporter.sendMail.firstCall.args[0].to, args.email);
should.equal(options.transporter.sendMail.firstCall.args[0].subject, options.getSubject.firstCall.returnValue);
@ -60,15 +67,13 @@ describe('MagicLink', function () {
const args = {
email: 'test@example.com',
user: {
id: 420
}
subject: '420'
};
const {token} = await service.sendMagicLink(args);
const user = service.getUserFromToken(token);
const subject = service.getUserFromToken(token);
should.deepEqual(user, args.user);
should.deepEqual(subject, args.subject);
});
});
});

View file

@ -75,14 +75,14 @@ module.exports = function MembersApi({
async function sendEmailWithMagicLink(email, requestedType, options = {forceEmailType: false}){
if (options.forceEmailType) {
return magicLinkService.sendMagicLink({email, user: {email}, type: requestedType});
return magicLinkService.sendMagicLink({email, subject: email, type: requestedType});
}
const member = await users.get({email});
if (member) {
return magicLinkService.sendMagicLink({email, user: {email}, type: 'signin'});
return magicLinkService.sendMagicLink({email, subject: email, type: 'signin'});
} else {
const type = requestedType === 'subscribe' ? 'subscribe' : 'signup';
return magicLinkService.sendMagicLink({email, user: {email}, type});
return magicLinkService.sendMagicLink({email, subject: email, type});
}
}
@ -97,8 +97,7 @@ module.exports = function MembersApi({
});
async function getMemberDataFromMagicLinkToken(token){
const user = await magicLinkService.getUserFromToken(token);
const email = user && user.email;
const email = await magicLinkService.getUserFromToken(token);
if (!email) {
return null;
}