1jQuery(document).ready(function ($) { 2 // Form references 3 const loginForm = $("#wpamo-sso-login-form"); 4 const forgotUsernameForm = $("#wpamo-sso-forgot-username-form"); 5 const forgotPasswordForm = $("#wpamo-sso-forgot-password-form"); 6 7 // Login form elements 8 const usernameEl = loginForm.find('input[name="username"]'); 9 const passwordEl = loginForm.find('input[name="password"]'); 10 const wpReturnEl = document.querySelector( 11 'form#wpamo-sso-login-form input[name="wp_return"]' 12 ); 13 14 // Forgot username form elements 15 const forgotUsernameEmailEl = forgotUsernameForm.find('input[name="email"]'); 16 const forgotUsernameWpReturnEl = document.querySelector( 17 'form#wpamo-sso-forgot-username-form input[name="wp_return"]' 18 ); 19 20 // Forgot password form elements 21 const forgotPasswordEmailEl = forgotPasswordForm.find('input[name="email"]'); 22 const forgotPasswordWpReturnEl = document.querySelector( 23 'form#wpamo-sso-forgot-password-form input[name="wp_return"]' 24 ); 25 26 // Open modal when SSO link is clicked 27 $('a[href*="site_signin_wp.cfm"]').each(function () { 28 var link = $(this); 29 link.on("click", function (e) { 30 e.preventDefault(); 31 const wpReturnUrl = new URL(this.getAttribute("href")); 32 const wpReturnVal = wpReturnUrl.searchParams.get("wp_return"); 33 wpReturnEl.setAttribute("value", wpReturnVal); 34 35 showLoginView(); 36 new $.modal($("#amo-sso-login-modal"), { 37 fadeDuration: 100, 38 modalClass: "wpamo-sso-modal", 39 }); 40 41 // Add accessibility attributes to close button 42 setTimeout(function() { 43 $('a.close-modal').attr({ 44 'aria-label': 'Close', 45 'role': 'button', 46 'title': 'Close' 47 }); 48 }, 100); 49 }); 50 }); 51 52 // Check for return codes on page load 53 checkForReturnCodes(); 54 55 // View switching functions 56 function showLoginView() { 57 $(".wpamo-sso-form-view").hide(); 58 loginForm.show(); 59 clearAllErrors(); 60 } 61 62 function showForgotUsernameView() { 63 $(".wpamo-sso-form-view").hide(); 64 forgotUsernameForm.show(); 65 clearAllErrors(); 66 } 67 68 function showForgotPasswordView() { 69 $(".wpamo-sso-form-view").hide(); 70 forgotPasswordForm.show(); 71 clearAllErrors(); 72 } 73 74 // Forgot username link click handler 75 $(".wpamo-sso-forgot-username-link").on("click", function (e) { 76 e.preventDefault(); 77 showForgotUsernameView(); 78 }); 79 80 // Forgot password link click handler 81 $(".wpamo-sso-forgot-password-link").on("click", function (e) { 82 e.preventDefault(); 83 showForgotPasswordView(); 84 }); 85 86 // Back to login link click handlers 87 $(".wpamo-sso-back-to-login-link").on("click", function (e) { 88 e.preventDefault(); 89 showLoginView(); 90 }); 91 92 // Validation constraints 93 const presenceConstraint = { 94 presence: { allowEmpty: false, message: "is required" }, 95 }; 96 97 const emailConstraint = { 98 presence: { allowEmpty: false, message: "is required" }, 99 email: { message: "is not valid" }, 100 }; 101 102 // Login form validation 103 usernameEl.on("change keyup", function () { 104 const result = validate( 105 { username: usernameEl.val() }, 106 { username: presenceConstraint } 107 ); 108 if (hasError(result, "username")) { 109 addError(usernameEl, result.username[0]); 110 } else { 111 removeErrors(usernameEl); 112 } 113 }); 114 115 passwordEl.on("change keyup", function () { 116 const result = validate( 117 { password: passwordEl.val() }, 118 { password: presenceConstraint } 119 ); 120 if (hasError(result, "password")) { 121 addError(passwordEl, result.password[0]); 122 } else { 123 removeErrors(passwordEl); 124 } 125 }); 126 127 loginForm.on("submit", function (ev) { 128 ev.preventDefault(); 129 130 const input = { 131 username: usernameEl.val(), 132 password: passwordEl.val(), 133 }; 134 const constraints = { 135 username: presenceConstraint, 136 password: presenceConstraint, 137 }; 138 139 const result = validate(input, constraints); 140 const invalid = 141 hasError(result, "username") || hasError(result, "password"); 142 143 if (!invalid) { 144 $(this).unbind("submit").submit(); 145 } 146 147 if (hasError(result, "username")) { 148 addError(usernameEl, result.username[0]); 149 } 150 if (hasError(result, "password")) { 151 addError(passwordEl, result.password[0]); 152 } 153 }); 154 155 // Forgot username form validation 156 forgotUsernameEmailEl.on("change keyup", function () { 157 const result = validate( 158 { email: forgotUsernameEmailEl.val() }, 159 { email: emailConstraint } 160 ); 161 if (hasError(result, "email")) { 162 addError(forgotUsernameEmailEl, result.email[0]); 163 } else { 164 removeErrors(forgotUsernameEmailEl); 165 } 166 }); 167 168 forgotUsernameForm.on("submit", function (ev) { 169 ev.preventDefault(); 170 171 const input = { 172 email: forgotUsernameEmailEl.val(), 173 }; 174 const constraints = { 175 email: emailConstraint, 176 }; 177 178 const result = validate(input, constraints); 179 const invalid = hasError(result, "email"); 180 181 if (!invalid) { 182 // Set wp_return value before submitting 183 const currentUrl = window.location.href.split("?")[0]; 184 forgotUsernameWpReturnEl.setAttribute("value", currentUrl); 185 186 // Submit form normally like login form does 187 $(this).unbind("submit").submit(); 188 } 189 190 if (hasError(result, "email")) { 191 addError(forgotUsernameEmailEl, result.email[0]); 192 } 193 }); 194 195 // Forgot password form validation 196 forgotPasswordEmailEl.on("change keyup", function () { 197 const result = validate( 198 { email: forgotPasswordEmailEl.val() }, 199 { email: emailConstraint } 200 ); 201 if (hasError(result, "email")) { 202 addError(forgotPasswordEmailEl, result.email[0]); 203 } else { 204 removeErrors(forgotPasswordEmailEl); 205 } 206 }); 207 208 forgotPasswordForm.on("submit", function (ev) { 209 ev.preventDefault(); 210 211 const input = { 212 email: forgotPasswordEmailEl.val(), 213 }; 214 const constraints = { 215 email: emailConstraint, 216 }; 217 218 const result = validate(input, constraints); 219 const invalid = hasError(result, "email"); 220 221 if (!invalid) { 222 // Set wp_return value before submitting 223 const currentUrl = window.location.href.split("?")[0]; 224 forgotPasswordWpReturnEl.setAttribute("value", currentUrl); 225 226 // Submit form normally like login form does 227 $(this).unbind("submit").submit(); 228 } 229 230 if (hasError(result, "email")) { 231 addError(forgotPasswordEmailEl, result.email[0]); 232 } 233 }); 234 235 // Helper functions 236 function addError(el, error) { 237 el.addClass("wpamo-sso-error"); 238 el.parent().find(".wpamo-sso-error-message").remove(); 239 el.parent().append( 240 '<div class="wpamo-sso-error-message">' + error + "</div>" 241 ); 242 } 243 244 function removeErrors(el) { 245 el.removeClass("wpamo-sso-error"); 246 el.parent().find(".wpamo-sso-error-message").remove(); 247 } 248 249 function clearAllErrors() { 250 $(".wpamo-sso-error").removeClass("wpamo-sso-error"); 251 $(".wpamo-sso-error-message").remove(); 252 } 253 254 function hasError(result, type) { 255 return typeof result === "object" && result.hasOwnProperty(type); 256 } 257 258 // Check for return codes from AMO redirects 259 function checkForReturnCodes() {
260 const urlParams = new URLSearchParams(window.location.search); 261 const returnCode = urlParams.get("return_code"); 262 const formType = urlParams.get("form_type"); 263 264 console.log("=== CHECKING FOR RETURN CODES ==="); 265 console.log("Current URL:", window.location.href); 266 console.log("Return Code:", returnCode); 267 console.log("Form Type:", formType); 268 269 if (returnCode && formType) { 270 console.log("Both parameters found - showing message"); 271 272 // Define messages for username return codes 273 const usernameMessages = { 274 1: { 275 title: "Check Your Email", 276 message: 277 "An email with your username has been sent. Please contact our support for further assistance.", 278 type: "success", 279 }, 280 2: { 281 title: "Email Not Found", 282 message: 283 "The email address you entered is not associated with a member account for this association. Please contact our support for assistance.", 284 type: "error", 285 }, 286 3: { 287 title: "Multiple Accounts Found", 288 message: 289 "The email address you entered is associated with multiple member accounts for this association. Please contact our support for assistance.", 290 type: "error", 291 }, 292 4: { 293 title: "Email Required", 294 message: "Please Enter Your Email Address", 295 type: "error", 296 }, 297 }; 298 299 // Define messages for password return codes 300 const passwordMessages = { 301 1: { 302 title: "Check Your Email", 303 message: 304 "An email with password reset instructions has been sent. Please check your inbox.", 305 type: "success", 306 }, 307 2: { 308 title: "Email Not Found", 309 message: 310 "The email address you entered is not associated with a member account for this association. Please contact our support for assistance.", 311 type: "error", 312 }, 313 3: { 314 title: "Multiple Accounts Found", 315 message: 316 "The email address you entered is associated with multiple member accounts for this association. Please contact our support for assistance.", 317 type: "error", 318 }, 319 4: { 320 title: "Email Required", 321 message: "Please Enter Your Email Address", 322 type: "error", 323 }, 324 }; 325 326 const messages = 327 formType === "username" ? usernameMessages : passwordMessages; 328 const messageData = messages[returnCode]; 329 330 if (messageData) { 331 // Open modal and show appropriate form with message 332 if (formType === "username") { 333 showForgotUsernameView(); 334 } else if (formType === "password") { 335 showForgotPasswordView(); 336 } 337 338 new $.modal($("#amo-sso-login-modal"), { 339 fadeDuration: 100, 340 modalClass: "wpamo-sso-modal", 341 }); 342 343 // Add accessibility attributes to close button 344 setTimeout(function() { 345 $('a.close-modal').attr({ 346 'aria-label': 'Close', 347 'role': 'button', 348 'title': 'Close' 349 }); 350 }, 100); 351 352 // Show the message in the modal 353 const form = 354 formType === "username" ? forgotUsernameForm : forgotPasswordForm; 355 showReturnCodeMessage(form, messageData); 356 357 // Clean up URL without reloading page 358 const cleanUrl = window.location.href.split("?")[0]; 359 window.history.replaceState({}, document.title, cleanUrl); 360 } else { 361 console.log("Message data not found for return code:", returnCode); 362 } 363 } else { 364 console.log("Missing required parameters - not showing modal"); 365 if (returnCode && !formType) { 366 console.log( 367 "WARNING: return_code found but form_type is missing. AMO needs to add &form_type=username or &form_type=password to the redirect URL" 368 ); 369 } 370 } 371 } 372 373 // Show return code message in modal 374 function showReturnCodeMessage(form, messageData) { 375 // Hide all form fields 376 form.find(".wpamo-row").hide(); 377 378 // Determine icon based on type 379 const icon = 380 messageData.type === "success" 381 ? "â" 382 : messageData.type === "error" 383 ? "â" 384 : "!"; 385 const iconColor = 386 messageData.type === "success" 387 ? "#4CAF50" 388 : messageData.type === "error" 389 ? "#f44336" 390 : "#ff9800"; 391 392 // Create message HTML 393 const messageHtml = 394 '<div class="wpamo-sso-return-message">' + 395 '<div class="wpamo-sso-return-icon" style="background-color: ' + 396 iconColor + 397 ';">' + 398 icon + 399 "</div>" + 400 '<h3 class="wpamo-sso-return-title">' + 401 messageData.title + 402 "</h3>" + 403 '<p class="wpamo-sso-return-text">' + 404 messageData.message + 405 "</p>" + 406 '<button type="button" class="wpamo-sso-submit-btn btn btn-primary block full-width m-b wpamo-sso-return-close">Close</button>' + 407 "</div>"; 408 409 // Append message to form 410 form.append(messageHtml); 411 412 // Handle close button 413 form.find(".wpamo-sso-return-close").on("click", function () { 414 $.modal.close(); 415 // Reset form after modal closes 416 setTimeout(function () { 417 form.find(".wpamo-sso-return-message").remove(); 418 form.find(".wpamo-row").show(); 419 form[0].reset(); 420 clearAllErrors(); 421 }, 300); 422 }); 423 } 424 425 // Submit forgot username form via AJAX 426 function submitForgotUsernameForm(form) { 427 const formData = new FormData(form[0]); 428 const submitButton = form.find('button[type="submit"]'); 429 const originalButtonText = submitButton.text(); 430 431 // Debug: Log form data being sent 432 console.log("=== FORGOT USERNAME FORM SUBMISSION ==="); 433 console.log("Form Action URL:", form.attr("action")); 434 console.log("Form Data:"); 435 for (let pair of formData.entries()) { 436 console.log(" " + pair[0] + ": " + pair[1]); 437 } 438 439 // Disable button and show loading state 440 submitButton.prop("disabled", true).text("Sending..."); 441 442 $.ajax({ 443 url: form.attr("action"), 444 type: "POST", 445 data: formData, 446 processData: false, 447 contentType: false, 448 success: function (response, status, xhr) { 449 console.log("Success Response:"); 450 console.log(" Status:", status); 451 console.log(" Status Code:", xhr.status); 452 console.log(" Response Type:", typeof response); 453 console.log(" Response Length:", response ? response.length : 0); 454 console.log(" Response Preview:", response ? response.substring(0, 500) : "empty"); 455 456 showConfirmationMessage( 457 forgotUsernameForm, 458 "Check Your Email", 459 "We've sent your username to the email address you provided. Please check your inbox." 460 ); 461 }, 462 error: function (xhr, status, error) { 463 console.log("Error Response:"); 464 console.log(" Status:", status); 465 console.log(" Status Code:", xhr.status); 466 console.log(" Error:", error); 467 console.log(" Response Text Preview:", xhr.responseText ? xhr.responseText.substring(0, 500) : "empty"); 468 469 showConfirmationMessage( 470 forgotUsernameForm, 471 "Request Submitted", 472 "Your request has been submitted. If an account exists with that email address, you will receive your username shortly." 473 ); 474 }, 475 complete: function () { 476 console.log("=== REQUEST COMPLETE ===\n"); 477 submitButton.prop("disabled", false).text(originalButtonText); 478 }, 479 }); 480 } 481 482 // Submit forgot password form via AJAX 483 function submitForgotPasswordForm(form) { 484 const formData = new FormData(form[0]); 485 const submitButton = form.find('button[type="submit"]'); 486 const originalButtonText = submitButton.text(); 487 488 // Debug: Log form data being sent 489 console.log("=== FORGOT PASSWORD FORM SUBMISSION ==="); 490 console.log("Form Action URL:", form.attr("action")); 491 console.log("Form Data:"); 492 for (let pair of formData.entries()) { 493 console.log(" " + pair[0] + ": " + pair[1]); 494 } 495 496 // Disable button and show loading state 497 submitButton.prop("disabled", true).text("Sending..."); 498 499 $.ajax({ 500 url: form.attr("action"), 501 type: "POST", 502 data: formData, 503 processData: false, 504 contentType: false, 505 success: function (response, status, xhr) { 506 console.log("Success Response:"); 507 console.log(" Status:", status); 508 console.log(" Status Code:", xhr.status); 509 console.log(" Response Type:", typeof response); 510 console.log(" Response Length:", response ? response.length : 0); 511 console.log(" Response Preview:", response ? response.substring(0, 500) : "empty"); 512 513 showConfirmationMessage( 514 forgotPasswordForm, 515 "Check Your Email", 516 "We've sent a password reset link to the email address you provided. Please check your inbox and follow the instructions to reset your password." 517 ); 518 }, 519 error: function (xhr, status, error) { 520 console.log("Error Response:"); 521 console.log(" Status:", status); 522 console.log(" Status Code:", xhr.status); 523 console.log(" Error:", error); 524 console.log(" Response Text Preview:", xhr.responseText ? xhr.responseText.substring(0, 500) : "empty"); 525 526 showConfirmationMessage( 527 forgotPasswordForm, 528 "Request Submitted", 529 "Your request has been submitted. If an account exists with that email address, you will receive a password reset link shortly." 530 ); 531 }, 532 complete: function () { 533 console.log("=== REQUEST COMPLETE ===\n"); 534 submitButton.prop("disabled", false).text(originalButtonText); 535 }, 536 }); 537 } 538 539 // Show confirmation message in modal 540 function showConfirmationMessage(form, title, message) { 541 // Hide all form fields and show confirmation 542 form.find(".wpamo-row").hide(); 543 544 // Create confirmation message HTML 545 const confirmationHtml = 546 '<div class="wpamo-sso-confirmation-message">' + 547 '<div class="wpamo-sso-confirmation-icon">â</div>' + 548 '<h3 class="wpamo-sso-confirmation-title">' + 549 title + 550 "</h3>" + 551 '<p class="wpamo-sso-confirmation-text">' + 552 message + 553 "</p>" + 554 '<button type="button" class="wpamo-sso-submit-btn btn btn-primary block full-width m-b wpamo-sso-confirmation-close">Close</button>' + 555 "</div>"; 556 557 // Append confirmation message to form 558 form.append(confirmationHtml); 559 560 // Handle close button 561 form.find(".wpamo-sso-confirmation-close").on("click", function () { 562 $.modal.close(); 563 // Reset form after modal closes 564 setTimeout(function () { 565 form.find(".wpamo-sso-confirmation-message").remove(); 566 form.find(".wpamo-row").show(); 567 form[0].reset(); 568 clearAllErrors(); 569 }, 300); 570 }); 571 } 572});
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.