1document.addEventListener('DOMContentLoaded', function () { 2 getTemplateContents(); 3}); 4 5var securityVerifyAccountIdUserEmail; 6var securityVerifyAccountId; 7var queryResults; 8 9//testing environment 10var accountSecurityAPI = '/secondline/call/check_account_security/'; 11var generateCodeAPI = '/secondline/call/create_verify_code/'; 12var confirmVerificationCodeAPI = '/secondline/call/confirm_code/'; 13var checkPhoneNumberAndCountsAPI = '/secondline/call/check_phone_number/' 14 15 16var emailInterfaceHtmlCode; 17var registrationInterfaceHtmlCode; 18var smsInterfaceHtmlCode; 19var is_continue = false; 20var JwtForSecurityVerification = localStorage.getItem("callapp_jwt"); 21 22function nextStep() { 23 clearErrors(); 24 let inputField = document.getElementById("input_field_code"); 25 let smsCodeError = document.getElementById("sms_code_error"); 26 27 if (inputField && smsCodeError && inputField.style.visibility === "visible" && smsCodeError.style.visibility === "visible") { 28 confirmSMSVerificationCodeAsync(inputField.value) 29 .then(result => { 30 if (result) { 31 clearVerificationInterface(); 32 return false; 33 } else { 34 updateSMSError("Incorrect verification code.", "code"); 35 return false; 36 } 37 }) 38 } else { 39 if (checkPhoneNumberSync(getSecurityPhoneNUmber())) { 40 showCodeInput(); 41 } else { 42 updateSMSError("Please enter the correct phone number.", 'input'); 43 return false; 44 } 45 } 46} 47 48// Check if the phone number is correct synchronously 49function checkPhoneNumberSync(phoneNumber) { 50 if (phoneNumber === "") { 51 return false; 52 } 53
54 phoneNumber = phoneNumber.replace(/\s/g, ""); 55 let sendData = { 56 "phoneNumber": phoneNumber.toString(), 57 "check_call_record_counts": false, 58 "account_id": securityVerifyAccountId 59 }; 60 61 let response; 62 $.ajax({ 63 url: checkPhoneNumberAndCountsAPI, 64 type: "POST", 65 contentType: "application/json", 66 data: JSON.stringify(sendData), 67 headers: { 68 "AuthJWT": "yes", "Authorization": `JWT ${JwtForSecurityVerification}` 69 }, 70 async: false, 71 cache: false, 72 success: function (res) { 73 response = res.status; 74 }, 75 error: function (err) { 76 response = false; 77 } 78 }); 79 80 return response; 81} 82 83//Display code input box 84function showCodeInput() { 85 if (!generateSMSVerificationCode()) { 86 updateSMSError("Failed to send verification code to the number.", "input"); 87 return false; 88 } 89 let inputField = document.getElementById("input_field_code"); 90 let smsCodeError = document.getElementById("sms_code_error"); 91 let confirmButton = document.getElementById("confirm_sms_button"); 92 let sendButton = document.getElementById("send_button"); 93 94 if (inputField && smsCodeError && confirmButton) { 95 inputField.style.visibility = "visible"; 96 smsCodeError.style.visibility = "visible"; 97 confirmButton.textContent = "Confirm"; 98 sendButton.style.display = "inline-block"; 99 disableResendButton(); 100 } else { 101 return false; 102 } 103} 104 105function confirmSMSVerificationCodeAsync(code) { 106 return new Promise((resolve, reject) => { 107 // let phoneNumber = document.getElementById("input_field_phone").value; 108 let phoneNumber = getSecurityPhoneNUmber(); 109 if (!code || code.trim() === "") { 110 updateSMSError("Verification code is empty", "code"); 111 reject("Verification code is empty"); 112 } 113 if (!phoneNumber || phoneNumber.trim() === "") { 114 updateSMSError("Phone number is empty", "input"); 115 reject("Phone number is empty"); 116 } 117 118 let verifyData = new FormData(); 119 verifyData.append("verifyPhoneNumber", phoneNumber); 120 verifyData.append("channel", "sms"); 121 verifyData.append("account_id", securityVerifyAccountId); 122 verifyData.append("code", code); 123 124 $.ajax({ 125 url: confirmVerificationCodeAPI, 126 type: 'POST', 127 data: verifyData, 128 headers: { 129 "AuthJWT": "yes", "Authorization": `JWT ${JwtForSecurityVerification}` 130 }, 131 processData: false, 132 contentType: false, 133 cache: false, 134 success: function (response) { 135 resolve(response.status); 136 }, 137 error: function (error) { 138 reject("Ajax request failed"); 139 } 140 }); 141 }); 142} 143 144 145//Perform SMS verification 146function handleSMSVerification(res) { 147 if (!res.verify_phone_number) { 148 addSMSHtmlToContainer(); 149 } else { 150 addSMSHtmlToContainer(res.verify_phone_number) 151 } 152} 153 154function addSMSHtmlToContainer(phoneNumber = null) { 155 let Verify_Model_Container = document.getElementById("Verify_Model_Container"); 156 if (Verify_Model_Container) { 157 Verify_Model_Container.innerHTML = ''; 158 Verify_Model_Container.innerHTML = smsInterfaceHtmlCode; 159 160 // Select elements to hide and modify 161 let phoneCodeSelect = document.getElementById('security_verify_phone_code_select'); 162 let phoneCodeDisplay = document.getElementById('security_verify_phone_code_display'); 163 164 if (phoneNumber) { 165 let phoneInputElement = document.getElementById('input_field_phone'); 166 phoneInputElement.value = phoneNumber; 167 phoneInputElement.disabled = true; 168 169 // Make elements invisible and set value to space 170 if (phoneCodeSelect) { 171 phoneCodeSelect.style.display = 'none'; // Hide select element 172 } 173 if (phoneCodeDisplay) { 174 phoneCodeDisplay.style.display = 'none'; 175 phoneCodeDisplay.value = ' '; // Set value to space 176 } 177 } else { 178 // If no phoneNumber, ensure elements are visible and reset value 179 if (phoneCodeSelect) { 180 phoneCodeSelect.style.display = 'block'; // Show select element 181 } 182 if (phoneCodeDisplay) { 183 phoneCodeDisplay.value = ''; // Reset value to empty 184 } 185 } 186 } 187} 188 189function generateSMSVerificationCode() { 190 let phoneNumber = getSecurityPhoneNUmber(); 191 let smsData = new FormData(); 192 smsData.append("to_number", phoneNumber); 193 smsData.append("account_id", securityVerifyAccountId); 194 smsData.append("channel", "sms"); 195 let result; 196 $.ajax({ 197 url: generateCodeAPI, 198 type: 'POST', 199 data: smsData, 200 headers: { 201 "AuthJWT": "yes", "Authorization": `JWT ${JwtForSecurityVerification}` 202 }, 203 processData: false, 204 contentType: false, 205 cache: false, 206 async: false, 207 success: function (response) { 208 result = response.status; 209 }, 210 error: function (error) { 211 result = false;
212 } 213 }); 214 return result; 215} 216 217 218function reSendCode() { 219 if (!generateSMSVerificationCode) { 220 updateSMSError("Failed to send verification code to the current numbeer.", "input") 221 return false; 222 } 223 disableResendButton(); 224} 225 226function disableResendButton() { 227 let reSendButton = document.getElementById('send_button'); 228 let countdown = 60; 229 reSendButton.disabled = true; 230 reSendButton.textContent = `Send (${countdown})`; 231 let countdownInterval = setInterval(() => { 232 countdown--; 233 reSendButton.textContent = `Send (${countdown})`; 234 if (countdown <= 0) { 235 clearInterval(countdownInterval); 236 reSendButton.disabled = false; 237 reSendButton.textContent = "Send"; 238 } 239 }, 1000); 240} 241 242function clearVerificationInterface() { 243 let Verify_Model_Container = document.getElementById("Verify_Model_Container"); 244 if (Verify_Model_Container) { 245 Verify_Model_Container.innerHTML = ''; 246 } 247 if (queryResults.verification_type === "half_required") { 248 is_continue = true; 249 } 250 turnOffSecurityVerificationModeBox(); 251 location.reload(); 252} 253 254function addEmailHtmlToContainer() { 255 let Verify_Model_Container = document.getElementById("Verify_Model_Container"); 256 if (Verify_Model_Container) { 257 Verify_Model_Container.innerHTML = ''; 258 Verify_Model_Container.innerHTML = emailInterfaceHtmlCode; 259 } 260} 261 262function addRegisterHtmlToContainer(text, link, need_to_fill, canSkip, is_waiting = false) { 263 let Verify_Model_Container = document.getElementById("Verify_Model_Container"); 264 if (Verify_Model_Container) { 265 Verify_Model_Container.innerHTML = ''; 266 Verify_Model_Container.innerHTML = registrationInterfaceHtmlCode; 267 updateContent(text, link, need_to_fill, canSkip, is_waiting) 268 } else { 269 console.error("Please first add a container with the ID Verify-Model-Container"); 270 } 271} 272 273//Perform email verification 274function handleEmailVerification(res) { 275 addEmailHtmlToContainer(); 276 generateEmailVerificationCode() 277} 278 279//Generate email verification code 280function generateEmailVerificationCode() { 281 let verify_email_data = new FormData(); 282 verify_email_data.append("email", securityVerifyAccountIdUserEmail); 283 verify_email_data.append("account_id", securityVerifyAccountId); 284 verify_email_data.append("channel", "email"); 285 286 $.ajax({ 287 url: generateCodeAPI, 288 type: "POST", 289 data: verify_email_data, 290 headers: { 291 "AuthJWT": "yes", "Authorization": `JWT ${JwtForSecurityVerification}` 292 }, 293 processData: false, 294 contentType: false, 295 cache: false, 296 async: false, 297 success: function (response) { 298 console.log(response.msg) 299 }, 300 error: function () { 301 callback({ 302 "status": false, 303 "type": "", 304 "msg": "The verification code failed to be sent. Please try again later" 305 }); 306 } 307 }); 308} 309 310//Confirm email verification code 311function verifyConfirmEmailCode() { 312 let inputField = document.getElementById('input_field'); 313 let verifyData = new FormData(); 314 let code; 315 if (inputField) { 316 code = inputField.value; 317 } else { 318 updateEmailError("Please enter the verification code first") 319 } 320 verifyData.append("verifyEmail", securityVerifyAccountIdUserEmail); 321 verifyData.append("channel", "email"); 322 verifyData.append("code", code); 323 verifyData.append("account_id", securityVerifyAccountId) 324 325 $.ajax({ 326 url: confirmVerificationCodeAPI, 327 type: "POST", 328 data: verifyData, 329 headers: { 330 "AuthJWT": "yes", "Authorization": `JWT ${JwtForSecurityVerification}` 331 }, 332 processData: false, 333 contentType: false, 334 cache: false, 335 success: function (response) { 336 if (response.status) { 337 clearVerificationInterface(); 338 } else { 339 updateEmailError("Please input the correct verification code.") 340 } 341 }, 342 error: function (error) { 343 console.log('Error:', error); 344 updateEmailError("Please input the correct verification code.") 345 } 346 }); 347 348} 349 350//Email error prompt 351function updateEmailError(message) { 352 let emailError = document.getElementById('email_error'); 353 if (emailError) { 354 emailError.textContent = ''; 355 emailError.textContent = message; 356 emailError.style.color = 'red'; 357 } else { 358 console.log('Element with id "email_error" not found.'); 359 } 360} 361 362function clearErrors() { 363 let smsInputError = document.getElementById('sms_phone_error'); 364 let smsCodeError = document.getElementById('sms_code_error'); 365 366 if (smsInputError) { 367 smsInputError.textContent = ''; 368 } 369 370 if (smsCodeError) { 371 smsCodeError.textContent = ''; 372 } 373} 374 375//SMS error prompt type = input / code 376function updateSMSError(message, type) { 377 let errorMsg; 378 let smsInputError = document.getElementById('sms_phone_error'); 379 let smsCodeError = document.getElementById('sms_code_error'); 380 if (type === "input") { 381 if (smsInputError) { 382 smsInputError.textContent = ''; 383 smsInputError.textContent = message; 384 smsInputError.style.color = 'red'; 385 } 386 } else if (type === "code") { 387 if (smsCodeError) { 388 smsCodeError.textContent = ''; 389 smsCodeError.textContent = message; 390 smsCodeError.style.color = 'red'; 391 } 392 } 393} 394 395//Process Half verification 396function handleHalfRequiredVerification(res) { 397 let profileLink = res.verify_register_link; 398 addRegisterHtmlToContainer('Would you like to proceed with using or provide your profile information?', profileLink, true, true); 399} 400 401//Process Fully verification 402function handleFullyRequiredVerification(res) { 403 let profileLink = res.verify_register_link; 404 if (res.account_business_profile_status === "failed") { 405 addRegisterHtmlToContainer("We need to confirm your registration information, please complete the required fields.", profileLink, true, false); 406 return false 407 } else if (res.account_business_profile_status === "success") { 408 return true 409 } 410 411} 412 413//Process Approval verification 414function handleApprovalRequiredVerification(res) { 415 let profileLink = res.verify_register_link; 416 if (res.account_business_profile_status === "failed") { 417 addRegisterHtmlToContainer("We need to confirm your registration information, please complete the required fields.", profileLink, true, false); 418 return false;
419 } else if (res.account_business_profile_status === "waiting") { 420 addRegisterHtmlToContainer("Please wait for the registration outcome to be reviewed.", profileLink, false, true, true); 421 return false; 422 } else if (res.account_business_profile_status === "success") { 423 return true 424 } 425} 426 427// Send email for account behavior security verification 428function checkAccountSecurity(email = null, accountId = null) { 429 let data = {}; 430 431 if (accountId) { 432 securityVerifyAccountId = accountId; 433 } 434 435 if (email) { 436 data.email = email; 437 securityVerifyAccountIdUserEmail = email; 438 } else { 439 data.email = localStorage.getItem("callapp_user_email"); 440 securityVerifyAccountIdUserEmail = localStorage.getItem("callapp_user_email"); 441 } 442 443 let result; 444 445 $.ajax({ 446 url: accountSecurityAPI, 447 type: 'POST', 448 data: data, 449 headers: { 450 "AuthJWT": "yes", "Authorization": `JWT ${JwtForSecurityVerification}` 451 }, 452 async: false, 453 success: function (response) { 454 result = response; 455 }, 456 error: function (xhr, status, error) { 457 console.error(error); 458 } 459 }); 460 461 return result; 462} 463 464//Display verification information and text 465function updateContent(text, link, need_to_fill, canSkip, is_waiting = false) { 466 const info = document.getElementById('verification_information'); 467 const profileLink = document.getElementById('profile_link'); 468 const continueButton = document.getElementById('continue_button'); 469 const registerButton = document.getElementById('register_button'); 470 471 472 if (info && profileLink && registerButton && continueButton) { 473 info.innerText = text; 474 475 if (need_to_fill) { 476 if (!profileLink.hasAttribute('href')) { 477 profileLink.setAttribute('href', ''); 478 } 479 profileLink.href = link; 480 profileLink.classList.remove('disabled'); 481 registerButton.disabled = false; 482 registerButton.style.opacity = '1'; 483 registerButton.style.cursor = 'pointer'; 484 } else { 485 profileLink.removeAttribute('href'); 486 profileLink.disabled = true; 487 profileLink.classList.add('disabled'); 488 registerButton.disabled = false; 489 registerButton.style.opacity = '0.5'; 490 registerButton.style.cursor = 'not-allowed'; 491 } 492 if (canSkip === false) { 493 continueButton.disabled = true; 494 continueButton.style.opacity = '0.5'; 495 continueButton.style.cursor = 'not-allowed'; 496 } else { 497 if (is_waiting) { 498 continueButton.innerHTML = 'Close'; 499 } 500 continueButton.disabled = false; 501 continueButton.style.opacity = '1'; 502 continueButton.style.cursor = 'pointer'; 503 } 504 } 505} 506 507function extractTemplateContent(templateId) { 508 var template = document.getElementById(templateId); 509 if (template) { 510 return template.innerHTML; 511 } 512 return null; 513} 514 515function getTemplateContents() { 516 registrationInterfaceHtmlCode = extractTemplateContent('Shaken_stir_template'); 517 emailInterfaceHtmlCode = extractTemplateContent('Email_template'); 518 smsInterfaceHtmlCode = extractTemplateContent('SMS_template'); 519} 520 521function getSecurityPhoneNUmber() {
522 let codePrefixEl = document.getElementById('security_verify_phone_code_display'); 523 let securityPhoneInputEl = document.getElementById('input_field_phone'); 524 if (securityPhoneInputEl && codePrefixEl) { 525 return formatPhoneNumber(codePrefixEl.value + securityPhoneInputEl.value); 526 } else { 527 return null; 528 } 529} 530 531function formatPhoneNumber(phoneString) { 532 let trimmedString = phoneString.replace(/\s/g, ''); 533 let lastPlusIndex = trimmedString.lastIndexOf('+'); 534 if (lastPlusIndex !== -1) { 535 return trimmedString.substring(lastPlusIndex); 536 } else { 537 return trimmedString; 538 } 539} 540 541 542
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.