storing unix timestamps

This commit is contained in:
Ivan Socolsky 2014-12-10 13:32:44 -03:00
parent 83e6d9bad0
commit ff0a8612fa
2 changed files with 6 additions and 6 deletions

View File

@ -371,7 +371,7 @@
var available = false;
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;
@ -379,7 +379,7 @@
var secret = emailPlugin.crypto.randomBytes(16).toString('hex');
var value = {
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) {
if (err) {
@ -762,7 +762,7 @@
}
if (_.isObject(value)) {
if (moment().isAfter(value.expires)) {
if (moment().unix() > value.expires) {
return emailPlugin.returnError(emailPlugin.errors.REGISTRATION_EXPIRED, response);
} else {
value = value.secret;

View File

@ -230,7 +230,7 @@ describe('emailstore test', function() {
plugin.createVerificationSecretAndSendEmail(fakeEmail, function(err) {
var arg = leveldb_stub.put.firstCall.args[1];
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();
done();
});
@ -380,7 +380,7 @@ describe('emailstore test', function() {
it('should validate correctly an email if the secret matches (using expiration date)', function() {
leveldb_stub.get.onFirstCall().callsArgWith(1, null, {
secret: secret,
expires: moment().add(7, 'days')
expires: moment().add(7, 'days').unix(),
});
leveldb_stub.del = sinon.stub().yields(null);
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() {
leveldb_stub.get.onFirstCall().callsArgWith(1, null, {
secret: secret,
expires: moment().subtract(2, 'days')
expires: moment().subtract(2, 'days').unix(),
});
response.status.returnsThis();
response.json.returnsThis();