diff --git a/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js b/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js index 2f65ae7..dc5cb13 100644 --- a/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js +++ b/400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js @@ -1,7 +1,7 @@ 'use strict'; -AIA.controller("HomeController", ["$rootScope", "Modules", "$log", "$location", "$timeout", "DataService", "AuthenticationService", "LoginConstants", "UserModules", "LoginMessageConstants", "AdminService", "$http", "AdminConstants", "UserTypeConstants", "AIAConstants", -function ($rootScope, Modules, $log, $location, $timeout, DataService, AuthenticationService, LoginConstants, UserModules, LoginMessageConstants, AdminService, $http, AdminConstants, UserTypeConstants,AIAConstants) { +AIA.controller("HomeController", ["$rootScope", "$scope", "Modules", "$log", "$location", "$timeout", "DataService", "AuthenticationService", "LoginConstants", "UserModules", "LoginMessageConstants", "AdminService", "$http", "AdminConstants", "UserTypeConstants", "AIAConstants", +function ($rootScope, $scope, Modules, $log, $location, $timeout, DataService, AuthenticationService, LoginConstants, UserModules, LoginMessageConstants, AdminService, $http, AdminConstants, UserTypeConstants,AIAConstants) { //$scope.pageToOpen = { // name: 'MainMenu' @@ -42,6 +42,8 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.current_year = AIAConstants.current_year; // on refersh this variable will also get null that is why we are only checking this variable on initialize that if it is null that means page gets refershed. $rootScope.refreshcheck = null; + var isCommingSoonModel = true; + $rootScope.isCloseSettingClicked = false; @@ -140,9 +142,26 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.isVisibleResetPass = true; } else { - $rootScope.isVisibleLogin = true; - $rootScope.isVisibleResetPass = false; - getUserDetails(); + + $rootScope.isVisibleLogin = true; + $rootScope.isVisibleResetPass = false; + + //get user is already loggedin or not + $scope.currentUserDetails = $rootScope.getLocalStorageValue('loggedInUserDetails'); + if ($scope.currentUserDetails != undefined) { + AuthenticateAlreadyLoggedInUser(); + } + var isRememberChecked = $rootScope.getLocalStorageValue('isRememberMeChecked'); + + if ($rootScope.getLocalStorageValue('isRememberMeChecked') != "" && sessionStorage.getItem("loginSession") == null) { + sessionStorage.setItem("loginSession", "true"); + } + if (isRememberChecked == "true" && sessionStorage.getItem("loginSession") == "true" && $rootScope.isVisibleLogin == true) { + + $timeout(function () { + $rootScope.userInfo = { username: $rootScope.getLocalStorageValue('RememberMeLoginId'), password: $rootScope.getLocalStorageValue('RememberMePassword'), rememberChk: true }; + }, 800); + } } } @@ -158,21 +177,24 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.AuthenticateUser = function (userInfo) { + + if (navigator.cookieEnabled) { - $rootScope.errorMessage = ""; - if (userInfo.username == "" || userInfo.username == null || userInfo.password == "" || userInfo.password == null) { + if (userInfo.username == "" || userInfo.username == null || userInfo.username == undefined || userInfo.password == "" || userInfo.password == null || userInfo.password == undefined) { // alert(LoginMessageConstants.USER_CREDENTIALS_MISSING); $rootScope.errorMessage = LoginMessageConstants.USER_CREDENTIALS_MISSING; $("#messageModal").modal('show'); } else { - + + AuthenticationService.authenticateUser(userInfo) .then( function (result) { + if (result == LoginConstants.USER_NOT_FOUND) { $rootScope.isVisibleLogin = true; // alert(LoginMessageConstants.USER_OR_PASSWORD_INCORRECT); @@ -180,6 +202,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $("#messageModal").modal('show'); } else { + if (typeof result.LoginId != undefined || result.LoginId != "" || result.LoginId != null) { if ($("#messageModal").length > 0) { @@ -241,25 +264,76 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } else { - //if (result.UserType == UserTypeConstants.SUPER_ADMIN && result.IsActive) { //(!result.IsSubscriptionExpired) && - if (result.LicenseId == 0 && result.IsActive) { - $rootScope.userData = result; - $rootScope.userModules = result.Modules; - $rootScope.isVisibleLogin = false; + //LicenseId would be zero for admin that is why we set the haveRoleAdmin = true + if (result.LicenseId == 0 && result.IsActive) + { $rootScope.haveRoleAdmin = true; - localStorage.setItem('loggedInUserDetails', JSON.stringify(result)); - ShowAssignedModulesPopup(result.Modules); + + $rootScope.userData = result; + $rootScope.userModules = result.Modules; + + if ($scope.currentUserDetails == null || $scope.currentUserDetails == undefined || $scope.currentUserDetails == "") { + localStorage.setItem('loggedInUserDetails', JSON.stringify(result)); + } + + if (isCommingSoonModel == true) + { + + ShowAssignedModulesPopup(result.Modules); + + if (userInfo.rememberChk) { + + $scope.saveRemeberMeDetails(result, userInfo); + } + + sessionStorage.setItem("loginSession", "true"); + localStorage.setItem('isCommingSoonModel', false); + + $rootScope.isVisibleLogin = false; + } + + $location.path('/'); } else { - if (result.LicenseInfo != null && result.LicenseInfo.IsTermAccepted) { + if (result.LicenseInfo != null && result.LicenseInfo.IsTermAccepted) + { + //0. $rootScope.userData = result; $rootScope.userModules = result.Modules; - $rootScope.isVisibleLogin = false; + + //1. set haveRoleAdmin = false because LicenseInfo is not null $rootScope.haveRoleAdmin = false; - localStorage.setItem('loggedInUserDetails', JSON.stringify(result)); - ShowAssignedModulesPopup(result.Modules); + + //2. + if ($scope.currentUserDetails == null || $scope.currentUserDetails == undefined || $scope.currentUserDetails == "") { + + localStorage.setItem('loggedInUserDetails', JSON.stringify(result)); + } + + // 3.ShowAssignedModulesPopup + //isCommingSoonModel =true only when user comes first time on application and login + if (isCommingSoonModel == true) + { + + ShowAssignedModulesPopup(result.Modules); + } + + //4. + if($scope.rememberChk) + { + + $scope.saveRemeberMeDetails(result, userInfo); + } + + //5. + sessionStorage.setItem("loginSession", "true"); + $rootScope.isVisibleLogin = false; + + //6. reset the isCommingSoonModel to false in local storage so that upcomming module pop up would not show again to the user after firts time + localStorage.setItem('isCommingSoonModel', false); + $location.path('/'); } @@ -275,6 +349,8 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $location.path('/'); } } + + } @@ -297,7 +373,15 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $rootScope.promptUserForCookies(); } - } + } + + $scope.saveRemeberMeDetails = function (result, userInfo) { + + localStorage.setItem('RememberMeLoginId', result.LoginId); + localStorage.setItem('RememberMePassword', result.Password); + localStorage.setItem("isRememberMeChecked", userInfo.rememberChk); + } + function ShowAssignedModulesPopup(userModules) { var allModules = Modules; @@ -335,6 +419,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $('#dvPendingModules').show(); } } + $rootScope.UpdateLicenseTermStatus = function () { $('#dvTermCondition').fadeOut(); var currentUserDetails = $rootScope.getLocalStorageValue('loggedInUserDetails'); @@ -382,34 +467,54 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic }); } }; + $rootScope.RememberMe = function (isRememberMeChecked) + { + if (localStorage.getItem('isRememberMeChecked') != null) + { + localStorage.removeItem('loggedInUserDetails'); + localStorage.removeItem('isRememberMeChecked'); + localStorage.removeItem('RememberMeLoginId'); + localStorage.removeItem('RememberMePassword'); + + } + + } $rootScope.LogoutUser = function () { localStorage.removeItem('loggedInUserDetails'); - localStorage.clear(); + // localStorage.clear(); document.location = '/'; $rootScope.isVisibleLogin = true; } - function getUserDetails() { //Retain logged in user details - var currentUserDetails = $rootScope.getLocalStorageValue('loggedInUserDetails'); - if (currentUserDetails) { + function AuthenticateAlreadyLoggedInUser() + { + + isCommingSoonModel = $rootScope.getLocalStorageValue('isCommingSoonModel'); + try { - var userInfo = JSON.parse(currentUserDetails); + var userInfo = JSON.parse($scope.currentUserDetails); if (userInfo.LoginId != undefined || userInfo.LoginId != "" || userInfo.LoginId != null) { - if (userInfo.UserType == UserTypeConstants.SUPER_ADMIN && userInfo.IsActive) { //(!result.IsSubscriptionExpired) && - - $rootScope.userData = userInfo; - + if (userInfo.UserType == UserTypeConstants.SUPER_ADMIN && userInfo.IsActive) { + + //0 + $rootScope.userData = userInfo; $rootScope.userModules = userInfo.Modules; - - $rootScope.isVisibleLogin = false; + + //1. + userInfo["username"] = userInfo.LoginId; + userInfo["password"] = userInfo.Password; + + //2. + $rootScope.AuthenticateUser(userInfo); + $rootScope.haveRoleAdmin = true; if ($rootScope.refreshcheck == null) { - + if ($location.path() == "/lab-exercises-detail") { $location.url('/'); @@ -418,7 +523,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic $location.path('/'); } - + $rootScope.isVisibleLogin = false; } } @@ -427,11 +532,12 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic { $rootScope.haveRoleAdmin = false; - if (userInfo.LicenseInfo.IsTermAccepted) { + if (userInfo.LicenseInfo.IsTermAccepted) + { $rootScope.userData = userInfo; $rootScope.userModules = userInfo.Modules; $rootScope.isVisibleLogin = false; - //$rootScope.haveRoleAdmin = true; + if ($rootScope.refreshcheck == null) { $location.path('/'); @@ -451,11 +557,12 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic } } } + } catch (e) { localStorage.removeItem('loggedInUserDetails'); } - } + } $rootScope.SendMailToUser = function (userInfo, isMailForForgotPassword) { diff --git a/400-SOURCECODE/AIAHTML5.Web/index.html b/400-SOURCECODE/AIAHTML5.Web/index.html index d22bfd5..3effe19 100644 --- a/400-SOURCECODE/AIAHTML5.Web/index.html +++ b/400-SOURCECODE/AIAHTML5.Web/index.html @@ -205,9 +205,12 @@ Forgot Password?-->