diff options
author | Dennis Eriksen <dennis.se@gmail.com> | 2013-05-14 09:47:53 +0200 |
---|---|---|
committer | Dennis Eriksen <dennis.se@gmail.com> | 2013-05-14 09:47:53 +0200 |
commit | 45b6f32943a816a687f3493fe2a246830d1e08d0 (patch) | |
tree | 1ab3462306efd99981881bf367904c1284dab2c3 /models/User.js | |
parent | experimenting with emailjs (diff) | |
download | Divid-45b6f32943a816a687f3493fe2a246830d1e08d0.tar.gz |
added length parameter to random token generator
Diffstat (limited to 'models/User.js')
-rw-r--r-- | models/User.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/models/User.js b/models/User.js index 9e6e52f..a40ba34 100644 --- a/models/User.js +++ b/models/User.js @@ -29,7 +29,8 @@ var UserSchema = new Schema({ accessToken: String, facebook: {}, twitter: {}, - status: { type: Number, default: 2 } + status: { type: Number, default: 2 }, + randomToken: String }); @@ -140,14 +141,16 @@ UserSchema.methods = { /** * Generate random access token for Remember Me function * + * @param {Number} length * @return {String} * @api public */ - generateRandomToken: function() { + generateRandomToken: function(length) { + if (typeof(length) === 'undefined') length = 16; // default length of token var chars = "_!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" , token = new Date().getTime() + '_'; - for (var i = 0; i < 16; i++) { + for (var i = 0; i < length; i++) { var x = Math.floor(Math.random() * 62); token += chars.charAt(x); } |