<commit_before>import AdhHttp = require("../Http/Http");
import AdhConfig = require("../Config/Config");

var pkgLocation = "/User";

export interface IUserBasic {
    name? : string;
    email? : string;
    tzname? : string;
}


interface IScopeLogin {
    user : User;
    credentials : {
        nameOrEmail : string;
        password : string;
    };
    errors : string[];

    resetCredentials : () => void;
    logIn : () => ng.IPromise<void>;
}


interface IScopeRegister {
    input : {
        username : string;
        email : string;
        password : string;
        passwordRepeat : string;
    };
    errors : string[];

    register : () => ng.IPromise<void>;
}


export interface IRegisterResponse {}


var bindServerErrors = (
    $scope : {errors : string[]},
    errors : AdhHttp.IBackendErrorItem[]
) => {
    $scope.errors = [];
    if (!errors.length) {
        $scope.errors.push("Unknown error from server (no details provided)");
    } else {
        errors.forEach((e) => {
            $scope.errors.push(e.description);
        });
    }
};


export class User {
    public loggedIn : boolean = false;
    public data : IUserBasic;
    private token : string;

    constructor(
        private adhHttp : AdhHttp.Service<any>,
        private $q : ng.IQService,
        private $http : ng.IHttpService,
        private $rootScope : ng.IScope,
        private $window : Window,
        private angular : ng.IAngularStatic,
        private Modernizr
    ) {
        var _self : User = this;

        var updateTokenFromStorage = () => {
            if (_self.Modernizr.localstorage) {
                if (_self.$window.localStorage.getItem("user-token") !== null &&
                        _self.$window.localStorage.getItem("user-path") !== null) {
                    _self.enableToken(
                        _self.$window.localStorage.getItem("user-token"),
                        _self.$window.localStorage.getItem("user-path")
                    );
                } else if (_self.$window.localStorage.getItem("user-token") === null &&
                        _self.$window.localStorage.getItem("user-path") === null) {
                    // For some reason, $apply is necessary here to trigger a UI update
                    _self.$rootScope.$apply(() => {
                        _self.deleteToken();
                    });
                }
            }
        };

        var win = _self.angular.element(_self.$window);
        win.on("storage", updateTokenFromStorage);

        updateTokenFromStorage();
    }
<commit_msg>Fixup 8335e697d1<commit_after>import _ = require("lodash");

import AdhHttp = require("../Http/Http");
import AdhConfig = require("../Config/Config");

var pkgLocation = "/User";

export interface IUserBasic {
    name? : string;
    email? : string;
    tzname? : string;
}


interface IScopeLogin {
    user : User;
    credentials : {
        nameOrEmail : string;
        password : string;
    };
    errors : string[];

    resetCredentials : () => void;
    logIn : () => ng.IPromise<void>;
}


interface IScopeRegister {
    input : {
        username : string;
        email : string;
        password : string;
        passwordRepeat : string;
    };
    errors : string[];

    register : () => ng.IPromise<void>;
}


export interface IRegisterResponse {}


var bindServerErrors = (
    $scope : {errors : string[]},
    errors : AdhHttp.IBackendErrorItem[]
) => {
    $scope.errors = [];
    if (!errors.length) {
        $scope.errors.push("Unknown error from server (no details provided)");
    } else {
        errors.forEach((e) => {
            $scope.errors.push(e.description);
        });
    }
};


export class User {
    public loggedIn : boolean = false;
    public data : IUserBasic;
    private token : string;

    constructor(
        private adhHttp : AdhHttp.Service<any>,
        private $q : ng.IQService,
        private $http : ng.IHttpService,
        private $rootScope : ng.IScope,
        private $window : Window,
        private angular : ng.IAngularStatic,
        private Modernizr
    ) {
        var _self : User = this;

        var updateTokenFromStorage = () => {
            if (_self.Modernizr.localstorage) {
                if (_self.$window.localStorage.getItem("user-token") !== null &&
                        _self.$window.localStorage.getItem("user-path") !== null) {
                    _self.enableToken(
                        _self.$window.localStorage.getItem("user-token"),
                        _self.$window.localStorage.getItem("user-path")
                    );
                } else if (_self.$window.localStorage.getItem("user-token") === null &&
                        _self.$window.localStorage.getItem("user-path") === null) {
                    // For some reason, $apply is necessary here to trigger a UI update
                    _.defer(() => _self.$rootScope.$apply(() => {
                        _self.deleteToken();
                    }));
                }
            }
        };

        var win = _self.angular.element(_self.$window);
        win.on("storage", updateTokenFromStorage);

        updateTokenFromStorage();
    }

{'fraction_non_alphanumeric': 0.1311885956463109, 'fraction_numerical': 0.001541128876902331, 'mean_word_length': 1.8685082872928176, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 24, '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': '374410', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1420, 'n_words': 298}