Showing
1 changed file
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,6 +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 | + var isCommingSoonModel = true; | |
46 | + | |
45 | 47 | $rootScope.isCloseSettingClicked = false; |
46 | 48 | |
47 | 49 | |
... | ... | @@ -140,9 +142,15 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
140 | 142 | $rootScope.isVisibleResetPass = true; |
141 | 143 | } |
142 | 144 | else { |
143 | - $rootScope.isVisibleLogin = true; | |
144 | - $rootScope.isVisibleResetPass = false; | |
145 | - 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 | + } | |
146 | 154 | } |
147 | 155 | } |
148 | 156 | |
... | ... | @@ -158,21 +166,24 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
158 | 166 | |
159 | 167 | $rootScope.AuthenticateUser = function (userInfo) |
160 | 168 | { |
169 | + | |
170 | + | |
161 | 171 | if (navigator.cookieEnabled) { |
162 | - | |
163 | 172 | $rootScope.errorMessage = ""; |
164 | - 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) { | |
165 | 174 | |
166 | 175 | // alert(LoginMessageConstants.USER_CREDENTIALS_MISSING); |
167 | 176 | $rootScope.errorMessage = LoginMessageConstants.USER_CREDENTIALS_MISSING; |
168 | 177 | $("#messageModal").modal('show'); |
169 | 178 | } |
170 | 179 | else { |
171 | - | |
180 | + | |
181 | + | |
172 | 182 | AuthenticationService.authenticateUser(userInfo) |
173 | 183 | .then( |
174 | 184 | |
175 | 185 | function (result) { |
186 | + | |
176 | 187 | if (result == LoginConstants.USER_NOT_FOUND) { |
177 | 188 | $rootScope.isVisibleLogin = true; |
178 | 189 | // alert(LoginMessageConstants.USER_OR_PASSWORD_INCORRECT); |
... | ... | @@ -180,6 +191,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
180 | 191 | $("#messageModal").modal('show'); |
181 | 192 | } |
182 | 193 | else { |
194 | + | |
183 | 195 | if (typeof result.LoginId != undefined || result.LoginId != "" || result.LoginId != null) { |
184 | 196 | |
185 | 197 | if ($("#messageModal").length > 0) { |
... | ... | @@ -241,25 +253,52 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
241 | 253 | } |
242 | 254 | else { |
243 | 255 | |
244 | - //if (result.UserType == UserTypeConstants.SUPER_ADMIN && result.IsActive) { //(!result.IsSubscriptionExpired) && | |
245 | - if (result.LicenseId == 0 && result.IsActive) { | |
246 | - $rootScope.userData = result; | |
247 | - $rootScope.userModules = result.Modules; | |
248 | - $rootScope.isVisibleLogin = false; | |
256 | + //LicenseId would be zero for admin that is why we set the haveRoleAdmin = true | |
257 | + if (result.LicenseId == 0 && result.IsActive) | |
258 | + { | |
249 | 259 | $rootScope.haveRoleAdmin = true; |
250 | - localStorage.setItem('loggedInUserDetails', JSON.stringify(result)); | |
251 | - ShowAssignedModulesPopup(result.Modules); | |
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) | |
269 | + { | |
270 | + | |
271 | + ShowAssignedModulesPopup(result.Modules); | |
272 | + $rootScope.isVisibleLogin = false; | |
273 | + localStorage.setItem('isCommingSoonModel', false); | |
274 | + } | |
275 | + | |
276 | + | |
252 | 277 | $location.path('/'); |
253 | 278 | |
254 | 279 | } |
255 | 280 | else { |
256 | - if (result.LicenseInfo != null && result.LicenseInfo.IsTermAccepted) { | |
281 | + if (result.LicenseInfo != null && result.LicenseInfo.IsTermAccepted) | |
282 | + { | |
257 | 283 | $rootScope.userData = result; |
258 | 284 | $rootScope.userModules = result.Modules; |
259 | - $rootScope.isVisibleLogin = false; | |
285 | + | |
286 | + //set haveRoleAdmin = false because LicenseInfo is not null | |
260 | 287 | $rootScope.haveRoleAdmin = false; |
261 | - localStorage.setItem('loggedInUserDetails', JSON.stringify(result)); | |
262 | - ShowAssignedModulesPopup(result.Modules); | |
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 | + | |
296 | + ShowAssignedModulesPopup(result.Modules); | |
297 | + $rootScope.isVisibleLogin = false; | |
298 | + localStorage.setItem('isCommingSoonModel', false); | |
299 | + } | |
300 | + | |
301 | + | |
263 | 302 | $location.path('/'); |
264 | 303 | |
265 | 304 | } |
... | ... | @@ -391,25 +430,33 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
391 | 430 | $rootScope.isVisibleLogin = true; |
392 | 431 | } |
393 | 432 | |
394 | - function getUserDetails() { //Retain logged in user details | |
395 | - var currentUserDetails = $rootScope.getLocalStorageValue('loggedInUserDetails'); | |
396 | - if (currentUserDetails) { | |
433 | + function AuthenticateAlreadyLoggedInUser() | |
434 | + { | |
435 | + | |
436 | + isCommingSoonModel = $rootScope.getLocalStorageValue('isCommingSoonModel'); | |
437 | + | |
397 | 438 | try { |
398 | - var userInfo = JSON.parse(currentUserDetails); | |
439 | + var userInfo = JSON.parse($scope.currentUserDetails); | |
399 | 440 | |
400 | 441 | if (userInfo.LoginId != undefined || userInfo.LoginId != "" || userInfo.LoginId != null) { |
401 | 442 | |
402 | - if (userInfo.UserType == UserTypeConstants.SUPER_ADMIN && userInfo.IsActive) { //(!result.IsSubscriptionExpired) && | |
403 | - | |
404 | - $rootScope.userData = userInfo; | |
405 | - | |
443 | + if (userInfo.UserType == UserTypeConstants.SUPER_ADMIN && userInfo.IsActive) { | |
444 | + | |
445 | + //0 | |
446 | + $rootScope.userData = userInfo; | |
406 | 447 | $rootScope.userModules = userInfo.Modules; |
407 | - | |
408 | - $rootScope.isVisibleLogin = false; | |
448 | + | |
449 | + //1. | |
450 | + userInfo["username"] = userInfo.LoginId; | |
451 | + userInfo["password"] = userInfo.Password; | |
452 | + | |
453 | + //2. | |
454 | + $rootScope.AuthenticateUser(userInfo); | |
455 | + | |
409 | 456 | $rootScope.haveRoleAdmin = true; |
410 | 457 | |
411 | 458 | if ($rootScope.refreshcheck == null) { |
412 | - | |
459 | + | |
413 | 460 | if ($location.path() == "/lab-exercises-detail") { |
414 | 461 | |
415 | 462 | $location.url('/'); |
... | ... | @@ -418,7 +465,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
418 | 465 | |
419 | 466 | $location.path('/'); |
420 | 467 | } |
421 | - | |
468 | + $rootScope.isVisibleLogin = false; | |
422 | 469 | } |
423 | 470 | |
424 | 471 | } |
... | ... | @@ -427,11 +474,12 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
427 | 474 | { |
428 | 475 | $rootScope.haveRoleAdmin = false; |
429 | 476 | |
430 | - if (userInfo.LicenseInfo.IsTermAccepted) { | |
477 | + if (userInfo.LicenseInfo.IsTermAccepted) | |
478 | + { | |
431 | 479 | $rootScope.userData = userInfo; |
432 | 480 | $rootScope.userModules = userInfo.Modules; |
433 | 481 | $rootScope.isVisibleLogin = false; |
434 | - //$rootScope.haveRoleAdmin = true; | |
482 | + | |
435 | 483 | |
436 | 484 | if ($rootScope.refreshcheck == null) { |
437 | 485 | $location.path('/'); |
... | ... | @@ -455,7 +503,7 @@ function ($rootScope, Modules, $log, $location, $timeout, DataService, Authentic |
455 | 503 | catch (e) { |
456 | 504 | localStorage.removeItem('loggedInUserDetails'); |
457 | 505 | } |
458 | - } | |
506 | + | |
459 | 507 | } |
460 | 508 | |
461 | 509 | $rootScope.SendMailToUser = function (userInfo, isMailForForgotPassword) { | ... | ... |