serializing json for email confirmation
This commit is contained in:
parent
cd7c344125
commit
1a692690dc
|
@ -149,6 +149,7 @@
|
||||||
*/
|
*/
|
||||||
emailPlugin.sendVerificationEmail = function(email, secret) {
|
emailPlugin.sendVerificationEmail = function(email, secret) {
|
||||||
var confirmUrl = emailPlugin.makeConfirmUrl(email, secret);
|
var confirmUrl = emailPlugin.makeConfirmUrl(email, secret);
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
|
|
||||||
function(callback) {
|
function(callback) {
|
||||||
|
@ -381,9 +382,9 @@
|
||||||
secret: secret,
|
secret: secret,
|
||||||
expires: moment().add(DAYS_TO_EXPIRATION, 'days').unix(),
|
expires: moment().add(DAYS_TO_EXPIRATION, 'days').unix(),
|
||||||
};
|
};
|
||||||
emailPlugin.db.put(pendingKey(email), value, function(err) {
|
emailPlugin.db.put(pendingKey(email), JSON.stringify(value), function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error('error saving pending data:', email, secret);
|
logger.error('error saving pending data:', email, value);
|
||||||
return callback(emailPlugin.errors.INTERNAL_ERROR);
|
return callback(emailPlugin.errors.INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
return callback(null, secret);
|
return callback(null, secret);
|
||||||
|
@ -761,11 +762,16 @@
|
||||||
}, response);
|
}, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.isObject(value)) {
|
var parsed = null;
|
||||||
if (moment().unix() > value.expires) {
|
try {
|
||||||
|
parsed = JSON.parse(value);
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
if (parsed && _.isObject(parsed)) {
|
||||||
|
if (moment().unix() > parsed.expires) {
|
||||||
return emailPlugin.returnError(emailPlugin.errors.REGISTRATION_EXPIRED, response);
|
return emailPlugin.returnError(emailPlugin.errors.REGISTRATION_EXPIRED, response);
|
||||||
} else {
|
} else {
|
||||||
value = value.secret;
|
value = parsed.secret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -228,7 +228,7 @@ describe('emailstore test', function() {
|
||||||
setupLevelDb();
|
setupLevelDb();
|
||||||
var clock = sinon.useFakeTimers();
|
var clock = sinon.useFakeTimers();
|
||||||
plugin.createVerificationSecretAndSendEmail(fakeEmail, function(err) {
|
plugin.createVerificationSecretAndSendEmail(fakeEmail, function(err) {
|
||||||
var arg = leveldb_stub.put.firstCall.args[1];
|
var arg = JSON.parse(leveldb_stub.put.firstCall.args[1]);
|
||||||
arg.secret.should.equal(fakeRandom);
|
arg.secret.should.equal(fakeRandom);
|
||||||
arg.expires.should.equal(moment().add(7, 'days').unix());
|
arg.expires.should.equal(moment().add(7, 'days').unix());
|
||||||
clock.restore();
|
clock.restore();
|
||||||
|
@ -378,10 +378,10 @@ describe('emailstore test', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should validate correctly an email if the secret matches (using expiration date)', function() {
|
it('should validate correctly an email if the secret matches (using expiration date)', function() {
|
||||||
leveldb_stub.get.onFirstCall().callsArgWith(1, null, {
|
leveldb_stub.get.onFirstCall().callsArgWith(1, null, JSON.stringify({
|
||||||
secret: secret,
|
secret: secret,
|
||||||
expires: moment().add(7, 'days').unix(),
|
expires: moment().add(7, 'days').unix(),
|
||||||
});
|
}));
|
||||||
leveldb_stub.del = sinon.stub().yields(null);
|
leveldb_stub.del = sinon.stub().yields(null);
|
||||||
response.redirect = sinon.stub();
|
response.redirect = sinon.stub();
|
||||||
|
|
||||||
|
@ -406,10 +406,10 @@ describe('emailstore test', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to validate an email if the secret has expired', function() {
|
it('should fail to validate an email if the secret has expired', function() {
|
||||||
leveldb_stub.get.onFirstCall().callsArgWith(1, null, {
|
leveldb_stub.get.onFirstCall().callsArgWith(1, null, JSON.stringify({
|
||||||
secret: secret,
|
secret: secret,
|
||||||
expires: moment().subtract(2, 'days').unix(),
|
expires: moment().subtract(2, 'days').unix(),
|
||||||
});
|
}));
|
||||||
response.status.returnsThis();
|
response.status.returnsThis();
|
||||||
response.json.returnsThis();
|
response.json.returnsThis();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue