<commit_before>'use strict';

var request = require('request');

var path = process.cwd();
var User = require('../models/users.js');
var Movie = require('../models/movies.js');
var sess;

function MovieSwap () {

	var max_results = 4;

	function validateEmail(email) {
	    var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	    return re.test(email);
	}

	this.signUp = function(req, res) {
		sess = req.session;
		if (!req.body.name) {
			res.json({error: true, message: 'What is your name?'});
		} else if (!req.body.email) {
			res.json({error: true, message: 'Email is necessary'});
		} else if (!validateEmail(req.body.email)) {
			res.json({error: true, message: 'Email format is incorrect'});
		} else if (!req.body.password) {
			res.json({error: true, message: 'Password its empty, fill this'});
		} else {
			var user = { 'name': req.body.name, 'email': req.body.email, 'password': <PASSWORD>, 'date': new Date() };
			User.findOne({ 'email': req.body.email }, function(err, doc) {
				if (err) throw err;
      	if (doc) {
					// User is registered
					res.json({error: true, message: 'User registered with this email'});
				} else {
					// Save new user
					var user = new User({
						'name': req.body.name,
						'email': req.body.email,
					  'password': <PASSWORD>,
					  'date': new Date()
					});
					user.save(function(err, doc) {
        		if(err) throw err;
        		res.json(doc);
      		});
				};
			});
		};
  };

	this.logIn = function(req, res) {
		sess = req.session;
		console.log(sess);
		if (!req.body.email) {
			res.json({error: true, message: 'What is your email?'});
		} else if (!validateEmail(req.body.email)) {
			res.json({error: true, message: 'Email format is incorrect'});
		} else if (!req.body.password) {
			res.json({error: true, message: 'Password its empty, fill this'});
		} else {
			User.findOne({ 'email': req.body.email, 'password': <PASSWORD> }, function(err, doc) {
				if (err) throw err;
				if (doc) {
					sess.user = doc;
					res.json(doc);
				} else {
					res.json({error: true, message: 'Email/Password incorrect, try again!'});
				}
			});
		};
	};

	this.checkLogin = function(req, res) {
		sess = req.session;
		if (sess.user) {
			res.json(sess.user);
		} else {
			res.json({error: true, message: 'User not logged'});
		}
	}

	this.logOut = function(req, res) {
		sess = req.session;
		console.log(sess);
		delete sess.user;
		res.json({logout: true});
	}

	this.initApp = function(req, res) {
		sess = req.session;
		sess.count = (sess.count || 0) + 1;
		console.log(req.session);
		res.sendFile(path + '/public/index.html');
	}

	this.getSearch = function(req, res) {
		var movie = req.params.movie;
		var api_url = "http://www.omdbapi.com/?type=movie&s=" + movie;
		request(api_url, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        var data = JSON.parse(body).Search;
				// Filter without posters
				if (data.length) {
					data = data.filter(function(value, index) {
	          return (value.Poster !== 'N/A');
	        });
				}
				res.json(data.slice(0,max_results));<commit_msg>Use native function to delete session<commit_after>'use strict';

var request = require('request');

var path = process.cwd();
var User = require('../models/users.js');
var Movie = require('../models/movies.js');
var sess;

function MovieSwap () {

	var max_results = 4;

	function validateEmail(email) {
	    var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	    return re.test(email);
	}

	this.signUp = function(req, res) {
		sess = req.session;
		if (!req.body.name) {
			res.json({error: true, message: 'What is your name?'});
		} else if (!req.body.email) {
			res.json({error: true, message: 'Email is necessary'});
		} else if (!validateEmail(req.body.email)) {
			res.json({error: true, message: 'Email format is incorrect'});
		} else if (!req.body.password) {
			res.json({error: true, message: 'Password its empty, fill this'});
		} else {
			var user = { 'name': req.body.name, 'email': req.body.email, 'password': <PASSWORD>, 'date': new Date() };
			User.findOne({ 'email': req.body.email }, function(err, doc) {
				if (err) throw err;
      	if (doc) {
					// User is registered
					res.json({error: true, message: 'User registered with this email'});
				} else {
					// Save new user
					var user = new User({
						'name': req.body.name,
						'email': req.body.email,
					  'password': <PASSWORD>,
					  'date': new Date()
					});
					user.save(function(err, doc) {
        		if(err) throw err;
        		res.json(doc);
      		});
				};
			});
		};
  };

	this.logIn = function(req, res) {
		sess = req.session;
		console.log(sess);
		if (!req.body.email) {
			res.json({error: true, message: 'What is your email?'});
		} else if (!validateEmail(req.body.email)) {
			res.json({error: true, message: 'Email format is incorrect'});
		} else if (!req.body.password) {
			res.json({error: true, message: 'Password its empty, fill this'});
		} else {
			User.findOne({ 'email': req.body.email, 'password': <PASSWORD>.body.password }, function(err, doc) {
				if (err) throw err;
				if (doc) {
					sess.user = doc;
					res.json(doc);
				} else {
					res.json({error: true, message: 'Email/Password incorrect, try again!'});
				}
			});
		};
	};

	this.checkLogin = function(req, res) {
		sess = req.session;
		if (sess.user) {
			res.json(sess.user);
		} else {
			res.json({error: true, message: 'User not logged'});
		}
	}

	this.logOut = function(req, res) {
		sess = req.session;
		console.log(sess);
		req.session.destroy();
		res.json({logout: true});
	}

	this.initApp = function(req, res) {
		sess = req.session;
		sess.count = (sess.count || 0) + 1;
		console.log(req.session);
		res.sendFile(path + '/public/index.html');
	}

	this.getSearch = function(req, res) {
		var movie = req.params.movie;
		var api_url = "http://www.omdbapi.com/?type=movie&s=" + movie;
		request(api_url, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        var data = JSON.parse(body).Search;
				// Filter without posters
				if (data.length) {
					data = data.filter(function(value, index) {
	          return (value.Poster !== 'N/A');
	        });
				}
				res.json(data.slice(0,max_results));
{'fraction_non_alphanumeric': 0.21095553162024927, 'fraction_numerical': 0.008001230958609017, 'mean_word_length': 2.9346246973365617, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6419964', 'n_tokens_mistral': 2729, 'n_tokens_neox': 2367, 'n_words': 525}