<commit_before>'use strict';

var Q = require('q');
var UserFactory = require('./UserFactoryService.js');

module.exports = function(session) {
	var self = this;

	this.session = session;

	this.login = function(name) {
    	return UserFactory.findByName(name);
	};

	this.logout = function(id) {
		var deferred = Q.defer();

		// Take care of cases where the client becomes de-synchronized with the server.
		if(!self.session || !self.session.user) {
			deferred.resolve();
		}
		else if(id === self.session.user.id) {
		  UserFactory.removeByUser(self.session.user).then(function() {
			self.session.destroy();
			deferred.resolve();
		  }, function() {
			deferred.reject('We had trouble logging you out. Please try again in a few minutes!');
		  });
		}
		else {
		  deferred.reject('You can\'t log out as another user.');
		}

    	return deferred.promise;
	};
};<commit_msg>Removed the unnecessary require statement from the beginning of SessionService.<commit_after>'use strict';

var Q = require('q');

module.exports = function(session) {
	var self = this;

	this.session = session;

	this.login = function(name) {
    	return UserFactoryService.findByName(name);
	};

	this.logout = function(id) {
		var deferred = Q.defer();

		// Take care of cases where the client becomes de-synchronized with the server.
		if(!self.session || !self.session.user) {
			deferred.resolve();
		}
		else if(id === self.session.user.id) {
		  UserFactoryService.removeByUser(self.session.user).then(function() {
			self.session.destroy();
			deferred.resolve();
		  }, function() {
			deferred.reject('We had trouble logging you out. Please try again in a few minutes!');
		  });
		}
		else {
		  deferred.reject('You can\'t log out as another user.');
		}

    	return deferred.promise;
	};
};
{'fraction_non_alphanumeric': 0.1444568868980963, 'fraction_numerical': 0.0, 'mean_word_length': 3.535532994923858, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '504873', 'n_tokens_mistral': 615, 'n_tokens_neox': 556, 'n_words': 144}