fix: update to use shortid for sub resub
This commit is contained in:
committed by
Stuart Taylor
parent
99b9e9e3ba
commit
4511e33716
@ -14,8 +14,8 @@ import { isEmail } from 'validator';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import loopback from 'loopback';
|
import loopback from 'loopback';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { ObjectId } from 'mongodb';
|
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
|
import generate from 'nanoid/generate';
|
||||||
|
|
||||||
import { fixCompletedChallengeItem } from '../utils';
|
import { fixCompletedChallengeItem } from '../utils';
|
||||||
import { themes } from '../utils/themes';
|
import { themes } from '../utils/themes';
|
||||||
@ -34,6 +34,8 @@ import {
|
|||||||
|
|
||||||
const log = debugFactory('fcc:models:user');
|
const log = debugFactory('fcc:models:user');
|
||||||
const BROWNIEPOINTS_TIMEOUT = [1, 'hour'];
|
const BROWNIEPOINTS_TIMEOUT = [1, 'hour'];
|
||||||
|
const nanoidCharSet =
|
||||||
|
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
|
|
||||||
const createEmailError = redirectTo => wrapHandledError(
|
const createEmailError = redirectTo => wrapHandledError(
|
||||||
new Error('email format is invalid'),
|
new Error('email format is invalid'),
|
||||||
@ -237,7 +239,7 @@ module.exports = function(User) {
|
|||||||
user.externalId = uuid();
|
user.externalId = uuid();
|
||||||
}
|
}
|
||||||
if (!user.unsubscribeId) {
|
if (!user.unsubscribeId) {
|
||||||
user.unsubscribeId = new ObjectId();
|
user.unsubscribeId = generate(nanoidCharSet, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.progressTimestamps) {
|
if (!user.progressTimestamps) {
|
||||||
@ -296,7 +298,7 @@ module.exports = function(User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!user.unsubscribeId) {
|
if (!user.unsubscribeId) {
|
||||||
user.unsubscribeId = new ObjectId();
|
user.unsubscribeId = generate(nanoidCharSet, 20);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ignoreElements();
|
.ignoreElements();
|
||||||
|
9
package-lock.json
generated
9
package-lock.json
generated
@ -5901,7 +5901,7 @@
|
|||||||
},
|
},
|
||||||
"event-stream": {
|
"event-stream": {
|
||||||
"version": "3.3.4",
|
"version": "3.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz",
|
"resolved": "http://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz",
|
||||||
"integrity": "sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE=",
|
"integrity": "sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
@ -12719,6 +12719,11 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
|
"nanoid": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-iOCqgXieGrk8/wDt1n9rZS2KB1dYVssemY0NTWjfzVr+1t1gAmdTp1u2+YHppKro3Bk5S+Gs+xmYCfpuXauYXQ=="
|
||||||
|
},
|
||||||
"nanomatch": {
|
"nanomatch": {
|
||||||
"version": "1.2.6",
|
"version": "1.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.6.tgz",
|
||||||
@ -16834,7 +16839,7 @@
|
|||||||
},
|
},
|
||||||
"should-equal": {
|
"should-equal": {
|
||||||
"version": "0.3.1",
|
"version": "0.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/should-equal/-/should-equal-0.3.1.tgz",
|
"resolved": "http://registry.npmjs.org/should-equal/-/should-equal-0.3.1.tgz",
|
||||||
"integrity": "sha1-vY6pemdI45+tR2o75v1y68LnK/A=",
|
"integrity": "sha1-vY6pemdI45+tR2o75v1y68LnK/A=",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
@ -102,6 +102,7 @@
|
|||||||
"mongodb": "^3.0.4",
|
"mongodb": "^3.0.4",
|
||||||
"morgan": "^1.6.1",
|
"morgan": "^1.6.1",
|
||||||
"mousetrap": "~1.6.0",
|
"mousetrap": "~1.6.0",
|
||||||
|
"nanoid": "^1.1.0",
|
||||||
"node-emoji": "^1.4.1",
|
"node-emoji": "^1.4.1",
|
||||||
"nodemailer": "^2.1.0",
|
"nodemailer": "^2.1.0",
|
||||||
"nodemailer-ses-transport": "^1.5.1",
|
"nodemailer-ses-transport": "^1.5.1",
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import request from 'request';
|
import request from 'request';
|
||||||
import { ObjectId } from 'mongodb';
|
|
||||||
|
|
||||||
import constantStrings from '../utils/constantStrings.json';
|
import constantStrings from '../utils/constantStrings.json';
|
||||||
import testimonials from '../resources/testimonials.json';
|
import testimonials from '../resources/testimonials.json';
|
||||||
@ -162,7 +161,7 @@ module.exports = function(app) {
|
|||||||
req.flash('info', {
|
req.flash('info', {
|
||||||
msg: 'We\'ve successfully updated your Email preferences.'
|
msg: 'We\'ve successfully updated your Email preferences.'
|
||||||
});
|
});
|
||||||
return res.redirect('/unsubscribed/');
|
return res.redirect('/unsubscribed');
|
||||||
})
|
})
|
||||||
.catch(next);
|
.catch(next);
|
||||||
});
|
});
|
||||||
@ -176,13 +175,11 @@ module.exports = function(app) {
|
|||||||
msg: 'We could not find an account to unsubscribe'
|
msg: 'We could not find an account to unsubscribe'
|
||||||
});
|
});
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
|
|
||||||
}
|
}
|
||||||
const [ user ] = users;
|
const [ user ] = users;
|
||||||
return new Promise((resolve, reject) =>
|
return new Promise((resolve, reject) =>
|
||||||
user.updateAttributes({
|
user.updateAttributes({
|
||||||
sendQuincyEmail: false,
|
sendQuincyEmail: false
|
||||||
unsubscribeId: unsubscribeId
|
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
@ -194,7 +191,7 @@ module.exports = function(app) {
|
|||||||
req.flash('success', {
|
req.flash('success', {
|
||||||
msg: 'We\'ve successfully updated your email preferences.'
|
msg: 'We\'ve successfully updated your email preferences.'
|
||||||
});
|
});
|
||||||
return res.redirect(`/unsubscribed/${queryId}`);
|
return res.redirect(`/unsubscribed/${unsubscribeId}`);
|
||||||
})
|
})
|
||||||
.catch(next);
|
.catch(next);
|
||||||
});
|
});
|
||||||
@ -215,16 +212,8 @@ module.exports = function(app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resubscribe(req, res, next) {
|
function resubscribe(req, res, next) {
|
||||||
const { unsubscribeId: queryId } = req.params;
|
const { unsubscribeId } = req.params;
|
||||||
return User.find({
|
return User.find({ where: { unsubscribeId } },
|
||||||
where: {
|
|
||||||
or: [
|
|
||||||
{ unsubscribeId: queryId },
|
|
||||||
{ unsubscribeId: ObjectId(queryId).toString() },
|
|
||||||
{ unsubscribeId: ObjectId(queryId) }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(err, users) => {
|
(err, users) => {
|
||||||
if (err || !users.length) {
|
if (err || !users.length) {
|
||||||
req.flash('info', {
|
req.flash('info', {
|
||||||
|
Reference in New Issue
Block a user