<commit_before>'use strict';

/* 
 * Auth Services
 * Sets Nav, Session and Build as global page variables. 
 */

angular.module('AuthService', [
    'rcAuth.constants',
    'rcAuth.cookies',
    'rcAuth.facebook',
    'rcAuth.interceptors',
    'rcAuth.user',
    'rcAuth.visibility'
]).factory('AuthService', ['$rootScope', '$q', '$log', 'UserSession', 'AUTH_EVENTS', 'VisibilityService', 'ApiRoutesAuth', 'FacebookAuthService', 'CookieService',
    function($rootScope, $q, $log, UserSession, AUTH_EVENTS, VisibilityService, API, FacebookAuthService, CookieService) {
        
        var factory = {};
        
        factory.init = function() {
            /* Returns promise that always resolves true */ 
            return $q(function (resolve, reject) {
                if (UserSession.get()) {
                    return resolve(true);
                }
                
                var credentials = CookieService.getAuthCookie();
            
                if (credentials) {
                        API.getAuthenticatedUser(credentials)
                        .then(function (data) {
                            data.user.apiKey = credentials.apiKey;
                            data.user.apiToken = credentials.apiToken;
                            if (!UserSession.create(data.user)) {
                                $log.error('[authInit] Credentials found but session Couldn\'t be Created', data);
                            }
                            return resolve(true);
                        }, function (error) {
                            $log.info('[authInit] No Credentials Found', error);
                            return resolve(true);
                        });
                } else {
                    return resolve(true);
                }
            });
        };<commit_msg>Bug Fix: Infinite loop was occuring when accessing login and signup.<commit_after>'use strict';

/* 
 * Auth Services
 * Sets Nav, Session and Build as global page variables. 
 */

angular.module('AuthService', [
    'rcAuth.constants',
    'rcAuth.cookies',
    'rcAuth.facebook',
    'rcAuth.interceptors',
    'rcAuth.user',
    'rcAuth.visibility'
]).factory('AuthService', ['$rootScope', '$q', '$log', 'UserSession', 'AUTH_EVENTS', 'VisibilityService', 'ApiRoutesAuth', 'FacebookAuthService', 'CookieService',
    function($rootScope, $q, $log, UserSession, AUTH_EVENTS, VisibilityService, API, FacebookAuthService, CookieService) {
        
        var factory = {};
        
        factory.init = function() {
            /* Returns promise that always resolves true */ 
            return $q(function (resolve, reject) {
                if (UserSession.get()) {
                    return resolve(true);
                }
                
                var credentials = CookieService.getAuthCookie();
            
                if (credentials) {
                        API.getAuthenticatedUser(credentials)
                        .then(function (data) {
                            data.user.apiKey = credentials.apiKey;
                            data.user.apiToken = credentials.apiToken;
                            if (!UserSession.create(data.user)) {
                                $log.error('[authInit] Credentials found but session Couldn\'t be Created', data);
                            }
                            return resolve(true);
                        }, function (error) {
                            $log.info('[authInit] No Credentials Found', error);
                            return resolve(false);
                        });
                } else {
                    return resolve(false);
                }
            });
        };
{'fraction_non_alphanumeric': 0.1113202473783275, 'fraction_numerical': 0.0, 'mean_word_length': 1.4409448818897639, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4716512', 'n_tokens_mistral': 917, 'n_tokens_neox': 870, 'n_words': 198}