Created
February 9, 2017 05:32
-
-
Save prabod/0d20b644ad65fa92022b611b04dbaf2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/', function(req, res) { | |
res.render('index'); | |
}); | |
// PROFILE SECTION ========================= | |
app.get('/profile', isLoggedIn, function(req, res) { | |
res.render('profile', { | |
user: req.user | |
}); | |
}); | |
// LOGOUT ============================== | |
app.get('/logout', function(req, res) { | |
req.logout(); | |
res.redirect('/'); | |
}); | |
// LOGIN =============================== | |
// show the login form | |
app.get('/login', function(req, res) { | |
res.render('login', { | |
message: req.flash('loginMessage') | |
}); | |
}); | |
// process the login form | |
app.post('/login', passport.authenticate('local-login', { | |
successRedirect: '/profile', // redirect to the secure profile section | |
failureRedirect: '/login', // redirect back to the signup page if there is an error | |
failureFlash: true // allow flash messages | |
})); | |
// SIGNUP ================================= | |
// show the signup form | |
app.get('/signup', function(req, res) { | |
res.render('signup', { | |
message: req.flash('signupMessage') | |
}); | |
}); | |
// process the signup form | |
app.post('/signup', passport.authenticate('local-signup', { | |
successRedirect: '/profile', // redirect to the secure profile section | |
failureRedirect: '/signup', // redirect back to the signup page if there is an error | |
failureFlash: true // allow flash messages | |
})); | |
// route middleware to ensure user is logged in | |
function isLoggedIn(req, res, next) { | |
if (req.isAuthenticated()) | |
return next(); | |
res.redirect('/'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment