diff --git a/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js b/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js index 1418f30..51e4e03 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js @@ -71,11 +71,14 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.shapestyleborderWidth = 2; $rootScope.shapestyleborderStyles = "solid"; + + $rootScope.initializeAIA = function () { $rootScope.isLoading = false; $rootScope.isVisibleLogin = true; + getUserDetails(); } $rootScope.userInfo = { @@ -87,41 +90,71 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.AuthenticateUser = function (userInfo) { $rootScope.isVisibleLogin = false; - //if (userInfo.username == "" || userInfo.username == null || userInfo.password == "" || userInfo.password == null) { + if (userInfo.username == "" || userInfo.username == null || userInfo.password == "" || userInfo.password == null) { - // alert("Please enter correct information"); + alert("Please enter correct information"); - //} - //else { + } + else { - // AuthenticationService.authenticateUser(userInfo) - // .then( - - // function (result) { - // if (result == LoginConstants.USER_NOT_FOUND) { - - // alert(result); - // } - // else if (result == LoginConstants.ERROR_IN_FECTHING_DETAILS) { - // alert(result); - // } - // else { - // if (result.loginId != undefined || result.loginId != "" || result.loginId != null) - - // $rootScope.userData = result; - // $rootScope.userModules = result.modules; - // $rootScope.isVisibleLogin = false; - // } - // }, - // function (error) { - // console.log(' Error in authentication = ' + error.statusText); - // alert(LoginConstants.ERROR_IN_FECTHING_DETAILS); - // }); - //} + AuthenticationService.authenticateUser(userInfo) + .then( + + function (result) { + if (result == LoginConstants.USER_NOT_FOUND) { + + alert(result); + } + else if (result == LoginConstants.ERROR_IN_FECTHING_DETAILS) { + alert(result); + } + else { + if (result.loginId != undefined || result.loginId != "" || result.loginId != null) { + + $rootScope.userData = result; + $rootScope.userModules = result.modules; + $rootScope.isVisibleLogin = false; + + localStorage.setItem('loggedInUserDetails', JSON.stringify(result)); + } + } + }, + function (error) { + console.log(' Error in authentication = ' + error.statusText); + alert(LoginConstants.ERROR_IN_FECTHING_DETAILS); + }); + } } + $rootScope.LogoutUser = function () { + localStorage.removeItem('loggedInUserDetails'); + document.location = '/'; + $rootScope.isVisibleLogin = true; + } + + function getUserDetails() { + //Retain logged in user details + var currentUserDetails = localStorage.getItem('loggedInUserDetails'); + if (currentUserDetails) { + try { + var userInfo = JSON.parse(storedUser); + + if (userInfo.loginId != undefined || userInfo.loginId != "" || userInfo.loginId != null) { + $rootScope.isVisibleLogin = false; + $rootScope.userData = userInfo; + $rootScope.userModules = userInfo.modules; + } + } + catch (e) { + localStorage.removeItem('loggedInUserDetails'); + } + } + } + $(document).ready(function () { + getUserDetails(); + }); $rootScope.$on("$locationChangeSuccess", function () { diff --git a/400-SOURCECODE/AIAHTML5.Web/app/widget/TopMenu.html b/400-SOURCECODE/AIAHTML5.Web/app/widget/TopMenu.html index dc2b85c..a56ba1c 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/widget/TopMenu.html +++ b/400-SOURCECODE/AIAHTML5.Web/app/widget/TopMenu.html @@ -52,9 +52,9 @@