繁体   English   中英

将PassportJS转发到表单身份验证以添加电子邮件,密码等

[英]Forward a PassportJS to a form authentication to add email, password etc

所以我遵循了本教程 我完成了整个系列,应用程序运行正常。 但是我想为使用社交网络(例如)注册的用户提供帮助。 Facebook等将被重定向到一个单独的表单,他们可以在其中填写自己的姓名,电子邮件等。几个问题。

  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');
}

如果有人需要,在文章下方的评论部分,第一个链接(指向本教程的内容)由作者提供一些有关如何实现此操作的建议。 但是,我主要关注的是SO链接。

显然这是行不通的(我只是复制了isLoggedIn的早期功能。(希望)创建视图应该不太困难。因此,如果有人可以阐明我应如何解决此问题,将不胜感激。

谢谢Uknj

PostScript:是否还有潜在的替代方法? 我在路由中没有使用单独功能的地方,而只是直接将它们重定向到另一个页面? 不知道我该怎么做,所以将不胜感激。

请参阅我关于使用Everyauth / Passport.js通过Twitter进行身份验证的说明,同时询问用户名/电子邮件/密码 ,以获取有关如何设置isCompleteProfile测试的说明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM