diff options
author | Dennis Eriksen <dennis.se@gmail.com> | 2013-05-01 11:25:43 +0200 |
---|---|---|
committer | Dennis Eriksen <dennis.se@gmail.com> | 2013-05-01 11:25:43 +0200 |
commit | a935f29043c48063839c5f139dbbde6817b213f6 (patch) | |
tree | 0099e70913ac51d7139f10beb0193803d076f558 /models/User.js | |
parent | better logging (diff) | |
download | Divid-a935f29043c48063839c5f139dbbde6817b213f6.tar.gz |
added generateRandomAccessToken method
Diffstat (limited to 'models/User.js')
-rw-r--r-- | models/User.js | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/models/User.js b/models/User.js index b61f7c9..4d32941 100644 --- a/models/User.js +++ b/models/User.js @@ -5,7 +5,7 @@ var mongoose = require('mongoose') , Schema = mongoose.Schema - , crypto =require('crypto') + , crypto = require('crypto') , authTypes = ['facebook', 'twitter']; @@ -20,6 +20,7 @@ var UserSchema = new Schema({ provider: String, hashed_password: String, salt: String, + accessToken: String, facebook: {}, twitter: {} }); @@ -98,6 +99,7 @@ UserSchema.methods = { return this.encryptPassword(plainText) === this.hashed_password; }, + /** * Make salt * @@ -109,6 +111,7 @@ UserSchema.methods = { return Math.round((new Date().valueOf() * Math.random())) + ''; }, + /** * Encrypt password * @@ -120,6 +123,24 @@ UserSchema.methods = { encryptPassword: function(password) { if (!password) return ''; return crypto.createHmac('sha1', this.salt).update(password).digest('hex'); + }, + + + /** + * Generate random access token for Remember Me function + * + * @return {String} + * @api public + */ + + generateRandomToken: function() { + var chars = "_!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" + , token = new Date().getTime() + '_'; + for (var i = 0; i < 16; i++) { + var x = Math.floor(Math.random() * 62); + token += chars.charAt(x); + } + return token; } } |