aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/models/User.js
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-05-14 09:47:53 +0200
committerDennis Eriksen <dennis.se@gmail.com>2013-05-14 09:47:53 +0200
commit45b6f32943a816a687f3493fe2a246830d1e08d0 (patch)
tree1ab3462306efd99981881bf367904c1284dab2c3 /models/User.js
parentexperimenting with emailjs (diff)
downloadDivid-45b6f32943a816a687f3493fe2a246830d1e08d0.tar.gz
added length parameter to random token generator
Diffstat (limited to 'models/User.js')
-rw-r--r--models/User.js9
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);
}