<commit_before>var User = require("../models/userModel");

module.exports = (app, passport) => {

	app.get('/', (req, res) => {
		res.sendFile('index.html', {root: './public/views'});
	});


	app.get('/api/me', ensureAuthenticatedAjax,  (req,res) => {
			User.findById(req.user._id, (err, user) => {
				if(err) { res.send("err");}
				user.gitToken = null;
				res.send(user);
			});
	});

	app.put('/api/me', ensureAuthenticatedAjax,  (req,res) => {
		User.findById(req.user._id, (err, user) => {
			if(err) { res.send("err");}
			user.displayName = req.body.displayName;
			user.bio = req.body.bio;
			user.hireable = req.body.hireable;
			user.location = req.body.location;
			user.blog = req.body.blog;
			user.company = req.body.company;
			user.email = req.body.email;
			user.name = req.body.name;
			user.save(function (err) {
				if(err) { res.send("err");}
				user.gitToken = null;
				res.send(user);
			});
		});
	});

	// app.get('/api/users/:userParams', ensureAuthenticatedAjax , (req,res) => {
	// 	// find latest 10 public profiles
	// });

	// app.get('/card/:githubId', ensureAuthenticatedAjax, (req,res) => {
	// 	User.findOne(req.params, (err,user) => {
	// 		// need better error handling for if user not found
	// 		if (err) { res.send(null);}
	// 		else{
	// 			if(user &&  user.gitToken) { user.gitToken = null;} 
	// 			res.send(user);
	// 		}
	// 	});
	// });

	app.get('/auth/github', passport.authenticate('github', {scope: ['user']}), (req, res) => {

	});

	app.get('/auth/github/callback', passport.authenticate('github', {failureRedirect: '/'}), (req, res) => {
		req.logIn(req.user, err => {
			if (err) {return next(err); }
			// ENABLE CORS LATER
			return res.redirect('/');
		});
	});

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

	function ensureAuthenticated (req, res, next) {
		if (req.isAuthenticated()) {return next(); }
		res.redirect('/');
	}
	
	function ensureAuthenticatedAjax (req, res, next) {
	    if (req.isAuthenticated()) { return next(); }
	    res.send({ error: 'not logged in' });
	}

};<commit_msg>sending better Error messages. Changed from PUT to POST.<commit_after>var User = require("../models/userModel");

module.exports = (app, passport) => {

	app.get('/', (req, res) => {
		res.sendFile('index.html', {root: './public/views'});
	});


	app.get('/api/me', ensureAuthenticatedAjax,  (req,res) => {
		User.findById(req.user._id, (err, user) => {
			if(err) { res.send({ error: 'Sorry something went wrong' });}
			user.gitToken = null;
			res.send(user);
		});
	});

	app.post('/api/me', ensureAuthenticatedAjax,  (req,res) => {
		User.findById(req.user._id, (err, user) => {
			if(err) { res.send({ error: 'Sorry something went wrong' });}
			user.displayName = req.body.displayName;
			user.bio = req.body.bio;
			user.hireable = req.body.hireable;
			user.location = req.body.location;
			user.blog = req.body.blog;
			user.company = req.body.company;
			user.email = req.body.email;
			user.name = req.body.name;
			user.repos = req.body.repos;
			user.followers = req.body.followers;
			user.save(function (err) {
				if(err) { res.send({ error: 'Sorry something went wrong' });}
				else{
					user.gitToken = null;
					res.send(user);
				}
			});
		});
	});
	

	app.get('/auth/github', passport.authenticate('github', {scope: ['user']}), (req, res) => {});
	
	app.get('/auth/github/callback', passport.authenticate('github', {failureRedirect: '/'}), (req, res) => {
		req.logIn(req.user, err => {
			if (err) {return next(err); }
			// ENABLE CORS LATER
			return res.redirect('/');
		});
	});

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

	function ensureAuthenticated (req, res, next) {
		if (req.isAuthenticated()) {return next(); }
		res.redirect('/');
	}
	
	function ensureAuthenticatedAjax (req, res, next) {
	    if (req.isAuthenticated()) { return next(); }
	    res.send({ error: 'not logged in' });
	}

};
{'fraction_non_alphanumeric': 0.21803941384537645, 'fraction_numerical': 0.0005053057099545225, 'mean_word_length': 3.20276008492569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '3273396', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1460, 'n_words': 269}