aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/models
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-05-24 13:00:19 +0200
committerDennis Eriksen <dennis.se@gmail.com>2013-05-24 13:00:19 +0200
commitcb1f1f31340642d28b18a19b7a48ed913ab50a5b (patch)
tree364aeae8dfd5f270f49c6974e7db179bc9936fe3 /models
parentfixes bug introduced in 4b63a89 (diff)
downloadDivid-cb1f1f31340642d28b18a19b7a48ed913ab50a5b.tar.gz
fixed issue #21
Diffstat (limited to 'models')
-rw-r--r--models/Access.js24
1 files changed, 24 insertions, 0 deletions
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 = {
/**