From cb1f1f31340642d28b18a19b7a48ed913ab50a5b Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Fri, 24 May 2013 13:00:19 +0200 Subject: fixed issue #21 --- models/Access.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'models/Access.js') diff --git a/models/Access.js b/models/Access.js index ba8097d..69b556a 100644 --- a/models/Access.js +++ b/models/Access.js @@ -31,6 +31,30 @@ var AccessSchema = new Schema({ // the four validations below only apply if you are signing up traditionally +AccessSchema.methods = { + + /** + * Generate random access token for Remember Me function + * + * @param {Number} length + * @return {String} + * @api public + */ + + generateRandomToken: function(length) { + if (typeof(length) === undefined) length = 16; // default length of token + var chars = '_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' + , token = ''; + for (var i = 0; i < length; i++) { + var x = Math.floor(Math.random() * chars.length); + token += chars.charAt(x); + } + console.log('token ' + token); + return token; + } + +} + AccessSchema.statics = { /** -- cgit v1.2.3