AuthenticationController.js 2.23 KB
/// <reference path="../../index.html" />
/// <reference path="../../index.html" />
'use strict';
(function () {
    "use strict";
    AIA.controller("AuthenticationController", ["userAccount",
                                            AuthenticationController]);

    function AuthenticationController(userAccount)
    {
        var AuthenCtrl = this;
        AuthenCtrl.isLoggedIn = false;
        AuthenCtrl.userData = {
            userName: ''
        };

        AuthenCtrl.login = function () {
            AuthenCtrl.userData.grant_type = "password";
            AuthenCtrl.userData.userName = AuthenCtrl.userData.userName;

            userAccount.login.loginUser(AuthenCtrl.userData, function (data) {

                AuthenCtrl.isLoggedIn = true;
                AuthenCtrl.message = "";
                AuthenCtrl.password = "";
                AuthenCtrl.token = data.access_token;
            },

            function (response)
            {
                AuthenCtrl.password = "";
                AuthenCtrl.isLoggedIn = false;
                AuthenCtrl.message = response.statusText + "\r\n"
                if(response.data.exceptionMessage)
                {
                    AuthenCtrl.message += response.data.exceptionMessage;
                }

                if(response.data.error)
                {
                    AuthenCtrl.message += response.data.error;
                }

            }
            
            )



        }

    }

})();



//AIA.controller("AuthenticationController", ["$scope", "$log", "$location", '$window', "$timeout", "AuthenticationService",
//    function ($scope, $log, $location, $window, $timeout, AuthenticationService) {
//        $scope.IsAuthenticated = false;

//        $scope.login = function () {


//                 var result = AuthenticationService.authenticateUser1("Authentication", "isUserAuthenticated", 'superadmin','education').success(function (data) {
//                var data = $.parseJSON(JSON.parse(data));
//                $scope.IsAuthenticated = data;
//                alert('$scope.IsAuthenticated= ' + $scope.IsAuthenticated);
//            });
//        }
       
//    }
//    ]);