1 var express = require('express');
  2 var router = express.Router();
  3 
  4 /* GET user information. */
  5 
  6 /**
  7 	* Function to handle GET requests for user information.
  8 	* Render the edit page corresponding to the user, or a 404 if the userID does not exist.
  9 	* @deprecated
 10 	* @param {Object} req The express routing HTTP client request object,
 11 	* whose parameters contain the userID.
 12 	* @param {Object} res The express routing HTTP client response object.
 13 	* @param {callback} next The express routing callback function to invoke next middleware in the stack.
 14 	* @return {Object} A JSON object that holds req, res, and next.
 15 */
 16 var editGetUserID = function(req, res, next) {
 17 	var db = req.app.locals.db;
 18 	var userId = parseInt(req.params.userid);
 19 
 20 	db.collection('Users')
 21 			.find({'userId': userId})
 22 			.toArray(function(err, results) {
 23 				if (results.length == 0) {
 24 					res.status(404).send("404: userId not found");
 25 				} else {
 26 					user = results[0]; // should only be one match
 27 
 28 					res.render('edit', {
 29 						userId: userId,
 30 						email: user.email,
 31 						activities: user.activities,
 32 						availability: user.availability
 33 					});
 34 				}
 35 			});
 36 }
 37 
 38 router.get('/:userid', editGetUserID);
 39 
 40 /**
 41 	* Function to handle POST requests for user information.
 42 	* Updates the user's information in the database.
 43 	* @deprecated
 44 	* @param {Object} req The express routing HTTP client request object,
 45 	* whose parameters contain the userID, email, password, and confirmation.
 46 	* @param {Object} res The express routing HTTP client response object.
 47 	* @param {callback} next The express routing callback function to invoke next middleware in the stack.
 48 	* @return {Object} A JSON object that holds req, res, and next.
 49 */
 50 var editPostUserID = function(req, res, next) {
 51 	var db = req.app.locals.db;
 52 	var userId = parseInt(req.params.userid);
 53 	var email = req.params.email;
 54 	var password = req.params.password;
 55 	var passwordconfirm = req.params.passwordconfirm;
 56 
 57 	var updateObj = {$set: {'email': email}};
 58 
 59 	// if password or email are reset, must make a new cookie!
 60 
 61 	// TODO put this in the database.js file
 62 	// db.collection('Users').updateOne({'userId': userId}, updateObj, {});
 63 	res.redirect('/profile/' + userId);
 64 }
 65 
 66 router.post('/:userid', editPostUserID);
 67 
 68 module.exports = router;
 69