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 --- controllers/users.js | 10 ++++++++-- models/Access.js | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index b6a9bcf..6d5ecaa 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -188,7 +188,7 @@ exports.postProjectParticipants = function(req, res) { access.user = newUser._id; access.creator = req.user._id; access.project = project._id; - access.randomToken = newUser.generateRandomToken(15, true); + access.randomToken = access.generateRandomToken(15); access.save(function(err) { if (err) { console.log(err.errors); @@ -212,6 +212,13 @@ exports.postProjectParticipants = function(req, res) { access.user = user._id; access.creator = req.user._id; access.project = project._id; + message.text = 'Du ble lagt til projektet "' + project.name + '"'; + console.log('user.status = '+ user.status); + if (Number(user.status) < 3) { + console.log('DAFUQ MANN! ER JO INNI IFFEN FFS!'); + access.randomToken = access.generateRandomToken(15); + message.text += '.\nDu kan få direkte tilgang til dette prosjektet her: https://divid.no/login/' + access.randomToken + ' \nDu kan bruke denne linken for å registrere deg, for å få tilgang til flere funksjoner: https://divid.no/invite/' + user.randomToken; + } access.save(function(err) { if (err) { console.log(err.errors); @@ -219,7 +226,6 @@ exports.postProjectParticipants = function(req, res) { } console.log('made new access for user ' + user.username); message.to = user.email; - message.text = 'Du ble lagt til projektet "' + project.name + '"'; server.send(message, function(err, message) { console.log(err || message);}); }); } 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