Commit 765a47e5568f9f87b8f9eabddc98ef004c471fc9

Authored by Mukul Rajput
1 parent 933c9aea

this is solution for the bug block five times

400-SOURCECODE/AIAHTML5.Web/app/controllers/HomeController.js
1 1 'use strict';
2 2  
3   -AIA.controller("HomeController", ["$rootScope", "Modules", "$log", "$location", "$timeout", "DataService", "AuthenticationService", "LoginConstants", "UserModules", "LoginMessageConstants", "AdminService", "$http", "AdminConstants", "UserTypeConstants", "AIAConstants",
4   -function ($rootScope, Modules, $log, $location, $timeout, DataService, AuthenticationService, LoginConstants, UserModules, LoginMessageConstants, AdminService, $http, AdminConstants, UserTypeConstants,AIAConstants) {
  3 +AIA.controller("HomeController", ["$rootScope", "$scope", "Modules", "$log", "$location", "$timeout", "DataService", "AuthenticationService", "LoginConstants", "UserModules", "LoginMessageConstants", "AdminService", "$http", "AdminConstants", "UserTypeConstants", "AIAConstants",
  4 +function ($rootScope, $scope, Modules, $log, $location, $timeout, DataService, AuthenticationService, LoginConstants, UserModules, LoginMessageConstants, AdminService, $http, AdminConstants, UserTypeConstants,AIAConstants) {
5 5  
6 6 //$scope.pageToOpen = {
7 7 // name: 'MainMenu'
... ... @@ -42,8 +42,8 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
42 42 $rootScope.current_year = AIAConstants.current_year;
43 43 // 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.
44 44 $rootScope.refreshcheck = null;
45   -
46   - $rootScope.isLoginAvilableModel = true;
  45 + var isCommingSoonModel = true;
  46 +
47 47 $rootScope.isCloseSettingClicked = false;
48 48  
49 49  
... ... @@ -142,9 +142,15 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
142 142 $rootScope.isVisibleResetPass = true;
143 143 }
144 144 else {
145   - $rootScope.isVisibleLogin = true;
146   - $rootScope.isVisibleResetPass = false;
147   - getUserDetails();
  145 +
  146 + $rootScope.isVisibleLogin = true;
  147 + $rootScope.isVisibleResetPass = false;
  148 +
  149 + //get user is already loggedin or not
  150 + $scope.currentUserDetails = $rootScope.getLocalStorageValue('loggedInUserDetails');
  151 + if ($scope.currentUserDetails != undefined) {
  152 + AuthenticateAlreadyLoggedInUser();
  153 + }
148 154 }
149 155 }
150 156  
... ... @@ -161,24 +167,23 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
161 167 $rootScope.AuthenticateUser = function (userInfo)
162 168 {
163 169  
164   - alert("sdfsdf" + $rootScope.isLoginAvilableModel);
  170 +
165 171 if (navigator.cookieEnabled) {
166   -
167 172 $rootScope.errorMessage = "";
168   - if (userInfo.username == "" || userInfo.username == null || userInfo.password == "" || userInfo.password == null) {
  173 + if (userInfo.username == "" || userInfo.username == null || userInfo.username == undefined || userInfo.password == "" || userInfo.password == null || userInfo.password == undefined) {
169 174  
170 175 // alert(LoginMessageConstants.USER_CREDENTIALS_MISSING);
171 176 $rootScope.errorMessage = LoginMessageConstants.USER_CREDENTIALS_MISSING;
172 177 $("#messageModal").modal('show');
173 178 }
174 179 else {
175   -
  180 +
  181 +
176 182 AuthenticationService.authenticateUser(userInfo)
177 183 .then(
178 184  
179 185 function (result) {
180   -
181   -
  186 +
182 187 if (result == LoginConstants.USER_NOT_FOUND) {
183 188 $rootScope.isVisibleLogin = true;
184 189 // alert(LoginMessageConstants.USER_OR_PASSWORD_INCORRECT);
... ... @@ -186,6 +191,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
186 191 $("#messageModal").modal('show');
187 192 }
188 193 else {
  194 +
189 195 if (typeof result.LoginId != undefined || result.LoginId != "" || result.LoginId != null) {
190 196  
191 197 if ($("#messageModal").length > 0) {
... ... @@ -246,36 +252,53 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
246 252 $("#messageModal").modal('show');
247 253 }
248 254 else {
249   - debugger;
250   - //if (result.UserType == UserTypeConstants.SUPER_ADMIN && result.IsActive) { //(!result.IsSubscriptionExpired) &&
251   - if (result.LicenseId == 0 && result.IsActive) {
252   - $rootScope.userData = result;
253   - $rootScope.userModules = result.Modules;
254   - $rootScope.isVisibleLogin = false;
  255 +
  256 + //LicenseId would be zero for admin that is why we set the haveRoleAdmin = true
  257 + if (result.LicenseId == 0 && result.IsActive)
  258 + {
255 259 $rootScope.haveRoleAdmin = true;
256   - localStorage.setItem('loggedInUserDetails', JSON.stringify(result));
257   - alert("first" + $rootScope.isLoginAvilableModel);
258   - if (($rootScope.isLoginAvilableModel == true) && ($rootScope.refreshcheck == null))
  260 +
  261 + $rootScope.userData = result;
  262 + $rootScope.userModules = result.Modules;
  263 +
  264 + if ($scope.currentUserDetails == null || $scope.currentUserDetails == undefined || $scope.currentUserDetails == "") {
  265 + localStorage.setItem('loggedInUserDetails', JSON.stringify(result));
  266 + }
  267 +
  268 + if (isCommingSoonModel == true)
259 269 {
260   -
261   - ShowAssignedModulesPopup(result.Modules);
262   - localStorage.setItem('isLoginAvilableModel',false);
  270 +
  271 + ShowAssignedModulesPopup(result.Modules);
  272 + $rootScope.isVisibleLogin = false;
  273 + localStorage.setItem('isCommingSoonModel', false);
263 274 }
264   -
  275 +
  276 +
265 277 $location.path('/');
266 278  
267 279 }
268 280 else {
269   - if (result.LicenseInfo != null && result.LicenseInfo.IsTermAccepted) {
  281 + if (result.LicenseInfo != null && result.LicenseInfo.IsTermAccepted)
  282 + {
270 283 $rootScope.userData = result;
271 284 $rootScope.userModules = result.Modules;
272   - $rootScope.isVisibleLogin = false;
  285 +
  286 + //set haveRoleAdmin = false because LicenseInfo is not null
273 287 $rootScope.haveRoleAdmin = false;
274   - localStorage.setItem('loggedInUserDetails', JSON.stringify(result));
275   - if (($rootScope.isLoginAvilableModel) && ($rootScope.refreshcheck == null)) {
  288 +
  289 + if ($scope.currentUserDetails == null || $scope.currentUserDetails == undefined || $scope.currentUserDetails == "") {
  290 +
  291 + localStorage.setItem('loggedInUserDetails', JSON.stringify(result));
  292 + }
  293 +
  294 + if (isCommingSoonModel == true) {
  295 +
276 296 ShowAssignedModulesPopup(result.Modules);
277   - localStorage.setItem('isLoginAvilableModel', false);
  297 + $rootScope.isVisibleLogin = false;
  298 + localStorage.setItem('isCommingSoonModel', false);
278 299 }
  300 +
  301 +
279 302 $location.path('/');
280 303  
281 304 }
... ... @@ -407,33 +430,33 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
407 430 $rootScope.isVisibleLogin = true;
408 431 }
409 432  
410   - function getUserDetails() { //Retain logged in user details
411   - var currentUserDetails = $rootScope.getLocalStorageValue('loggedInUserDetails');
412   - $rootScope.isLoginAvilableModel = $rootScope.getLocalStorageValue('isLoginAvilableModel');
413   - if (currentUserDetails) {
  433 + function AuthenticateAlreadyLoggedInUser()
  434 + {
  435 +
  436 + isCommingSoonModel = $rootScope.getLocalStorageValue('isCommingSoonModel');
  437 +
414 438 try {
415   - var userInfo = JSON.parse(currentUserDetails);
  439 + var userInfo = JSON.parse($scope.currentUserDetails);
416 440  
417 441 if (userInfo.LoginId != undefined || userInfo.LoginId != "" || userInfo.LoginId != null) {
418 442  
419   - if (userInfo.UserType == UserTypeConstants.SUPER_ADMIN && userInfo.IsActive) { //(!result.IsSubscriptionExpired) &&
420   -
421   - $rootScope.userData = userInfo;
422   -
  443 + if (userInfo.UserType == UserTypeConstants.SUPER_ADMIN && userInfo.IsActive) {
  444 +
  445 + //0
  446 + $rootScope.userData = userInfo;
423 447 $rootScope.userModules = userInfo.Modules;
  448 +
  449 + //1.
424 450 userInfo["username"] = userInfo.LoginId;
425 451 userInfo["password"] = userInfo.Password;
426 452  
  453 + //2.
427 454 $rootScope.AuthenticateUser(userInfo);
428   - // $rootScope.isVisibleLogin = false;
  455 +
429 456 $rootScope.haveRoleAdmin = true;
430 457  
431 458 if ($rootScope.refreshcheck == null) {
432   - //setTimeout(function () {
433   -
434   - // $('#dvUserModulesInfo').modal('hide')
435   -
436   - //}, 400);
  459 +
437 460 if ($location.path() == "/lab-exercises-detail") {
438 461  
439 462 $location.url('/');
... ... @@ -442,7 +465,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
442 465  
443 466 $location.path('/');
444 467 }
445   -
  468 + $rootScope.isVisibleLogin = false;
446 469 }
447 470  
448 471 }
... ... @@ -451,11 +474,12 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
451 474 {
452 475 $rootScope.haveRoleAdmin = false;
453 476  
454   - if (userInfo.LicenseInfo.IsTermAccepted) {
  477 + if (userInfo.LicenseInfo.IsTermAccepted)
  478 + {
455 479 $rootScope.userData = userInfo;
456 480 $rootScope.userModules = userInfo.Modules;
457 481 $rootScope.isVisibleLogin = false;
458   - //$rootScope.haveRoleAdmin = true;
  482 +
459 483  
460 484 if ($rootScope.refreshcheck == null) {
461 485 $location.path('/');
... ... @@ -479,7 +503,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic
479 503 catch (e) {
480 504 localStorage.removeItem('loggedInUserDetails');
481 505 }
482   - }
  506 +
483 507 }
484 508  
485 509 $rootScope.SendMailToUser = function (userInfo, isMailForForgotPassword) {
... ...