<commit_before>angular
    .module('app')
    .controller('loginController', [
        '$rootScope',
        '$scope',
        '$location',
        'authService',
        '$timeout',
        '$routeParams',
        function($rootScope, $scope, $location, Auth, $timeout, $routeParams) {

            // we use this to set credentials for demo on initial page screen
            $rootScope.demoCredentials = {
                admin: {
                    email: '<EMAIL>',
                    password: '<PASSWORD>'
                },
                salesRep: {
                    email: '<EMAIL>',
                    password: '<PASSWORD>'
                },
                vendorRep: {
                    email: '<EMAIL>',
                    password: '<PASSWORD>'
                }
            };


            /**
             * This allows us to pass credentials into the controller to prefill the login form fields
             * This is useful for demos and dev.
             *
             */
            if ($routeParams.demo) {
                $scope.email = $rootScope.demoCredentials[$routeParams.demo].email;
                $scope.password = $rootScope.demoCredentials[$routeParams.demo].password;
            }

            /**
             * Runs on success, useful for redirecting etc.
             *
             */

            function loginSuccessCallback() {
                // clear any demo params as needed
                $location.search('demo', null);
                // go to daahboard
                $location.url('/dashboard');
            }


            // used to provide a button specific activity spinner 
            // @todo eliminate this in favor of the namespaced "activity" spinners
            // @see https://github.com/ajoslin/angular-promise-tracker
            $scope.isProcessing = false;

            $scope.login = function() {

                $scope.isProcessing = true;

                Auth.login($scope.email, $scope.password).then(function(response) {

                    // @todo make this more robust! 
                    var loginSuccess = response;

                    $scope.isProcessing = false;

                    if (!loginSuccess) {
                        $scope.message = 'Login failed, please try again';
                    } else {
                        loginSuccessCallback();
                    }

                }, function(err) {
                    $scope.isProcessing = false;
                });

            };

        }
    ]);<commit_msg>Provide more robust error handling for login.<commit_after>angular
    .module('app')
    .controller('loginController', [
        '$rootScope',
        '$scope',
        '$location',
        'authService',
        '$timeout',
        '$routeParams',
        function($rootScope, $scope, $location, Auth, $timeout, $routeParams) {

            // declare variables
            $scope.email = '';
            $scope.password = '';
            
            // we use this to set credentials for demo on initial page screen
            $rootScope.demoCredentials = {
                admin: {
                    email: '<EMAIL>',
                    password: '<PASSWORD>'
                },
                salesRep: {
                    email: '<EMAIL>',
                    password: '<PASSWORD>'
                },
                vendorRep: {
                    email: '<EMAIL>',
                    password: '<PASSWORD>'
                }
            };


            /**
             * This allows us to pass credentials into the controller to prefill the login form fields
             * This is useful for demos and dev.
             *
             */
            if ($routeParams.demo) {
                $scope.email = $rootScope.demoCredentials[$routeParams.demo].email;
                $scope.password = $rootScope.demoCredentials[$routeParams.demo].password;
            }

            /**
             * Runs on success, useful for redirecting etc.
             *
             */

            function loginSuccessCallback() {
                // clear any demo params as needed
                $location.search('demo', null);
                // go to daahboard
                $location.url('/dashboard');
            }
            
             // sets message and removes after timeout
            var setMessage = function(message) {
                $scope.message = message;

                // set timeout to clear our message after 2 seconds
                $timeout(function() {
                    $scope.message = null;
                }, 2000);

            };


            // used to provide a button specific activity spinner 
            // @todo eliminate this in favor of the namespaced "activity" spinners
            // @see https://github.com/ajoslin/angular-promise-tracker
            $scope.isProcessing = false;

            $scope.login = function() {

                $scope.isProcessing = true;

                Auth.login($scope.email, $scope.password).then(function(response) {

                    // @todo make this more robust! 
                    $scope.isProcessing = false;
                    loginSuccessCallback();

                }, function(err) {
                    console.log(err);
                    setMessage('There was a problem loggin you in. ');
                    $scope.isProcessing = false;
                    
                });

            };

        }
    ]);
{'fraction_non_alphanumeric': 0.10237659963436929, 'fraction_numerical': 0.0009140767824497258, 'mean_word_length': 1.1556343577620174, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '2751112', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1199, 'n_words': 316}