<commit_before>'use strict';

/**
 * @ngdoc service
 * @name upstreamApp.djangoAuth
 * @description
 * # djangoAuth
 * Service in the upstreamApp.
 */
angular.module('upstreamApp')
  .service('djangoAuth', function djangoAuth($q, $http, $cookies, $rootScope, $location, $window) {
    // AngularJS will instantiate a singleton by calling "new" on this function
    var service = {
        /* START CUSTOMIZATION HERE */
        // Change this to point to your Django REST Auth API
        // e.g. /api/rest-auth  (DO NOT INCLUDE ENDING SLASH)
        'API_URL': '//172.16.58.3/rest-auth',
        // Set use_session to true to use Django sessions to store security token.
        // Set use_session to false to store the security token locally and transmit it as a custom header.
        'use_session': false,
        /* END OF CUSTOMIZATION */
        'authenticated': null,
        'authPromise': null,
        'request': function(args) {
            // Let's retrieve the token from the cookie, if available
            if($window.sessionStorage.token){
                $http.defaults.headers.common.Authorization = 'Token ' + $window.sessionStorage.token;
				$rootScope.authenticated = true;
            };
			if($window.sessionStorage.currentUser){
				$rootScope.currentUser =  JSON.parse($window.sessionStorage.currentUser);
			};
            // Continue
            params = args.params || {}
            args = args || {};
            var deferred = $q.defer(),
                url = this.API_URL + args.url,
                method = args.method || "GET",
                params = params,
                data = args.data || {};
            // Fire the request, as configured.
            $http({
                url: url,
                withCredentials: this.use_session,
                method: method.toUpperCase(),
                headers: {'X-CSRFToken': $cookies['csrftoken']},
                params: params,
                data: data
            })
            .success(angular.bind(this,function(data, status, headers, config) {
                deferred.resolve(data, status);
            }))
            .error(angular.bind(this,function(data, status, headers, config) {
                console.log("error syncing with: " + url);
                // Set request status
                if(data){
                    data.status = status;
                }
                if(status == 0){
                    if(data == ""){
                        data = {};
                        data['status'] = 0;
                        data['non_field_errors'] = ["Could not connect. Please try again."];
                    }
                    // or if the data is null, then there was a timeout.
                    if(data == null){
                        // Inject a non field error alerting the user
                        // that there's been a timeout error.
                        data = {};
                        data['status'] = 0;
                        data['non_field_errors'] = ["Server timed out. Please try again."];
                    }
                }
                deferred.reject(data, status, headers, config);
            }));
            return deferred.promise;
        },
        'register': function(username,<PASSWORD>,<PASSWORD>,email,more){
            var data = {
                'username':username,
                'password1':<PASSWORD>,
                '<PASSWORD>':<PASSWORD>,
                'email':email
            }
            data = angular.extend(data,more);
            return this.request({
                'method': "POST",
                'url': "/registration/",
                'data' :data
            });
        },
        'login': function(username,password){
            var djangoAuth = this;
            return this.request({
                'method': "POST",
                'url': "/login/",
                'data':{
                    'username':username,
                    'password':password
                }
            }).then(function(data){
                if(!djangoAuth.use_session){
                    $http.defaults.headers.common.Authorization = 'Token ' + data.key;
                    //$cookies.token = data.key;
					$window.sessionStorage.token = data.key;	
                }
				djangoAuth.profile().then(function(data){
  					$rootScope.currentUser = data;<commit_msg>clear out old auth variables when logging in<commit_after>'use strict';

/**
 * @ngdoc service
 * @name upstreamApp.djangoAuth
 * @description
 * # djangoAuth
 * Service in the upstreamApp.
 */
angular.module('upstreamApp')
  .service('djangoAuth', function djangoAuth($q, $http, $cookies, $rootScope, $location, $window) {
    // AngularJS will instantiate a singleton by calling "new" on this function
    var service = {
        /* START CUSTOMIZATION HERE */
        // Change this to point to your Django REST Auth API
        // e.g. /api/rest-auth  (DO NOT INCLUDE ENDING SLASH)
        'API_URL': '//172.16.58.3/rest-auth',
        // Set use_session to true to use Django sessions to store security token.
        // Set use_session to false to store the security token locally and transmit it as a custom header.
        'use_session': false,
        /* END OF CUSTOMIZATION */
        'authenticated': null,
        'authPromise': null,
        'request': function(args) {
            // Let's retrieve the token from the cookie, if available
            if($window.sessionStorage.token){
                $http.defaults.headers.common.Authorization = 'Token ' + $window.sessionStorage.token;
				$rootScope.authenticated = true;
            };
			if($window.sessionStorage.currentUser){
				$rootScope.currentUser =  JSON.parse($window.sessionStorage.currentUser);
			};
            // Continue
            params = args.params || {}
            args = args || {};
            var deferred = $q.defer(),
                url = this.API_URL + args.url,
                method = args.method || "GET",
                params = params,
                data = args.data || {};
            // Fire the request, as configured.
            $http({
                url: url,
                withCredentials: this.use_session,
                method: method.toUpperCase(),
                headers: {'X-CSRFToken': $cookies['csrftoken']},
                params: params,
                data: data
            })
            .success(angular.bind(this,function(data, status, headers, config) {
                deferred.resolve(data, status);
            }))
            .error(angular.bind(this,function(data, status, headers, config) {
                console.log("error syncing with: " + url);
                // Set request status
                if(data){
                    data.status = status;
                }
                if(status == 0){
                    if(data == ""){
                        data = {};
                        data['status'] = 0;
                        data['non_field_errors'] = ["Could not connect. Please try again."];
                    }
                    // or if the data is null, then there was a timeout.
                    if(data == null){
                        // Inject a non field error alerting the user
                        // that there's been a timeout error.
                        data = {};
                        data['status'] = 0;
                        data['non_field_errors'] = ["Server timed out. Please try again."];
                    }
                }
                deferred.reject(data, status, headers, config);
            }));
            return deferred.promise;
        },
        'register': function(username,<PASSWORD>,<PASSWORD>,email,more){
            var data = {
                'username':username,
                'password1':<PASSWORD>,
                'password2':<PASSWORD>,
                'email':email
            }
            data = angular.extend(data,more);
            return this.request({
                'method': "POST",
                'url': "/registration/",
                'data' :data
            });
        },
        'login': function(username,password){
            var djangoAuth = this;
			delete $http.defaults.headers.common.Authorization;
			delete $window.sessionStorage.token;
			delete $window.sessionStorage.currentUser;			
            return this.request({
                'method': "POST",
                'url': "/login/",
                'data':{
                    'username':username,
                    'password':password
                }
            }).then(function(data){
                if(!djangoAuth.use_session){
                    $http.defaults.headers.common.Authorization = 'Token ' + data.key;
                    //$cookies.token = data.key;
					$window.sessionStorage.token = data.key;	
                }
				djangoAuth.profile().then(function(data){
  					$rootScope.currentUser = data;
{'fraction_non_alphanumeric': 0.11850358422939068, 'fraction_numerical': 0.002800179211469534, 'mean_word_length': 1.4276780859162588, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5375863', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2179, 'n_words': 554}