redirects to correct challenge upon authentication

This commit is contained in:
Michael Q Larson
2014-11-06 23:01:01 -08:00
parent e36a98cf2a
commit ca0c71b77f
3 changed files with 13 additions and 8 deletions

12
app.js
View File

@ -175,27 +175,27 @@ app.post('/completed_challenge', function(req, res){
*/ */
app.get('/auth/instagram', passport.authenticate('instagram')); app.get('/auth/instagram', passport.authenticate('instagram'));
app.get('/auth/instagram/callback', passport.authenticate('instagram', { successRedirect: '/challenges/a-one-minute-introduction-to-free-code-camp',failureRedirect: '/login' }), function(req, res) { app.get('/auth/instagram/callback', passport.authenticate('instagram', { successRedirect: '/',failureRedirect: '/login' }), function(req, res) {
res.redirect(req.session.returnTo || '/'); res.redirect(req.session.returnTo || '/');
}); });
app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email', 'user_location'] })); app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email', 'user_location'] }));
app.get('/auth/facebook/callback', passport.authenticate('facebook', { successRedirect: '/challenges/a-one-minute-introduction-to-free-code-camp',failureRedirect: '/login' }), function(req, res) { app.get('/auth/facebook/callback', passport.authenticate('facebook', { successRedirect: '/',failureRedirect: '/login' }), function(req, res) {
res.redirect(req.session.returnTo || '/'); res.redirect(req.session.returnTo || '/');
}); });
app.get('/auth/github', passport.authenticate('github')); app.get('/auth/github', passport.authenticate('github'));
app.get('/auth/github/callback', passport.authenticate('github', { successRedirect: '/challenges/a-one-minute-introduction-to-free-code-camp',failureRedirect: '/login' }), function(req, res) { app.get('/auth/github/callback', passport.authenticate('github', { successRedirect: '/',failureRedirect: '/login' }), function(req, res) {
res.redirect(req.session.returnTo || '/'); res.redirect(req.session.returnTo || '/');
}); });
app.get('/auth/google', passport.authenticate('google', { scope: 'profile email' })); app.get('/auth/google', passport.authenticate('google', { scope: 'profile email' }));
app.get('/auth/google/callback', passport.authenticate('google', { successRedirect: '/challenges/a-one-minute-introduction-to-free-code-camp',failureRedirect: '/login' }), function(req, res) { app.get('/auth/google/callback', passport.authenticate('google', { successRedirect: '/',failureRedirect: '/login' }), function(req, res) {
res.redirect(req.session.returnTo || '/'); res.redirect(req.session.returnTo || '/');
}); });
app.get('/auth/twitter', passport.authenticate('twitter')); app.get('/auth/twitter', passport.authenticate('twitter'));
app.get('/auth/twitter/callback', passport.authenticate('twitter', { successRedirect: '/challenges/a-one-minute-introduction-to-free-code-camp',failureRedirect: '/login' }), function(req, res) { app.get('/auth/twitter/callback', passport.authenticate('twitter', { successRedirect: '/',failureRedirect: '/login' }), function(req, res) {
res.redirect(req.session.returnTo || '/'); res.redirect(req.session.returnTo || '/');
}); });
app.get('/auth/linkedin', passport.authenticate('linkedin', { state: 'SOME STATE' })); app.get('/auth/linkedin', passport.authenticate('linkedin', { state: 'SOME STATE' }));
app.get('/auth/linkedin/callback', passport.authenticate('linkedin', { successRedirect: '/challenges/a-one-minute-introduction-to-free-code-camp',failureRedirect: '/login' }), function(req, res) { app.get('/auth/linkedin/callback', passport.authenticate('linkedin', { successRedirect: '/',failureRedirect: '/login' }), function(req, res) {
res.redirect(req.session.returnTo || '/'); res.redirect(req.session.returnTo || '/');
}); });

View File

@ -5,7 +5,12 @@
exports.index = function(req, res) { exports.index = function(req, res) {
if (req.user) { if (req.user) {
res.redirect('challenges/a-one-minute-introduction-to-free-code-camp'); if (req.user.challengesCompleted.length > 0) {
nextChallenge = Math.max.apply(Math, req.user.challengesCompleted) + 1;
res.redirect("challenges/" + nextChallenge);
} else {
res.redirect("challenges/0");
}
} else { } else {
res.render('home', { res.render('home', {
title: 'Home' title: 'Home'

View File

@ -13,7 +13,7 @@ var userSchema = new mongoose.Schema({
google: String, google: String,
instagram: String, instagram: String,
tokens: Array, tokens: Array,
challengesCompleted: Array, challengesCompleted: { type: Array, default: [] },
profile: { profile: {
name: { type: String, default: '' }, name: { type: String, default: '' },