//============= routes ===============
module.exports = function(app, passport) {

	// home page =====================
	app.get('/', function(req, res) {
		res.render('index.ejs'); // load index.ejs file
	});

	// login page ====================
	app.get('/login', function(req, res) {
		// show message if wrong login
		res.render('login.ejs', {message: req.flash('loginMessage') }); // pass to template
	});

	// handling 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 page ===================
	app.get('/signup', function(req, res){
		res.render('signup.ejs', {message: req.flash('signupMessage') });
	});

	// handling the signup form
	app.post('/signup', passport.authenticate('local-signup', {
		successRedirect: '/profile',
		failureRedirect: '/signup',
		failureFlash: true // allow flash messages
	}));

	// profile pade ==================
	// isLoggedIn - check if user loggedin
	app.get('/profile', isLoggedIn, function(req, res) {
        res.render('profile.ejs', {user : req.user}); // get the user and pass to template
    });

    /*/ logout ========================
    app.get('/logout', function(res, req) {
    	//req.logout();
    	res.redirect('/');
    });
*/
};

// 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 aren't redirect them to the home page
    res.redirect('/');
}

@@ -171,16 +171,34 @@
 dex.ejs'
+, %7Buser: req.user%7D
 ); // lo
@@ -214,16 +214,42 @@
 ejs file
+ and pass user to template
 %0A%09%7D);%0A%0A%09
@@ -323,16 +323,138 @@
  res) %7B%0A
+%09%09// check  if the user is already logged, if yes skip login%0A%09%09if(req.isAuthenticated())%0A%09%09%09res.redirect('/profile');%0A%09%09%09%0A
 %09%09// sho
@@ -1492,17 +1492,16 @@
 ;%0A%0A    /
-*
 / logout
@@ -1564,14 +1564,14 @@
 n(re
-s
+q
 , re
-q
+s
 ) %7B%0A
@@ -1575,18 +1575,16 @@
  %7B%0A    %09
-//
 req.logo
@@ -1625,10 +1625,8 @@
 %7D);%0A
-*/
 %0A%7D;%0A

update routes file