<commit_before>/**
 * Created by tomasj on 26/04/14.
 */

var checkLoggedin = function($q, $timeout, $http, $location, $rootScope) {
// Initialize a new promise
    var deferred = $q.defer();
// Make an AJAX call to check if the user is logged in
    $http.get('/loggedin').success(function(user) {
        // Authenticated
        if (user !== '0') {
            $timeout(deferred.resolve, 0);
        }
        // Not Authenticated
        else {
            $rootScope.message = 'You need to log in.';
            $timeout(function() {
                deferred.reject();
            }, 0);
            $location.url('/');
        }
    });
};

var WeddingPlanner = angular.module('WeddingPlanner', [
    'flow',
    'ngRoute'
]);

WeddingPlanner.service('auth', ['$http', function($http) {
	var self = this;

	this.logged = null;
	this.username = '';
    this.log = [];
//	this.avatar = '';

	this.update = function(callback) {
        self.log.push('going to update login status');
		$http({method: 'GET', url: '/loggedin'}).
		success(function(data, status, headers, config) {
			if (null !== data['fb_id']) {
                self.log.push('user authenticated');
				self.logged = true;
				self.username = data['first_name'];
//				self.avatar = data['avatar'];
			} else {
                self.log.push('user NOT authenticated');
				self.logged = false;
			}
			undefined === callback || callback(self);
		}).
		error(function(data, status, headers, config) {
			self.log.push('Connection to /loggedin failed');
		});

		callback(self);
	};

	this.updateIfNeeded = function(callback) {
		if (null === self.logged) {
			self.update(callback);<commit_msg>use != to compare null to non-existing object attribute<commit_after>/**
 * Created by tomasj on 26/04/14.
 */

var checkLoggedin = function($q, $timeout, $http, $location, $rootScope) {
// Initialize a new promise
    var deferred = $q.defer();
// Make an AJAX call to check if the user is logged in
    $http.get('/loggedin').success(function(user) {
        // Authenticated
        if (user !== '0') {
            $timeout(deferred.resolve, 0);
        }
        // Not Authenticated
        else {
            $rootScope.message = 'You need to log in.';
            $timeout(function() {
                deferred.reject();
            }, 0);
            $location.url('/');
        }
    });
};

var WeddingPlanner = angular.module('WeddingPlanner', [
    'flow',
    'ngRoute'
]);

WeddingPlanner.service('auth', ['$http', function($http) {
	var self = this;

	this.logged = null;
	this.username = '';
    this.log = [];
//	this.avatar = '';

	this.update = function(callback) {
        self.log.push('going to update login status');
		$http({method: 'GET', url: '/loggedin'}).
		success(function(data, status, headers, config) {
			if (null != data['fb_id']) {
                self.log.push('user authenticated');
				self.logged = true;
				self.username = data['first_name'];
//				self.avatar = data['avatar'];
			} else {
                self.log.push('user NOT authenticated');
				self.logged = false;
			}
			undefined === callback || callback(self);
		}).
		error(function(data, status, headers, config) {
			self.log.push('Connection to /loggedin failed');
		});

		callback(self);
	};

	this.updateIfNeeded = function(callback) {
		if (null === self.logged) {
			self.update(callback);
{'fraction_non_alphanumeric': 0.1694915254237288, 'fraction_numerical': 0.0053523639607493305, 'mean_word_length': 2.496881496881497, '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': '5169294', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1052, 'n_words': 242}