From ec9a067313c3593834bc6b727429d028c43615eb Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Thu, 16 May 2013 00:12:14 +0200 Subject: just some small changes --- models/User.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'models/User.js') diff --git a/models/User.js b/models/User.js index 216b8b0..01a6694 100644 --- a/models/User.js +++ b/models/User.js @@ -30,7 +30,9 @@ var UserSchema = new Schema({ facebook: {}, twitter: {}, status: { type: Number, default: 2 }, - randomToken: String + randomToken: String, + created: { type: Date, default: Date.now }, + updated: { type: Date, default: Date.now } }); @@ -86,10 +88,9 @@ UserSchema.path('hashed_password').validate(function(hashed_password) { UserSchema.pre('save', function(next) { if (!this.isNew || this.status === 1) return next(); - if(!validatePrecenceOf(this.password) - && authTypes.indexOf(this.provider) === -1) - next(new Error('Invalid password')); - else next(); + this.updated = Date.now(); + next(); + }); @@ -142,14 +143,15 @@ UserSchema.methods = { * Generate random access token for Remember Me function * * @param {Number} length + * @param {Boolean} noDate * @return {String} * @api public */ - generateRandomToken: function(length) { - if (typeof(length) === 'undefined') length = 16; // default length of token + generateRandomToken: function(length, noDate) { + if (typeof(length) === undefined) length = 16; // default length of token var chars = '_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' - , token = new Date().getTime() + '_'; + , token = noDate ? '' : new Date().getTime() + '_'; for (var i = 0; i < length; i++) { var x = Math.floor(Math.random() * chars.length); token += chars.charAt(x); -- cgit v1.2.3