转发PassportJS到表单身份validation添加电子邮件,密码等

所以我按照这个教程 。 我完成了整个系列,应用程序工作正常。 不过,我想为使用社交networking注册的用户例如。 Facebook等被redirect到一个单独的表格,他们可以填写他们的名字(S)电子邮件等问题的夫妇。

  1. 我将不得不改变数据库模式,以允许“全球”(这是正确的术语来使用?)值的电子邮件和名称等从facebook / twitter特定的东西。 像这样:

    var userSchema = mongoose.Schema({ email : String, name : String password : String, facebook : { id : String, token : String, }, twitter : { id : String, token : String, displayName : String, username : String, }, google : { id : String, token : String, } }); 

那么正确的路线是什么? 我目前有:

  // TWITTER ROUTES // route for facebook authentication and login app.get('/auth/twitter', passport.authenticate('twitter')); // handle the callback after twitter has authenticated the user app.get('/auth/twitter/callback', passport.authenticate('twitter', { failureRedirect: '/signup' }), function(req, res) { // The user has authenticated with Twitter. Now check to see if the profile // is "complete". If not, send them down a flow to fill out more details. if (req.user.isCompleteProfile()) { res.redirect('/profile'); } else { res.redirect('/complete-profile'); }}); app.get('/complete-profile', function(req, res) { res.render('profile-form', { user: req.user }); }); app.post('/update-profile', function(req, res) { // Grab the missing info from the form and update the profile. res.redirect('/home'); }); // route middleware to make sure a user is logged in function isLoggedIn(req, res, next) { // if user is authenticated in the session, carry on if (req.isAuthenticated ()) return next(); // if they arent redirect them to the home page res.redirect('/'); } 

我把它从这个StackOverflow 。

我将如何定义函数isCompleteProfile ? 目前我有这样的事情:

 function isCompleteProfile(req, res, next) { // if user has completed profile, carry on if (req.isComplete ()) return next(); // if they arent redirect to complete-profile res.redirect('/complete-profile'); } 

第一个链接(到教程)作者提供了一些关于如何实现这一点的build议,在文章下面的评论部分,如果有人需要它。 不过,我主要是在看SO链接。

显然这是行不通的(我只是复制了早期函数isLoggedIn创build视图应该(希望)不是太难,所以如果任何人都可以阐明我应该如何解决这个问题,将不胜感激。

谢谢Uknj

PostScript:也有潜在的替代方法吗? 我不在路线中使用单独的function,只是将它们直接redirect到另一个页面? 不知道我怎么会这样做,所以帮助将不胜感激。

请参阅我的说明使用Everyauth / Passport.js使用Twitter进行身份validation,同时询问用户名/电子邮件/密码 ,以了解如何设置isCompleteProfiletesting。