From d135ce7ed7768928b82fd1530b3cc13090397dfb Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Fri, 24 May 2013 11:21:12 +0200 Subject: added random access link for invited users. now they don't have to register to post. --- config/passport.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'config') diff --git a/config/passport.js b/config/passport.js index 68d5204..75f42e8 100644 --- a/config/passport.js +++ b/config/passport.js @@ -3,7 +3,9 @@ var mongoose = require('mongoose') , LocalStrategy = require('passport-local').Strategy , FacebookStrategy = require('passport-facebook').Strategy , TwitterStrategy = require('passport-twitter').Strategy - , User = mongoose.model('User'); + , HashStrategy = require('passport-hash').Strategy + , User = mongoose.model('User') + , Access = mongoose.model('Access'); /** * This is where the magic happends @@ -25,7 +27,7 @@ module.exports = function (passport, config) { /** * Local strategy */ - passport.use(new LocalStrategy({ + passport.use('local', new LocalStrategy({ usernameField: 'email', passwordField: 'password' }, function(email, password, done) { @@ -39,6 +41,20 @@ module.exports = function (passport, config) { }); })); + passport.use(new HashStrategy({ passReqToCallback: true }, function(req, hash, done) { + console.log('TRYNG ' + hash); + Access.findOne({ randomToken: hash }, function(err, access) { + if (err) return done(err); + console.log(access); + if (!access) return done(null, false, { message: 'Unknown link' }); + User.findOne({ _id: access.user }, function(err, user) { + if (err) return done(err); + if (!user) return done(null, false, { message: 'Unknown user' }); + return done(null, user); + }); + }); + })); + /** * Facebook strategy -- cgit v1.2.3