1investagramsAngularApp.controller('loginPageController', 2 function ($scope, $rootScope, userApiService) { 3 4 var loginGoogleWindow; 5 6 $scope.ApplicationType = Enum.UserApplicationIntegrationType; 7 8 $scope.IsLoading = false; 9 10 $scope.ReturnUrl = ""; 11 12 $scope.loginForCheckout = false; 13 14 $scope.IsUserLoggedOn = gaAuthenticatedUserId > 0; 15 16 $scope.FbMessenger = { 17 IsAuthenticatingViaFbMessenger: false, 18 RedirectUri: "" 19 }; 20 21 $scope.Login = { 22 Source: "Login", 23 TargetFeature: null 24 }; 25 26 27 $scope.LoginRequest = { 28 Username: "", 29 Password: "", 30 DeviceId: "0000", 31 RequestComingFromType: 3, 32 DeviceName: "", 33 AppId: null, 34 IsRememberMe: true, 35 36 RedirectUri: "", 37 AccessToken: "", 38 ApplicationType: $scope.ApplicationType.Facebook 39 }; 40 41 42 $scope.DisplayMessage = { 43 IsSuccess: true, 44 Message: "" 45 }; 46 47 $scope.authenticateUser = function () { 48 49 if (!$scope.LoginRequest.Username) { 50 showErrorResponse("Email address is required. Please type your email address again."); 51 return; 52 } 53 54 55 if (!$scope.IsLoading) { 56 57 $scope.IsLoading = true; 58 59 $scope.initDeviceId(); 60 61 $scope.setErrorMessage(""); 62 63 if (!$scope.loginForCheckout) { 64 $scope.broadcastTrackActionSteps("DONE"); 65 } 66 67 showHeaderLoader(); 68 69 userApiService.authenticateUser($scope.LoginRequest).then(function (result) { 70 71 if ($scope.loginForCheckout) { 72 $rootScope.$broadcast("setUserJourneyDataForCheckoutPage"); 73 } 74 else { 75 $rootScope.$broadcast("setUserJourneyDataForPostLogin"); 76 } 77 78 $scope.postLogin(result.data); 79 80 }, function (error) { 81 //$scope.setErrorMessage(generateErrorResponse(error)); 82 $scope.IsLoading = false; 83 hideHeaderLoader(); 84 showErrorResponse(error); 85 $scope.broadcastTrackActionSteps("Show Incorrect Password Error Message"); 86 $scope.LoginRequest.Password = ""; 87 }); 88 89 } 90 91 }; 92 93 94 95 $scope.authenticateUserForApiViaExternalApplication = function () { 96 if (!$scope.IsLoading) { 97 98 $scope.IsLoading = true; 99 100 $scope.initDeviceId(); 101 102 //$scope.setErrorMessage(""); 103 104 showHeaderLoader(); 105 106 userApiService.authenticateUserForApiViaExternalApplication($scope.LoginRequest).then(function (result) { 107 108 $scope.postLogin(result.data); 109 110 }, function (error) { 111 $scope.IsLoading = false; 112 hideHeaderLoader(); 113 showErrorResponse(error); 114 115 $scope.LoginRequest.AccessToken = ""; 116 }); 117 118 } 119 120 }; 121 122 123 $scope.loginViaFacebook = function () { 124 125 FB.login(function (response) { 126 127 if (response.status === 'connected') { 128 129 $scope.LoginRequest.AccessToken = response.authResponse.accessToken; 130 $scope.LoginRequest.ApplicationType = $scope.ApplicationType.Facebook; 131 132 $scope.authenticateUserForApiViaExternalApplication(); 133 } 134 else { 135 136 showErrorResponse("Unable to connect. Please try again."); 137 } 138 139 }, { 140 scope: 'email' 141 }); 142 143 }; 144 145 $scope.loginViaGoogle = function () { 146 if (!loginGoogleWindow || loginGoogleWindow.closed) { 147 loginGoogleWindow = createWindowOpen(PageUrlConstant.LoginGoogle.Url); 148 149 window.loginGoogleFinish = function (accessCode) { 150 loginGoogleWindow.close(); 151 152 if (accessCode) { 153 $scope.LoginRequest.AccessToken = accessCode; 154 $scope.LoginRequest.ApplicationType = $scope.ApplicationType.Google; 155 156 $scope.authenticateUserForApiViaExternalApplication(); 157 isSuccess = true; 158 } 159 else { 160 showErrorResponse("Unable to connect. Please try again."); 161 } 162 163 loginGoogleWindow = null; 164 window.loginGoogleFinish = null; 165 } 166 } 167 else { 168 if (loginGoogleWindow) { 169 loginGoogleWindow.focus(); 170 } 171 } 172 }; 173 174 175 176 177 $scope.forgotUserPassword = function () { 178 179 if (!$scope.LoginRequest.Username) { 180 showErrorResponse("Email address is required"); 181 return; 182 } 183 184 if (!$scope.IsLoading) { 185 186 $scope.IsLoading = true; 187 //$scope.setErrorMessage(""); 188 189 showHeaderLoader(); 190 191 192 var usernameRequest = sanitizePlusSign($scope.LoginRequest.Username); 193 194 userApiService.forgotUserPassword(usernameRequest).then(function (result) { 195 196 showAlertNotificationSuccessMessage(result.data, 20000); 197 198 $scope.IsLoading = false; 199 hideHeaderLoader(); 200 201 }, function (error) { 202 $scope.IsLoading = false; 203 hideHeaderLoader(); 204 showErrorResponse(error); 205 206 }); 207 208 } 209 210 }; 211 212 213 $scope.postLogin = function (response) { 214 if (response != null) { 215 216 if ($scope.FbMessenger.IsAuthenticatingViaFbMessenger) { 217 showAlertNotificationSuccessMessage("Successfully Connected. Please wait..."); 218 219 window.location.replace($scope.FbMessenger.RedirectUri + "&authorization_code=" + response.UserInfo.UserInfo.UserId); 220 } 221 else { 222 showAlertNotificationSuccessMessage("Successfully Login. Please wait..."); 223 224 if ($scope.ReturnUrl) { 225 window.location.replace($scope.ReturnUrl); 226 } 227 else if ($scope.Login.Source == 'ITG') { 228 PageUrlConstant.ITG.ExecuteOriginalUrl(); 229 } 230 else if ($scope.Login.Source == 'Prompt') { 231 if ($scope.LoginPrompt.TargetUrl) { 232 window.location.href = $scope.LoginPrompt.TargetUrl; 233 } 234 else if ($scope.LoginPrompt.IsForceDisplay) 235 PageUrlConstant.Home.ExecuteOriginalUrlByReplace(); 236 else 237 location.reload(); 238 } 239 //else if (!response.IsDoneOnboarding) { 240 // PageUrlConstant.Onboarding.ExecuteOriginalUrlByReplace(); 241 //} 242 else { 243 PageUrlConstant.Home.ExecuteOriginalUrlByReplace(); 244 } 245 } 246 } 247 else { 248 $scope.IsLoading = false; 249 } 250 251 hideHeaderLoader(); 252 }; 253 254 255 256 $scope.broadcastConditionalTrackActionSteps = function (scenario, action, clearData) { 257 if ($scope.loginForCheckout) { 258 $scope.broadcastTrackActionStepsWithFinalUserJourneyScenario("Register Checkout", action, clearData); 259 } 260 else { 261 $scope.broadcastTrackActionStepsWithFinalUserJourneyScenario(scenario, action, clearData); 262 } 263 }; 264 265 266 $scope.broadcastTrackActionSteps = function (action, clearData) { 267 268 $rootScope.$broadcast("trackActionSteps", action, clearData); 269 }; 270 271 272 $scope.broadcastCancelTrackActionSteps = function (action) { 273 $rootScope.$broadcast("cancelTrackActionSteps", action); 274 } 275 276 $scope.broadcastTrackActionStepsWithFinalUserJourneyScenario = function (scenario, action, clearData) { 277 278 $rootScope.$broadcast("trackActionStepsAndScenario", scenario, action, clearData); 279 }; 280 281 282 $scope.$on("updateLoginTargetFeature", function (e, data) { 283 if (data) { 284 $scope.Login.TargetFeature = data; 285 } 286 }); 287 288 289 $scope.setErrorMessage = function (message) { 290 $scope.DisplayMessage.IsSuccess = false; 291 $scope.DisplayMessage.Message = message; 292 }; 293 294 $scope.setSuccessfulMessage = function (message) { 295 $scope.DisplayMessage.IsSuccess = true; 296 $scope.DisplayMessage.Message = message; 297 }; 298 299 300 $scope.initDeviceId = function () { 301 302 if ($scope.LoginRequest.DeviceId == "0000") { 303 304 $scope.LoginRequest.DeviceId = $scope.UserNav.getDeviceId();
305 306 } 307 308 }; 309 310 311 $scope.hasUserJourneyRequestForLoginPage = false; 312 313 $scope.initUserJourneyTracking = function () { 314 //process user journey if there are existing request from other page and continue here 315 var userJourneyRequest = LocalStorageCache.UserJourneyForLoginPage.Get(); 316 317 if (userJourneyRequest) { 318 $scope.hasUserJourneyRequestForLoginPage = true; 319 LocalStorageCache.UserJourneyForPrimeLandingPage.Remove(); 320 321 $rootScope.$broadcast("setUserJourneyTrackingData", userJourneyRequest); 322 323 if ($scope.loginForCheckout) { 324 325 $rootScope.$broadcast("trackActionStepsAndScenario", "Login Checkout", "INIT Login Details"); 326 } 327 else { 328 $rootScope.$broadcast("trackActionStepsAndScenario", "Login", "INIT Login Details"); 329 } 330 } 331 }; 332 333 334 window.addEventListener('beforeunload', function (e) { 335 336 if ($scope.hasUserJourneyRequestForLoginPage) { 337 //check if there are need to cancel pending user journey logs here 338 $rootScope.$broadcast("cancelTrackActionSteps"); 339 } 340 }); 341 342 343 $scope.init = function () { 344 345 $scope.ReturnUrl = getReturnUrlParameter(); 346 347 if ($scope.ReturnUrl) { 348 $scope.setErrorMessage("Please Login to Continue."); 349 350 var parts = $scope.ReturnUrl.split("/"); 351 var lastSegment = parts.filter(Boolean).pop().split("?")[0]; 352 353 354 switch (lastSegment.toLowerCase()) { 355 case "checkout": 356 case "upgrade": 357 $scope.loginForCheckout = true; 358 break; 359 } 360 } 361 362 if (getParameterByName("account_linking_token")) { 363 $scope.FbMessenger.IsAuthenticatingViaFbMessenger = true; 364 $scope.FbMessenger.RedirectUri = getParameterByName("redirect_uri"); 365 } 366 367 if ($scope.FbMessenger.IsAuthenticatingViaFbMessenger) { 368 $scope.setErrorMessage("Please login to connect your fb messenger to investagrams."); 369 } 370 else { 371 372 $scope.LoginRequest.AppId = getParameterByName("ssoAppId"); 373 374 if ($scope.LoginRequest.AppId) { 375 $scope.LoginRequest.RequestComingFromType = 2000; 376 } 377 378 379 } 380 381 $scope.LoginRequest.DeviceName = getBrowserName(); 382 383 setTimeout(function () { 384 $scope.initDeviceId(); 385 $scope.initUserJourneyTracking(); 386 }, 1000); 387 }; 388 389 390 $scope.init(); 391 392 } 393);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.