diff options
author | Dennis Eriksen <dennis.se@gmail.com> | 2013-05-24 11:21:12 +0200 |
---|---|---|
committer | Dennis Eriksen <dennis.se@gmail.com> | 2013-05-24 11:21:12 +0200 |
commit | d135ce7ed7768928b82fd1530b3cc13090397dfb (patch) | |
tree | 7c06d3e7177d72f65edd6358f221b8de18b99e66 /config | |
parent | fixed some nicklists and other stuffs (diff) | |
download | Divid-d135ce7ed7768928b82fd1530b3cc13090397dfb.tar.gz |
added random access link for invited users. now they don't have to
register to post.
Diffstat (limited to 'config')
-rw-r--r-- | config/passport.js | 20 |
1 files changed, 18 insertions, 2 deletions
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 |