<commit_before>var app = angular.module('subutai-app', [
    'ui.router',
    'ngCookies',
    'ngResource',
    'oc.lazyLoad',
    'oitozero.ngSweetAlert',
    'ngDialog',
    'datatables',
    '720kb.tooltips',
    'ngTagsInput',
    'nvd3',
    'cfp.loadingBar',
    'uiSwitch',
    'ngFileUpload'
])
    .config(routesConf)

    .controller('SubutaiController', SubutaiController)
    .controller('CurrentUserCtrl', CurrentUserCtrl)

    .controller('AccountCtrl', AccountCtrl)
    .factory('identitySrv', identitySrv)

    .factory('trackerSrv', trackerSrv)

    .run(startup);

CurrentUserCtrl.$inject = ['$location', '$scope', '$rootScope', '$http', 'SweetAlert', 'ngDialog', 'trackerSrv'];
routesConf.$inject = ['$httpProvider', '$stateProvider', '$urlRouterProvider', '$ocLazyLoadProvider'];
startup.$inject = ['$rootScope', '$state', '$location', '$http', 'SweetAlert', 'ngDialog'];

function CurrentUserCtrl($location, $scope, $rootScope, $http, SweetAlert, ngDialog, trackerSrv) {
    var vm = this;
    vm.currentUser = localStorage.getItem('currentUser');
    vm.hubStatus = false;
    vm.userId = "";
    vm.userEmail = "";
    vm.notifications = [];
    vm.notificationsCount = 0;
    vm.notificationNew = false;
    vm.notificationsLogs = [];
    vm.currentLogTitle = '';
    vm.currentLog = [];
    vm.currentUserRoles = [];
    $rootScope.notifications = {};
    vm.hubRegisterError = false;
    vm.isRegistrationFormVisible = false;

    vm.getRegistrationFormVisibilityStatus = function () {
        return vm.isRegistrationFormVisible;
    };


    function checkIfRegistered(afterRegistration) {
        if (afterRegistration === undefined || afterRegistration === null) afterRegistration = false;
        $http.get(SERVER_URL + "rest/v1/hub/registration_state", {
            withCredentials: true,
            headers: {'Content-Type': 'application/json'}
        }).success(function (data) {

            vm.hubStatus = data.isRegisteredToHub;
            vm.userId = data.ownerId;
            vm.userEmail = data.ownerEmail;

            if (vm.hubStatus != "true" && vm.hubStatus != true) {
                vm.hubStatus = false;
            } else {
                vm.hubStatus = true;
            }

            if (afterRegistration) {
                hubPopupLoadScreen();
                ngDialog.open({
                    template: 'subutai-app/common/partials/hubSuccessMessage.html',
                    scope: $scope
                });
            }
        });
    }

    checkIfRegistered();

    setInterval(function () {
        checkIfRegistered();
    }, 30000);


    vm.hub = {
        login: "",
        password: ""
    };


    //function
    vm.logout = logout;
    vm.hubRegister = hubRegister;
    vm.hubUnregister = hubUnregister;
    vm.hubHeartbeat = hubHeartbeat;
    vm.clearLogs = clearLogs;
    vm.viewLogs = viewLogs;


    function hubPopupLoadScreen(show) {
        if (show == undefined || show == null) show = false;
        if (show) {
            $('.js-hub-screen').show();
        } else {
            $('.js-hub-screen').hide();
        }
    }


    function hubRegister() {
        vm.hubRegisterError = false;
        hubPopupLoadScreen(true);
        var postData = 'hubIp=hub.subut.ai&email=' + vm.hub.login + '&password=' + vm.hub.password;
        $http.post(SERVER_URL + 'rest/v1/hub/register', postData, {
            withCredentials: true,
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        })
            .success(function () {

                checkIfRegistered(true);

                $http.post(SERVER_URL + 'rest/v1/hub/send-heartbeat?hubIp=hub.subut.ai', {
                    withCredentials: true,
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                })
                    .success(function () {
                    }).error(function (error) {<commit_msg>encode password on hub registration<commit_after>var app = angular.module('subutai-app', [
    'ui.router',
    'ngCookies',
    'ngResource',
    'oc.lazyLoad',
    'oitozero.ngSweetAlert',
    'ngDialog',
    'datatables',
    '720kb.tooltips',
    'ngTagsInput',
    'nvd3',
    'cfp.loadingBar',
    'uiSwitch',
    'ngFileUpload'
])
    .config(routesConf)

    .controller('SubutaiController', SubutaiController)
    .controller('CurrentUserCtrl', CurrentUserCtrl)

    .controller('AccountCtrl', AccountCtrl)
    .factory('identitySrv', identitySrv)

    .factory('trackerSrv', trackerSrv)

    .run(startup);

CurrentUserCtrl.$inject = ['$location', '$scope', '$rootScope', '$http', 'SweetAlert', 'ngDialog', 'trackerSrv'];
routesConf.$inject = ['$httpProvider', '$stateProvider', '$urlRouterProvider', '$ocLazyLoadProvider'];
startup.$inject = ['$rootScope', '$state', '$location', '$http', 'SweetAlert', 'ngDialog'];

function CurrentUserCtrl($location, $scope, $rootScope, $http, SweetAlert, ngDialog, trackerSrv) {
    var vm = this;
    vm.currentUser = localStorage.getItem('currentUser');
    vm.hubStatus = false;
    vm.userId = "";
    vm.userEmail = "";
    vm.notifications = [];
    vm.notificationsCount = 0;
    vm.notificationNew = false;
    vm.notificationsLogs = [];
    vm.currentLogTitle = '';
    vm.currentLog = [];
    vm.currentUserRoles = [];
    $rootScope.notifications = {};
    vm.hubRegisterError = false;
    vm.isRegistrationFormVisible = false;

    vm.getRegistrationFormVisibilityStatus = function () {
        return vm.isRegistrationFormVisible;
    };


    function checkIfRegistered(afterRegistration) {
        if (afterRegistration === undefined || afterRegistration === null) afterRegistration = false;
        $http.get(SERVER_URL + "rest/v1/hub/registration_state", {
            withCredentials: true,
            headers: {'Content-Type': 'application/json'}
        }).success(function (data) {

            vm.hubStatus = data.isRegisteredToHub;
            vm.userId = data.ownerId;
            vm.userEmail = data.ownerEmail;

            if (vm.hubStatus != "true" && vm.hubStatus != true) {
                vm.hubStatus = false;
            } else {
                vm.hubStatus = true;
            }

            if (afterRegistration) {
                hubPopupLoadScreen();
                ngDialog.open({
                    template: 'subutai-app/common/partials/hubSuccessMessage.html',
                    scope: $scope
                });
            }
        });
    }

    checkIfRegistered();

    setInterval(function () {
        checkIfRegistered();
    }, 30000);


    vm.hub = {
        login: "",
        password: ""
    };


    //function
    vm.logout = logout;
    vm.hubRegister = hubRegister;
    vm.hubUnregister = hubUnregister;
    vm.hubHeartbeat = hubHeartbeat;
    vm.clearLogs = clearLogs;
    vm.viewLogs = viewLogs;


    function hubPopupLoadScreen(show) {
        if (show == undefined || show == null) show = false;
        if (show) {
            $('.js-hub-screen').show();
        } else {
            $('.js-hub-screen').hide();
        }
    }


    function hubRegister() {
        vm.hubRegisterError = false;
        hubPopupLoadScreen(true);
        var postData = 'hubIp=hub.subut.ai&email=' + vm.hub.login + '&password=' + encodeURIComponent( vm.<PASSWORD>.password );
        $http.post(SERVER_URL + 'rest/v1/hub/register', postData, {
            withCredentials: true,
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        })
            .success(function () {

                checkIfRegistered(true);

                $http.post(SERVER_URL + 'rest/v1/hub/send-heartbeat?hubIp=hub.subut.ai', {
                    withCredentials: true,
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                })
                    .success(function () {
                    }).error(function (error) {
{'fraction_non_alphanumeric': 0.1441418619379354, 'fraction_numerical': 0.003293223559214693, 'mean_word_length': 2.285892634207241, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4739316', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2301, 'n_words': 385}