1 var jwt = require('jsonwebtoken');
  2 
  3 /**
  4 	* Checks a login, using the provided cookie and email.
  5 	* @param {Object} cookie The cookie provided by the client's browser.
  6 	* @param {String} email The user's email.
  7 	* @return {boolean} Whether the given cookie and email verify.
  8 */
  9 var checkLogin = function (cookie, email) {
 10 	var cert = "C-UFRaksvPKhx1txJYFcut3QGxsafPmwCY6SCly3G6c";
 11 	if(cookie == null) {
 12 		return false; // return 401
 13 	}
 14 
 15 	try {
 16 		var decoded = jwt.verify(cookie, cert, {algorithms: ["HS256"]});
 17 
 18 		if(!('usr' in decoded) || decoded.usr != email) {
 19 			return false; // return 401
 20 		}
 21 	} catch (error) {
 22 		return false;
 23 	}
 24 
 25 	return true;
 26 }
 27 
 28 module.exports = {
 29 	checkLogin: checkLogin
 30 };
 31