storing unix timestamps
This commit is contained in:
parent
83e6d9bad0
commit
ff0a8612fa
@ -371,7 +371,7 @@
|
|||||||
var available = false;
|
var available = false;
|
||||||
|
|
||||||
var notFound = err && err.notFound;
|
var notFound = err && err.notFound;
|
||||||
var expired = !err && _.isObject(value) && moment().isAfter(value.expires);
|
var expired = !err && _.isObject(value) && moment().unix() > value.expires;
|
||||||
|
|
||||||
var available = notFound || expired;
|
var available = notFound || expired;
|
||||||
|
|
||||||
@ -379,7 +379,7 @@
|
|||||||
var secret = emailPlugin.crypto.randomBytes(16).toString('hex');
|
var secret = emailPlugin.crypto.randomBytes(16).toString('hex');
|
||||||
var value = {
|
var value = {
|
||||||
secret: secret,
|
secret: secret,
|
||||||
expires: moment().add(DAYS_TO_EXPIRATION, 'days'),
|
expires: moment().add(DAYS_TO_EXPIRATION, 'days').unix(),
|
||||||
};
|
};
|
||||||
emailPlugin.db.put(pendingKey(email), value, function(err) {
|
emailPlugin.db.put(pendingKey(email), value, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -762,7 +762,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_.isObject(value)) {
|
if (_.isObject(value)) {
|
||||||
if (moment().isAfter(value.expires)) {
|
if (moment().unix() > value.expires) {
|
||||||
return emailPlugin.returnError(emailPlugin.errors.REGISTRATION_EXPIRED, response);
|
return emailPlugin.returnError(emailPlugin.errors.REGISTRATION_EXPIRED, response);
|
||||||
} else {
|
} else {
|
||||||
value = value.secret;
|
value = value.secret;
|
||||||
|
|||||||
@ -230,7 +230,7 @@ describe('emailstore test', function() {
|
|||||||
plugin.createVerificationSecretAndSendEmail(fakeEmail, function(err) {
|
plugin.createVerificationSecretAndSendEmail(fakeEmail, function(err) {
|
||||||
var arg = leveldb_stub.put.firstCall.args[1];
|
var arg = leveldb_stub.put.firstCall.args[1];
|
||||||
arg.secret.should.equal(fakeRandom);
|
arg.secret.should.equal(fakeRandom);
|
||||||
arg.expires.isSame(moment().add(7, 'days')).should.be.true;
|
arg.expires.should.equal(moment().add(7, 'days').unix());
|
||||||
clock.restore();
|
clock.restore();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -380,7 +380,7 @@ 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, {
|
||||||
secret: secret,
|
secret: secret,
|
||||||
expires: moment().add(7, 'days')
|
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();
|
||||||
@ -408,7 +408,7 @@ 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, {
|
||||||
secret: secret,
|
secret: secret,
|
||||||
expires: moment().subtract(2, 'days')
|
expires: moment().subtract(2, 'days').unix(),
|
||||||
});
|
});
|
||||||
response.status.returnsThis();
|
response.status.returnsThis();
|
||||||
response.json.returnsThis();
|
response.json.returnsThis();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user