1/* 2 This file overrides existing wc.render.RefreshController.refresh function and wc.service.Service.invoke function. 3 The 2 functions are copied as-is from dojo folder with code modification listed below. 4 defect addressed: 5 - COEU-404: handle session timeout scenario. When it is ajax area refresh/wc ajax action call, if it is session timeout error, capture current page 6 location and pass to log on page so it'll redirect shopper back to last visited page 7 8 ** Please clearly mark the modified code and indicate defect number in the comment ** 9*/ 10dojo.require("wc.render.RefreshController"); 11dojo.extend(wc.render.RefreshController, { 12 refresh: function (widget, parameters) { 13 // summary: Invoke an Ajax style request to refresh the specified widget. 14 // description: This function invokes an Ajax style request to the refresh controller's 15 // refresh URL with the specified parameters. This function is normally called by 16 // the "refresh" function of "wc.widget.RefreshArea". 17 // widget: wc.widget.RefreshArea 18 // The refresh area widget being refreshed. 19 // parameters: Object 20 // The name/value pair parameters that are to be sent with this URL. 21 22 function isParameterExcluded(url, parameterName){ 23 try{ 24 if(typeof URLConfig === 'object'){ 25 if (typeof URLConfig.excludedURLPatterns === 'object'){ 26 for ( var urlPatternName in URLConfig.excludedURLPatterns){ 27 var exclusionConfig = URLConfig.excludedURLPatterns[urlPatternName]; 28 var urlPattern = urlPatternName; 29 if(typeof exclusionConfig === 'object'){ 30 if(exclusionConfig.urlPattern){ 31 urlPattern = exclusionConfig.urlPattern; 32 } 33 console.debug("URL pattern to match : " + urlPattern); 34 urlPattern = new RegExp(urlPattern); 35 36 if(url.match(urlPattern)){ 37 var excludedParametersArray = exclusionConfig.excludedParameters; 38 for(var excludedParameter in excludedParametersArray){ 39 if(parametername == excludedParameter){ 40 return true; 41 } 42 } 43 } 44 } 45 } 46 } else { 47 console.debug("The parameter " + parameterName + " is not excluded"); 48 } 49 } else { 50 console.debug("No URLConfig defined.") 51 } 52 } catch (err){ 53 console.debug("An error occured while trying to exclude " + err); 54 } 55 return false; 56 } 57 58 var formNode = null; 59 if(this.formId) { 60 formNode = document.getElementById(this.formId); 61 } 62 63 if (parameters) { 64 if (!parameters.requesttype) { 65 parameters.requesttype = 'ajax'; 66 } 67 } else { 68 parameters = []; 69 parameters.requesttype = 'ajax'; 70 } 71 //Remove all instances of "amp;" in the URL which was added on the JSP by c:out 72 this.url = this.url.replace(/amp;/g, ""); 73 74 var mergedParameters = parameters; 75 if(typeof wcCommonRequestParameters === 'object'){ 76 console.debug("Common parameters = " + dojo.toJson(wcCommonRequestParameters)); 77 mergedParameters = {}; 78 dojo.mixin(mergedParameters, parameters); 79 80 for(var parameterName in wcCommonRequestParameters){ 81 if(!isParameterExcluded(this.url, parameterName)){ 82 mergedParameters[parameterName] = wcCommonRequestParameters[parameterName]; 83 } else { 84 console.debug("parameter " + parameterName + " is excluded"); 85 } 86 } 87 console.debug("After merging = " + dojo.toJson(mergedParameters)); 88 } 89 90 dojo.publish("ajaxRequestInitiated"); 91 92 dojo.xhrPost({ 93 url: this.url, 94 mimetype: this.mimetype, 95 form: formNode, 96 content: mergedParameters, 97 load: function(data) { 98 function getIds(idType, controllerURL) { 99 var myId = ""; 100 if (mergedParameters && mergedParameters[idType]) { 101 myId = mergedParameters[idType]; 102 } 103 if (myId == "" && formNode != null && formNode[idType]) { 104 myId = formNode[idType]; 105 if (formNode[idType].value != null) { 106 myId = formNode[idType].value; 107 } 108 } 109 if (myId == "" && controllerURL) { 110 var temp = controllerURL; 111 if (temp.indexOf(idType) != -1) { 112 temp = temp.substring(temp.indexOf(idType)); 113 var tokens = temp.split("&"); 114 var tokens2 = tokens[0].split("="); 115 myId = tokens2[1]; 116 } 117 } 118 return myId; 119 } 120 function parseJsonCommentFiltered(str){ 121 str = str.replace('\/\*', ''); 122 str = str.replace('\*\/', ''); 123 var json = eval('(' + str + ')'); 124 return json; 125 } 126 127 // determine storeId, catalogId and langId to use in our redirect url 128 var storeId = getIds("storeId", this.url); 129 var catalogId = getIds("catalogId", this.url); 130 var langId = getIds("langId", this.url); 131 132 let errorCodeBegin = data.indexOf('errorCode'); 133 var errorCodeEnd = data.indexOf(',', errorCodeBegin); 134 var errorCodeString = data.substring(errorCodeBegin, errorCodeEnd); 135 //Modifed the code as fusion response returns errorcode always "errorcode":"SUC_000" OR "errorcode":"ERR_915". So added a condition check to ignore if error code starts with SUC_000 136 137 if (errorCodeBegin != -1 && !errorCodeString.includes("SUC_") && !errorCodeString.includes("ERR_") && !errorCodeString.includes("WAR_")) { 138 // get error code 139 140 console.debug('error condition encountered - error code: ' + errorCodeString); 141 // error code: ERR_DIDNT_LOGON 142 // This error code is returned in the scenario where logon is required and user is not logged on 143 if (errorCodeString.indexOf('2550') != -1) {
144 console.debug('error type: ERR_DIDNT_LOGON - the customer did not log on to the system.'); 145 console.debug("redirecting to URL: " + "AjaxLogonForm?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId + '&myAcctMain=1'); 146 document.location.href = "AjaxLogonForm?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId + '&myAcctMain=1'; 147 } 148 // error code: ERR_SESSION_TIMEOUT 149 // This error code is returned in the scenario where user's logon session has timed out 150 else if (errorCodeString.indexOf('2510') != -1) { 151 //redirect to a full page for sign in 152 console.debug('error type: ERR_SESSION_TIMEOUT - use session has timed out'); 153 var serviceResponse = parseJsonCommentFiltered(data); 154 155 // COEU-404 - capture current page location and pass to timeout view 156 var currentPage = document.location.href; 157 currentPage = currentPage.replace('?', '%3F'); 158 currentPage = currentPage.replace(/&/g, '%26'); 159 currentPage = currentPage.replace(/&/g, '%26'); 160 currentPage = currentPage.replace(/=/g, '%3D'); 161 var timeoutURL = "Logoff?"; 162 if (serviceResponse.exceptionData.isBecomeUser == 'true') { 163 timeoutURL = "RestoreOriginalUserSetInSession?URL=Logoff&"; 164 } 165 if (serviceResponse.exceptionData.rememberMe == 'true'){ 166 var myURL = timeoutURL + 'rememberMe=true&storeId=' + storeId + "&catalogId=" + catalogId + "&langId=" + langId + "&nextUrl=" + currentPage; 167 console.debug('try to logoff, get URL='+myURL); 168 dojo.xhrGet({ 169 url: myURL, 170 handleAs: "text", 171 content: mergedParameters, 172 service: this, 173 load: function(serviceResponse, ioArgs) { 174 console.debug('User logged off. Reload current page to avoid data inconsistence...'); 175 document.location.reload(); 176 }, 177 error: function(errObj,ioArgs) { 178 // failed to logoff, directly go to relogon form; 179 // this should not happen, just in case. 180 document.location.href = 'ReLogonFormView?rememberMe=true&storeId='+storeId+"&nextUrl="+currentPage; 181 } 182 }); 183 } 184 else { 185 console.debug('redirecting to URL: ' + timeoutURL + 'URL=ReLogonFormView&storeId=' + storeId); 186 document.location.href = timeoutURL + 'URL=ReLogonFormView&storeId=' + storeId + "&nextUrl=" + currentPage; 187 } 188 189 // error code: ERR_PROHIBITED_CHAR 190 // This error code is returned in the scenario where user has entered prohibited character(s) in the request 191 } else if (errorCodeString.indexOf('2520') != -1) { 192 console.debug('error type: ERR_PROHIBITED_CHAR - detected prohibited characters in request'); 193 console.debug("redirecting to URL: " + "ProhibitedCharacterErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId); 194 document.location.href = "ProhibitedCharacterErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId; 195 196 // error code: ERR_CSRF 197 // This error code is returned in the scenario where a cross-site request forgery attempt was caught 198 } else if (errorCodeString.indexOf('2540') != -1) { 199 console.debug('error type: ERR_CSRF - cross site request forgery attempt was detected'); 200 console.debug("redirecting to URL: " + "CrossSiteRequestForgeryErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId); 201 document.location.href = "CrossSiteRequestForgeryErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId; 202 203 // error code: _ERR_INVALID_COOKIE 204 // This error code is returned in the scenario where a cookie error occurs 205 } else if (errorCodeString.indexOf('CMN1039E') != -1) { 206 console.debug('error type: _ERR_INVALID_COOKIE - cookie error was detected'); 207 console.debug("redirecting to URL: " + "CookieErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId); 208 document.location.href = "CookieErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId; 209 } 210 211 } else { 212 var controller = widget.controller; 213 214 console.debug("RefreshController.refresh - calling refreshHandler for " + widget); 215 controller.refreshHandler(widget, data); 216 217 if (controller.postRefreshHandler != null) { 218 console.debug("RefreshController.refresh - calling postRefreshHandler for " + widget); 219 controller.postRefreshHandler(widget); 220 } 221 } 222 dojo.publish("ajaxRequestCompleted"); 223 widget.updateLiveRegion(); 224 }, 225 error: function(error) { 226 // handle error here - what do you do when a refresh doesn't happen? 227 var messages = dojo.i18n.getLocalization("wc", "common"); 228 console.debug("Warning: communication error while updating the refresh area"); // Communication error. 229 dojo.publish("ajaxRequestCompleted"); 230 } 231 }); 232 } 233}); 234 235dojo.require("wc.service.common"); 236dojo.extend(wc.service.Service, { 237 invoke: function (parameters) { 238 // summary: Invoke the service. 239 // description: This function will asynchronously invoke the configured service URL with 240 // the specified parameters. If this service was configured with a form ID, then the 241 // form values will be posted to the URL. When the service completes successfully, 242 // a "modelChanged" event will be published to any listeners. If the "actionId" property 243 // has been configured, then an event with the topic name "modelChanged/actionId" will also 244 // be published. 245 246 function isParameterExcluded(url, parameterName){ 247 try{ 248 if(typeof URLConfig === 'object'){ 249 if (typeof URLConfig.excludedURLPatterns === 'object'){ 250 for ( var urlPatternName in URLConfig.excludedURLPatterns){ 251 var exclusionConfig = URLConfig.excludedURLPatterns[urlPatternName]; 252 var urlPattern = urlPatternName; 253 if(typeof exclusionConfig === 'object'){ 254 if(exclusionConfig.urlPattern){ 255 urlPattern = exclusionConfig.urlPattern; 256 } 257 console.debug("URL pattern to match : " + urlPattern); 258 urlPattern = new RegExp(urlPattern); 259 260 if(url.match(urlPattern)){ 261 var excludedParametersArray = exclusionConfig.excludedParameters; 262 for(var excludedParameter in excludedParametersArray){ 263 if(parametername == excludedParameter){ 264 return true; 265 } 266 } 267 } 268 } 269 } 270 } else { 271 console.debug("The parameter " + parameterName + " is not excluded"); 272 } 273 } else { 274 console.debug("No URLConfig defined.") 275 } 276 } catch (err){ 277 console.debug("An error occured while trying to exclude " + err); 278 } 279 return false; 280 } 281 282 function addAuthToken(url,parameters){ 283 try{ 284 if(dojo.byId("csrf_authToken") != null){ 285 parameters["authToken"] = dojo.byId("csrf_authToken").value; 286 } else { 287 console.debug("auth token is missing from the HTML DOM"); 288 } 289 return true; 290 } catch (err){ 291 console.debug("An error occured while trying to add authToken to request " + err); 292 } 293 return false; 294 } 295
296 var valid = true; 297 298 var formNode = null; 299 if (this.formId) { 300 formNode = document.getElementById(this.formId); 301 } 302 303 if (formNode) { 304 valid = this.validateForm(formNode); 305 } 306 if (valid) { 307 valid = this.validateParameters(parameters); 308 } 309 if (parameters) { 310 if (!parameters.requesttype) { 311 parameters.requesttype = 'ajax'; 312 } 313 } else { 314 parameters = []; 315 parameters.requesttype = 'ajax'; 316 } 317 addAuthToken(this.url,parameters); 318 319 var mergedParameters = parameters; 320 if(typeof wcCommonRequestParameters === 'object'){ 321 console.debug("Common parameters = " + dojo.toJson(wcCommonRequestParameters)); 322 mergedParameters = {}; 323 dojo.mixin(mergedParameters, parameters); 324 325 for(var parameterName in wcCommonRequestParameters){ 326 if(!isParameterExcluded(this.url, parameterName)){ 327 mergedParameters[parameterName] = wcCommonRequestParameters[parameterName]; 328 } else { 329 console.debug("parameter " + parameterName + " is excluded"); 330 } 331 } 332 console.debug("After merging = " + dojo.toJson(mergedParameters)); 333 } 334 335 console.debug("service formId = " + this.formId); 336 if (valid) { 337 dojo.publish("ajaxRequestInitiated"); 338 dojo.xhrPost({ 339 url: this.url, 340 handleAs: "json-comment-filtered", 341 form: formNode, 342 content: mergedParameters, 343 service: this, 344 load: function(serviceResponse, ioArgs) { 345 function getIds(idType, controllerURL) { 346 var myId = ""; 347 if (mergedParameters && mergedParameters[idType]) { 348 myId = mergedParameters[idType]; 349 } 350 if (myId == "" && formNode != null && formNode[idType]) { 351 myId = formNode[idType]; 352 if (formNode[idType].value != null) { 353 myId = formNode[idType].value; 354 } 355 } 356 if (myId == "" && controllerURL) { 357 var temp = controllerURL; 358 if (temp.indexOf(idType) != -1) { 359 temp = temp.substring(temp.indexOf(idType)); 360 var tokens = temp.split("&"); 361 var tokens2 = tokens[0].split("="); 362 myId = tokens2[1]; 363 } 364 } 365 return myId; 366 } 367 368 var service = ioArgs.args.service; 369 serviceResponse.serviceId = service.id; 370 serviceResponse.actionId = service.actionId; 371 console.debug("Service response action id : " + serviceResponse.actionId); 372 for (var prop in serviceResponse) { 373 console.debug(" " + prop + "=" + serviceResponse[prop]); 374 } 375 if (service.successTest(serviceResponse)) { 376 service.successHandler(serviceResponse, ioArgs); 377 378 console.debug("success: publishing modelChanged event") 379 dojo.publish("modelChanged", [serviceResponse]); 380 381 if (service.actionId) { 382 console.debug("success: publishing modelChanged/" + service.actionId + " event"); 383 dojo.publish("modelChanged/" + service.actionId, [serviceResponse]); 384 if(service.actionId === 'OrderShippingInfoUpdate') { 385 cursor_clear(); 386 } 387 } 388 } 389 else { 390 // determine storeId, catalogId and langId to use in our redirect url 391 var storeId = getIds("storeId", this.url); 392 var catalogId = getIds("catalogId", this.url); 393 var langId = getIds("langId", this.url); 394 395 console.debug('error condition encountered - error code: ' + serviceResponse.errorCode); 396 397 // error code: ERR_USER_NOT_LOGGED_ON 398 // This error code is returned in the scenario where logon is required and user is not logged on 399 if (serviceResponse.errorCode == '2500') { 400 var myURL = serviceResponse.originatingCommand; 401 myURL = myURL.replace('?', '%3F'); 402 myURL = myURL.replace(/&/g, '%26'); 403 myURL = myURL.replace(/&/g, '%26'); 404 myURL = myURL.replace(/=/g, '%3D'); 405 406 myURL = 'LogonForm?nextUrl=' + myURL + "&storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId + '&myAcctMain=1';
407 console.debug('error type: ERR_USER_NOT_LOGGED_ON - only registered user can invoke the command'); 408 console.debug('redirecting to URL: ' + myURL); 409 document.location.href = myURL; 410 // error code: ERR_DIDNT_LOGON 411 // This error code is returned in the scenario where logon is required and user is not logged on 412 } else if (serviceResponse.errorCode == '2550') { 413 var myURL = serviceResponse.originatingCommand; 414 myURL = myURL.replace('?', '%3F'); 415 myURL = myURL.replace(/&/g, '%26'); 416 myURL = myURL.replace(/&/g, '%26'); 417 myURL = myURL.replace(/=/g, '%3D'); 418 myURL = 'AjaxLogonForm?nextUrl=' + myURL + "&storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId + '&myAcctMain=1'; 419 console.debug('error type: ERR_DIDNT_LOGON - the customer did not log on to the system.'); 420 console.debug('redirecting to URL: ' + myURL); 421 document.location.href = myURL; 422 // error code: ERR_PASSWORD_REREQUEST 423 // This error code is returned in the scenario where password is required to proceed 424 } else if (serviceResponse.errorCode == '2530') { 425 var myURL = serviceResponse.originatingCommand; 426 myURL = myURL.replace('?', '%3F'); 427 myURL = myURL.replace(/&/g, '%26'); 428 myURL = myURL.replace(/&/g, '%26'); 429 myURL = myURL.replace(/=/g, '%3D'); 430 myURL = 'PasswordReEnterErrorView?nextUrl=' + myURL + "&storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId; 431 console.debug('error type: ERR_PASSWORD_REREQUEST - password is required'); 432 console.debug('redirecting to URL: ' + myURL); 433 document.location.href = myURL; 434 435 // error code: ERR_SESSION_TIMEOUT 436 // This error code is returned in the scenario where user's logon session has timed out 437 } else if (serviceResponse.errorCode == '2510') { 438 //redirect to a full page for sign in 439 console.debug('error type: ERR_SESSION_TIMEOUT - use session has timed out'); 440 441 // COEU-404 - capture current page location and pass to timeout view 442 var currentPage = document.location.href; 443 currentPage = currentPage.replace('?', '%3F'); 444 currentPage = currentPage.replace(/&/g, '%26'); 445 currentPage = currentPage.replace(/&/g, '%26'); 446 currentPage = currentPage.replace(/=/g, '%3D'); 447 448 var timeoutURL = "Logoff?"; 449 if (serviceResponse.exceptionData.isBecomeUser == 'true') { 450 timeoutURL = "RestoreOriginalUserSetInSession?URL=Logoff&"; 451 } 452 if (serviceResponse.exceptionData.rememberMe == 'true'){ 453 var myURL = timeoutURL + 'rememberMe=true&storeId=' + storeId + "&catalogId=" + catalogId + "&langId=" + langId + "&nextUrl=" + currentPage; 454 console.debug('try to logoff, get URL='+myURL); 455 dojo.xhrGet({ 456 url: myURL, 457 handleAs: "text", 458 content: mergedParameters, 459 service: this, 460 load: function(serviceResponse, ioArgs) { 461 console.debug('User logged off. Reload current page to avoid data inconsistence...'); 462 document.location.reload(); 463 }, 464 error: function(errObj,ioArgs) { 465 // failed to logoff, directly go to relogon form; 466 // this should not happen, just in case. 467 document.location.href = 'ReLogonFormView?rememberMe=true&storeId='+storeId+"&nextUrl="+currentPage; 468 } 469 });
470 } 471 else { 472 console.debug('redirecting to URL: ' + timeoutURL + 'URL=ReLogonFormView&storeId=' + storeId); 473 document.location.href = timeoutURL + 'URL=ReLogonFormView&storeId=' + storeId + "&nextUrl=" + currentPage; 474 } 475 476 // error code: ERR_PROHIBITED_CHAR 477 // This error code is returned in the scenario where user has entered prohibited character(s) in the request 478 } else if (serviceResponse.errorCode == '2520') { 479 console.debug('error type: ERR_PROHIBITED_CHAR - detected prohibited characters in request'); 480 console.debug("redirecting to URL: " + "ProhibitedCharacterErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId); 481 document.location.href = "ProhibitedCharacterErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId; 482 483 // error code: ERR_CSRF 484 // This error code is returned in the scenario where a cross-site request forgery attempt was caught 485 } else if (serviceResponse.errorCode == '2540') { 486 console.debug('error type: ERR_CSRF - cross site request forgery attempt was detected'); 487 console.debug("redirecting to URL: " + "CrossSiteRequestForgeryErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId); 488 document.location.href = "CrossSiteRequestForgeryErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId; 489 490 // error code: _ERR_INVALID_COOKIE 491 // This error code is returned in the scenario where a cookie error occurs 492 } else if (serviceResponse.errorCode == 'CMN1039E') { 493 console.debug('error type: _ERR_INVALID_COOKIE - cookie error was detected'); 494 console.debug("redirecting to URL: " + "CookieErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId); 495 document.location.href = "CookieErrorView?storeId=" + storeId + "&catalogId=" + catalogId + "&langId=" + langId; 496 497 } else { 498 console.debug('calling service.failureHandler'); 499 service.failureHandler(serviceResponse, ioArgs); 500 } 501 } 502 dojo.publish("ajaxRequestCompleted"); 503 }, 504 error: function(errObj, ioArgs) { 505 var messages = dojo.i18n.getLocalization("wc", "common"); 506 console.debug("Warning: communication error while making the service call"); // Communication error. 507 dojo.publish("ajaxRequestCompleted"); 508 } 509 }); 510 } 511 } 512});
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.