<commit_before>module.exports = function ($) {
	var Auth = {};
	var Useful = $.methods.Useful;
	var models = $.database.main.models;

	Auth.verifyCredentials = function (credentials) {
		var deferred = $.q.defer();
		models.Credential.findOne({
			attributes: ['PersonId'],
			where: {
				$or: [ {username: credentials.usernameOrEmail}, {email: credentials.usernameOrEmail} ],
				$and: {password: <PASSWORD>}
			}
		})
		// Success
		.then(function (credentials) {
			deferred.resolve(credentials);
		})
		// Error
		.catch(function (error) {
			deferred.reject(error);
		});
		return deferred.promise;
	}
	
	Auth.createSession = function (personId, res) {
		var deferred = $.q.defer();
		var sKey = Useful.createRandomWord(30);
		models.SessionKey.create({
			key: sKey,
			PersonId: personId
		})
		// Success
		.then(function (sessionKey) {
			res.cookie('uid', personId);
			res.cookie('skey', sKey);
			deferred.resolve({
				personId: personId
			});
		})
		// Error
		.catch(function (error) {
			deferred.reject(error);
		});
		return deferred.promise;
	}

	Auth.getCurrentSession = function (uid, skey) {
		var deferred = $.q.defer();
		models.SessionKey.findOne({
			PersonId: uid,
			key: skey
		})
		// Success
		.then(function (session) {
			if (!session) {
				deferred.resolve(null);
				return;
			}
			models.Person.findById(session.PersonId)
			// Success
			.then(function (person) {
				deferred.resolve(person);
			})
			// Error
			.catch(function (error) {
				deferred.reject(error);
			})
		})
		// Error
		.catch(function (error) {
			deferred.reject(error);
		});
		return deferred.promise;
	}

	Auth.deleteSession = function (uid, skey, res) {
		var deferred = $.q.defer();
		models.SessionKey.findOne({
			PersonId: uid,
			key: skey
		})
		// Success
		.then(function (session) {
			if (!session) {
				deferred.resolve(null);
				return;
			}
			session.destroy()
			// Success
			.then(function (status) {
				deferred.resolve(true);
			})
			// Error
			.catch(function (error) {
				deferred.reject(error);
			})
		})
		// Error
		.catch(function (error) {
			deferred.reject(error);
		});
		return deferred.promise;
	}

	return Auth;
}<commit_msg>Some updates<commit_after>module.exports = function ($) {
	var Auth = {};
	var Useful = $.methods.Useful;
	var models = $.database.main.models;

	Auth.verifyCredentials = function (credentials) {
		var deferred = $.q.defer();
		models.Credential.findOne({
			attributes: ['PersonId'],
			where: {
				$or: [ {username: credentials.usernameOrEmail}, {email: credentials.usernameOrEmail} ],
				$and: {password: <PASSWORD>}
			}
		})
		// Success
		.then(function (credentials) {
			deferred.resolve(credentials);
		})
		// Error
		.catch(function (error) {
			deferred.reject(error);
		});
		return deferred.promise;
	}
	
	Auth.createSession = function (personId, res) {
		var deferred = $.q.defer();
		var sKey = Useful.createRandomWord(30);
		models.SessionKey.create({
			key: sKey,
			PersonId: personId
		})
		// Success
		.then(function (sessionKey) {
			res.cookie('uid', personId);
			res.cookie('skey', sKey);
			deferred.resolve({
				personId: personId
			});
		})
		// Error
		.catch(function (error) {
			deferred.reject(error);
		});
		return deferred.promise;
	}

	Auth.getCurrentSession = function (uid, skey) {
		var deferred = $.q.defer();
		models.SessionKey.findOne({
			PersonId: uid,
			key: skey
		})
		// Success
		.then(function (session) {
			if (!session) {
				deferred.resolve(null);
				return;
			}
			models.Person.findById(session.PersonId)
			// Success
			.then(function (person) {
				deferred.resolve(person);
			})
			// Error
			.catch(function (error) {
				deferred.reject(error);
			})
		})
		// Error
		.catch(function (error) {
			deferred.reject(error);
		});
		return deferred.promise;
	}

	Auth.deleteSession = function (uid, skey, res) {
		var deferred = $.q.defer();
		models.SessionKey.findOne({
			PersonId: uid,
			key: skey
		})
		// Success
		.then(function (session) {
			if (!session) {
				deferred.resolve(null);
				return;
			}
			session.destroy()
			// Success
			.then(function (status) {
				deferred.resolve(true);
			})
			// Error
			.catch(function (error) {
				deferred.reject(error);
			})
		})
		// Error
		.catch(function (error) {
			deferred.reject(error);
		});
		return deferred.promise;
	}

	Auth.verifyPlatformAccess = function (uid, platformPath) {
		
	}

	return Auth;
}
{'fraction_non_alphanumeric': 0.16170500676589986, 'fraction_numerical': 0.0009021199819576004, 'mean_word_length': 2.9598214285714284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3351207', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1526, 'n_words': 285}