<commit_before>var express = require('express');
var router = express.Router();

// configure db 
var mongoose = require('mongoose');
var ListRatr = require('../schemas/listratr');
var List = require('../schemas/list');
var ObjectId = mongoose.Schema.ObjectId;

/* GET home page. */
router.get('/', homeGET);

/* GET signup page. */
router.get('/signup', signupGET);

/* POST signup form. */
router.post('/signup', signupPOST);

/* GET signin page. */
router.get('/signin', signinGET);

/* POST signup form. */
router.post('/signin', signinPOST);

/* GET ratrs's profile page. */
router.get('/profile', profileGET);

/* GET all lists. */
router.get('/lists', listsGET);

/* GET a list's individual page. */
router.get('/lists/:listName', getOneListByName);

/* GET ratrs's create list page. */
router.get('/createList', CreateListGET);

/* POST ratrs creates a new list. */
router.post('/createList', createListPOST);

/* GET ratrs's list page. */
router.get('/mylists/:ratrId', ratrIdGET);

/* POST ratr likes a list */
router.post('/like', likePOST);

//////////////////////////////////////////////////
// 				ROUTE MIDDLEWARES 				//
//////////////////////////////////////////////////

function homeGET (req, res, next) {
	// get first list from db
	List.find({}, function (err, lists) {
		if (err) 
			res.send(err);
		else {
			// pseudo: in future top list should be list with highest rank/score
			// for now assume first list to be top list
			// topList = lists[0];
			// res.send(lists);

			console.log('\n\nlists before sort:\n');
			console.log(lists);
			console.log('\n\n');

			// rank now! (based on likes for now)
			lists = sortByLikes(lists);
			console.log('\n\nlists after sort:\n');
			console.log(lists);
			console.log('\n\n');

			// rendaaah!
			res.render('index', {
				title : 'ListRatr',
				lists : lists,
				isAdmin : false,
				partials : {
					listsContainer : 'lists-container',
					header : 'header',
					footer : 'footer'
				}
			});
		}
	});	
}

function signupGET (req, res, next) {
	res.render('signup', { 
		title: 'ListRatr - Signup',
		partials : {
			header : 'header',
			footer : 'footer'
		}
	});
}

function signupPOST (req, res, next) {
	// get form data
	var email = req.body.email;
	var password = <PASSWORD>;
	var confirmPassword = <PASSWORD>;

	ListRatr.findOne({email : email}, function (err, ratr) {
		if (err) {
			res.send(err);
		} else {
			if (ratr) {
				res.send('bad: email not available');
			} else {
				console.log('good: email available');

				// create new listratr
				var listratr = new ListRatr ({
					email : email,
					password : password,
				});
				listratr.save();

				res.send(listratr);
			}
		}
	});
}

function signinGET (req, res, next) {
	res.render('signin', { 
		title: 'ListRatr - Signin',
		partials : {
			header : 'header',
			footer : 'footer'
		}
	});
}

function signinPOST (req, res, next) {
	// get form data
	var email = req.body.email;
	var password = <PASSWORD>;

	ListRatr.findOne({email : email}, function (err, ratr) {
		if (err) {
			res.send(err);
		} else {
			if (ratr) {
				// save session
				req.session.ratr = ratr;	

				console.log('good: ratr found');
				res.send(ratr);
			} else {
				console.log('bad: ratr does not exist');
				res.send('bad: ratr does not exist');
			}
		}
	});
}

function profileGET (req, res, next) {
	var ratr = req.session.ratr;

	if (ratr) 
		res.send(ratr);
	else 
		res.send('bad: ratr undefined');
}

function listsGET (req, res, next) {
	// get ratrId
	var ratr = req.session.ratr;
	var ratrId;
	if (ratr)
		ratrId = ratr._id;
	else
		res.send('bad: no user logged in on this session');

	// get first list from db
	List.find({}, function (err, lists) {
		if (err) 
			res.send(err);
		else {
			// pseudo: in future top list should be list with highest rank/score
			// for now assume first list to be top list
			// topList = lists[0];
			// res.send(lists);

			console.log('\n\nlists before sort:\n');
			console.log(lists);
			console.log('\n\n');

			// rank now! (based on likes for now)
			lists = sortByLikes(lists);<commit_msg>no need user at /lists<commit_after>var express = require('express');
var router = express.Router();

// configure db 
var mongoose = require('mongoose');
var ListRatr = require('../schemas/listratr');
var List = require('../schemas/list');
var ObjectId = mongoose.Schema.ObjectId;

/* GET home page. */
router.get('/', homeGET);

/* GET signup page. */
router.get('/signup', signupGET);

/* POST signup form. */
router.post('/signup', signupPOST);

/* GET signin page. */
router.get('/signin', signinGET);

/* POST signup form. */
router.post('/signin', signinPOST);

/* GET ratrs's profile page. */
router.get('/profile', profileGET);

/* GET all lists. */
router.get('/lists', listsGET);

/* GET a list's individual page. */
router.get('/lists/:listName', getOneListByName);

/* GET ratrs's create list page. */
router.get('/createList', CreateListGET);

/* POST ratrs creates a new list. */
router.post('/createList', createListPOST);

/* GET ratrs's list page. */
router.get('/mylists/:ratrId', ratrIdGET);

/* POST ratr likes a list */
router.post('/like', likePOST);

//////////////////////////////////////////////////
// 				ROUTE MIDDLEWARES 				//
//////////////////////////////////////////////////

function homeGET (req, res, next) {
	// get first list from db
	List.find({}, function (err, lists) {
		if (err) 
			res.send(err);
		else {
			// pseudo: in future top list should be list with highest rank/score
			// for now assume first list to be top list
			// topList = lists[0];
			// res.send(lists);

			console.log('\n\nlists before sort:\n');
			console.log(lists);
			console.log('\n\n');

			// rank now! (based on likes for now)
			lists = sortByLikes(lists);
			console.log('\n\nlists after sort:\n');
			console.log(lists);
			console.log('\n\n');

			// rendaaah!
			res.render('index', {
				title : 'ListRatr',
				lists : lists,
				isAdmin : false,
				partials : {
					listsContainer : 'lists-container',
					header : 'header',
					footer : 'footer'
				}
			});
		}
	});	
}

function signupGET (req, res, next) {
	res.render('signup', { 
		title: 'ListRatr - Signup',
		partials : {
			header : 'header',
			footer : 'footer'
		}
	});
}

function signupPOST (req, res, next) {
	// get form data
	var email = req.body.email;
	var password = <PASSWORD>;
	var confirmPassword = req.body.confirmPassword;

	ListRatr.findOne({email : email}, function (err, ratr) {
		if (err) {
			res.send(err);
		} else {
			if (ratr) {
				res.send('bad: email not available');
			} else {
				console.log('good: email available');

				// create new listratr
				var listratr = new ListRatr ({
					email : email,
					password : password,
				});
				listratr.save();

				res.send(listratr);
			}
		}
	});
}

function signinGET (req, res, next) {
	res.render('signin', { 
		title: 'ListRatr - Signin',
		partials : {
			header : 'header',
			footer : 'footer'
		}
	});
}

function signinPOST (req, res, next) {
	// get form data
	var email = req.body.email;
	var password = <PASSWORD>;

	ListRatr.findOne({email : email}, function (err, ratr) {
		if (err) {
			res.send(err);
		} else {
			if (ratr) {
				// save session
				req.session.ratr = ratr;	

				console.log('good: ratr found');
				res.send(ratr);
			} else {
				console.log('bad: ratr does not exist');
				res.send('bad: ratr does not exist');
			}
		}
	});
}

function profileGET (req, res, next) {
	var ratr = req.session.ratr;

	if (ratr) 
		res.send(ratr);
	else 
		res.send('bad: ratr undefined');
}

function listsGET (req, res, next) {
	// get ratrId
	var ratr = req.session.ratr;
	// var ratrId;
	// if (ratr)
	// 	ratrId = ratr._id;
	// else
	// 	res.send('bad: no user logged in on this session');

	// get first list from db
	List.find({}, function (err, lists) {
		if (err) 
			res.send(err);
		else {
			// pseudo: in future top list should be list with highest rank/score
			// for now assume first list to be top list
			// topList = lists[0];
			// res.send(lists);

			console.log('\n\nlists before sort:\n');
			console.log(lists);
			console.log('\n\n');

			// rank now! (based on likes for now)
			lists = sortByLikes(lists);
{'fraction_non_alphanumeric': 0.19102626459143968, 'fraction_numerical': 0.00048638132295719845, 'mean_word_length': 2.6153846153846154, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '7271235', 'n_tokens_mistral': 3238, 'n_tokens_neox': 2867, 'n_words': 761}