<commit_before>module.exports = function (app, io, passport) {

// ================== Home Page ================== 
	app.get ('/', function (req, res) {
		res.render('index');
	});
// ================== Chat Page ================== 
	app.get ('/chat', function (req, res) {
		
		// render the page and pass in any flash data if it exists
		// loginMessage will be created inside of passport
		res.render ('chat', {
			message: req.flash('loginMessage')
		});
	});


// ================== Login ================== 
	app.get ('/login', function (req, res) {
		
		// render the page and pass in any flash data if it exists
		// loginMessage will be created inside of passport
		// console.log(req.flash());
		res.render ('login', {
			message: req.flash('loginMessage')
		});
	});

	app.post ('/login', function (req, res) {
		console.log(req.body);
		req.checkBody('email', 'Email is empty!' ).notEmpty();
		req.checkBody('email', 'Email is not valid!').isEmail();
		req.checkBody('password', '<PASSWORD>!').notEmpty();
	
		var err = req.validationErrors();

		if (err) {
			console.log (err);
			req.flash('loginMessage', 'Incorrect username or password.')
			req.session.save(function () {
				res.redirect('/login');
			});
		} else {
			passport.authenticate('local-login', {
				successRedirect: '/chat',
				failureRedirect: '/login',
				failureFlash: true
			})(req,res);
		}

	});

// ================== Sign up ================== 
	app.get ('/signup', function (req, res) {
		res.render ('signup', {
			message: req.flash('signupMessage')
		});
	});
   // app.post('/signup', passport.authenticate('local-signup', {
   //      successRedirect : '/chat', // redirect to the secure profile section
   //      failureRedirect : '/signup', // redirect back to the signup page if there is an error
   //      failureFlash : true // allow flash messages
   //  }));

   	app.post ('/signup', function (req, res) {
		console.log(req.body);
		req.checkBody('email', 'Email is empty!' ).notEmpty();
		req.checkBody('email', 'Email is not valid!').isEmail();
		req.checkBody('password', '<PASSWORD>!').notEmpty();
		var err = req.validationErrors();

		if (err) {
			console.log (err);
			req.flash('signupMessage', 'Incorrect signup information.')
			req.session.save(function () {
				res.redirect('/signup');
			});
		} else {
			passport.authenticate('local-signup', {
				successRedirect: '/chat',
				failureRedirect: '/signup',
				failureFlash: true
			})(req,res);
		}

	});

// ================== Logout  ================== 
// TODO: Implement a "You"

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

// ================== Chat Connectoin ================== 

	io.on ('connection', function (socket) {
		socket.on('chat message', function(msg) {
			io.emit('chat message', msg);
		})
	})
};

// route middleware to make sure a user is logged in

function isLoggedIn (req, res, next) {
	
	// if user is autheticated in the session, carry on 
	if (req.isAuthenticated()) 
		return next();

	// if they arent, redirect them to the home page
	res.redirect('/');
};<commit_msg>Fixed the problem where you can access the chat page when not logged in<commit_after>module.exports = function (app, io, passport) {

// ================== Home Page ================== 
	app.get ('/', function (req, res) {
		res.render('index');
	});
// ================== Chat Page ================== 
	app.get ('/chat', isLoggedIn, function (req, res) {
		
		// render the page and pass in any flash data if it exists
		// loginMessage will be created inside of passport
		res.render ('chat', {
			message: req.flash('loginMessage')
		});
	});


// ================== Login ================== 
	app.get ('/login', function (req, res) {
		
		// render the page and pass in any flash data if it exists
		// loginMessage will be created inside of passport
		// console.log(req.flash());
		res.render ('login', {
			message: req.flash('loginMessage')
		});
	});

	app.post ('/login', function (req, res) {
		console.log(req.body);
		req.checkBody('email', 'Email is empty!' ).notEmpty();
		req.checkBody('email', 'Email is not valid!').isEmail();
		req.checkBody('password', '<PASSWORD>!').notEmpty();
	
		var err = req.validationErrors();

		if (err) {
			console.log (err);
			req.flash('loginMessage', 'Incorrect username or password.')
			req.session.save(function () {
				res.redirect('/login');
			});
		} else {
			passport.authenticate('local-login', {
				successRedirect: '/chat',
				failureRedirect: '/login',
				failureFlash: true
			})(req,res);
		}

	});

// ================== Sign up ================== 
	app.get ('/signup', function (req, res) {
		res.render ('signup', {
			message: req.flash('signupMessage')
		});
	});
   // app.post('/signup', passport.authenticate('local-signup', {
   //      successRedirect : '/chat', // redirect to the secure profile section
   //      failureRedirect : '/signup', // redirect back to the signup page if there is an error
   //      failureFlash : true // allow flash messages
   //  }));

   	app.post ('/signup', function (req, res) {
		console.log(req.body);
		req.checkBody('email', 'Email is empty!' ).notEmpty();
		req.checkBody('email', 'Email is not valid!').isEmail();
		req.checkBody('password', '<PASSWORD>!').notEmpty();
		var err = req.validationErrors();

		if (err) {
			console.log (err);
			req.flash('signupMessage', 'Incorrect signup information.')
			req.session.save(function () {
				res.redirect('/signup');
			});
		} else {
			passport.authenticate('local-signup', {
				successRedirect: '/chat',
				failureRedirect: '/signup',
				failureFlash: true
			})(req,res);
		}

	});

// ================== Logout  ================== 
// TODO: Implement a "You"

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

// ================== Chat Connectoin ================== 

	io.on ('connection', function (socket) {
		socket.on('chat message', function(msg) {
			io.emit('chat message', msg);
		})
	})
};

// route middleware to make sure a user is logged in

function isLoggedIn (req, res, next) {
	
	// if user is autheticated in the session, carry on 
	if (req.isAuthenticated()) 
		return next();

	// if they arent, redirect them to the home page
	res.redirect('/');
};
{'fraction_non_alphanumeric': 0.23334390862944163, 'fraction_numerical': 0.0, 'mean_word_length': 3.4432699083861875, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7499874', 'n_tokens_mistral': 2193, 'n_tokens_neox': 1916, 'n_words': 522}