簡體   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