From 82399393b82300d1ea1099546950c81acec26b8f Mon Sep 17 00:00:00 2001 From: Rish Date: Thu, 24 Sep 2020 23:01:28 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20email=20verification=20m?= =?UTF-8?q?ails=20not=20sent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - Email ownership verification emails for support/from address was not using the updated magic link service syntax --- core/server/api/canary/settings.js | 2 +- core/server/services/members/settings.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/server/api/canary/settings.js b/core/server/api/canary/settings.js index 67473208f3..77eb21a7ac 100644 --- a/core/server/api/canary/settings.js +++ b/core/server/api/canary/settings.js @@ -97,7 +97,7 @@ module.exports = { frame.response = async function (req, res) { try { const {token, action} = frame.options; - const updatedEmailAddress = membersService.settings.getEmailFromToken({token}); + const updatedEmailAddress = await membersService.settings.getEmailFromToken({token}); const actionToKeyMapping = { fromAddressUpdate: 'members_from_address', supportAddressUpdate: 'members_support_address' diff --git a/core/server/services/members/settings.js b/core/server/services/members/settings.js index e2b3d9c7dc..21f0c7fda9 100644 --- a/core/server/services/members/settings.js +++ b/core/server/services/members/settings.js @@ -6,6 +6,9 @@ const settingsCache = require('../settings/cache'); const logging = require('../../../shared/logging'); const mail = require('../mail'); const updateEmailTemplate = require('./emails/updateEmail'); +const SingleUseTokenProvider = require('./SingleUseTokenProvider'); +const models = require('../../models'); +const MAGIC_LINK_TOKEN_VALIDITY = 4 * 60 * 60 * 1000; const ghostMailer = new mail.GhostMailer(); @@ -63,14 +66,14 @@ function createSettingsInstance(config) { const magicLinkService = new MagicLink({ transporter, - secret: config.getAuthSecret(), + tokenProvider: new SingleUseTokenProvider(models.SingleUseToken, MAGIC_LINK_TOKEN_VALIDITY), getSigninURL, getText, getHTML, getSubject }); - const sendEmailAddressUpdateMagicLink = ({email, payload = {}, type = 'fromAddressUpdate'}) => { + const sendEmailAddressUpdateMagicLink = ({email, type = 'fromAddressUpdate'}) => { const [,toDomain] = email.split('@'); let fromEmail = `noreply@${toDomain}`; if (fromEmail === email) { @@ -90,11 +93,12 @@ function createSettingsInstance(config) { return ghostMailer.send(msg); } }; - return magicLinkService.sendMagicLink({email, payload, subject: email, type}); + return magicLinkService.sendMagicLink({email, tokenData: {email}, subject: email, type}); }; - const getEmailFromToken = ({token}) => { - return magicLinkService.getUserFromToken(token); + const getEmailFromToken = async ({token}) => { + const data = await magicLinkService.getDataFromToken(token); + return data.email; }; const getAdminRedirectLink = ({type}) => {