mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Stored geolocation for member on creation (#15320)
refs https://github.com/TryGhost/Team/issues/1826 Geolocation was prev. loaded after member was created and updated on existing member. this was mostly due to historical context where we couldn't store data on magic link token. Since email alerts go out at the time of member creation, this flow missed out on attaching member's location to email. This change - - stores request ip when a member asks for magic link in the token - loads request ip from token when member uses magic link, and for new members loads their geolocation and stores it with member creation
This commit is contained in:
parent
b16ad52401
commit
1bf70bf3c6
2 changed files with 19 additions and 3 deletions
|
@ -2,6 +2,7 @@ const {Router} = require('express');
|
|||
const body = require('body-parser');
|
||||
const MagicLink = require('@tryghost/magic-link');
|
||||
const errors = require('@tryghost/errors');
|
||||
const logging = require('@tryghost/logging');
|
||||
|
||||
const MemberAnalyticsService = require('@tryghost/member-analytics-service');
|
||||
const MembersAnalyticsIngress = require('@tryghost/members-analytics-ingress');
|
||||
|
@ -204,7 +205,7 @@ module.exports = function MembersAPI({
|
|||
}
|
||||
|
||||
async function getMemberDataFromMagicLinkToken(token) {
|
||||
const {email, labels = [], name = '', oldEmail, newsletters, attribution} = await getTokenDataFromMagicLinkToken(token);
|
||||
const {email, labels = [], name = '', oldEmail, newsletters, attribution, reqIp} = await getTokenDataFromMagicLinkToken(token);
|
||||
if (!email) {
|
||||
return null;
|
||||
}
|
||||
|
@ -220,7 +221,19 @@ module.exports = function MembersAPI({
|
|||
}
|
||||
return member;
|
||||
}
|
||||
const newMember = await users.create({name, email, labels, newsletters, attribution});
|
||||
|
||||
let geolocation;
|
||||
if (reqIp) {
|
||||
try {
|
||||
geolocation = JSON.stringify(await geolocationService.getGeolocationFromIP(reqIp));
|
||||
} catch (err) {
|
||||
logging.warn(err);
|
||||
// no-op, we don't want to stop anything working due to
|
||||
// geolocation lookup failing
|
||||
}
|
||||
}
|
||||
|
||||
const newMember = await users.create({name, email, labels, newsletters, attribution, geolocation});
|
||||
|
||||
// Notify staff users of new free member signup
|
||||
if (labsService.isSet('emailAlerts')) {
|
||||
|
|
|
@ -27,6 +27,7 @@ module.exports = class RouterController {
|
|||
* @param {import('@tryghost/members-stripe-service')} deps.stripeAPIService
|
||||
* @param {import('@tryghost/member-attribution')} deps.memberAttributionService
|
||||
* @param {any} deps.tokenService
|
||||
* @param {any} deps.sendEmailWithMagicLink
|
||||
* @param {{isSet(name: string): boolean}} deps.labsService
|
||||
*/
|
||||
constructor({
|
||||
|
@ -401,7 +402,9 @@ module.exports = class RouterController {
|
|||
}
|
||||
} else {
|
||||
const tokenData = _.pick(req.body, ['labels', 'name', 'newsletters']);
|
||||
|
||||
if (req.ip) {
|
||||
tokenData.reqIp = req.ip;
|
||||
}
|
||||
// Save attribution data in the tokenData
|
||||
tokenData.attribution = this._memberAttributionService.getAttribution(req.body.urlHistory);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue