1// AUTH 2 3function onLoad() { 4 // const pageUrl = window.location.href; 5 // const page = pageUrl.split('?')[0].substring(pageUrl.lastIndexOf('/') + 1); 6 7 const loginForm = document.querySelector('#login_form'); 8 if (loginForm) 9 loginForm.addEventListener('submit', onLogin); 10 11 const registerForm = document.querySelector('#register_form'); 12 if (registerForm) { 13 const languageSelector = document.getElementById('language'); 14 languages.forEach(function (language) { 15 languageSelector.add(new Option(language.name, language.id)); 16 }); 17 languageSelector.value = langId; 18 registerForm.addEventListener('submit', onRegister); 19 } 20 const forgotPasswordForm = document.querySelector('#forgot_pwd_form'); 21 if (forgotPasswordForm) 22 forgotPasswordForm.addEventListener('submit', onForgotPassword); 23 24 const resetPasswordForm = document.querySelector('#reset_pwd_form'); 25 if (resetPasswordForm) 26 resetPasswordForm.addEventListener('submit', onResetPassword); 27 28 const claimForm = document.querySelector('#claim_form'); 29 if (claimForm) 30 claimForm.addEventListener('submit', onClaim); 31 32 const resendConfirmationForm = document.querySelector('#resend_confirmation_form'); 33 if (resendConfirmationForm){ 34 var regemail = getCookie("regemail"); 35 if (regemail && regemail.length) 36 document.getElementById('email').value = regemail; 37 resendConfirmationForm.addEventListener('submit', onResendConfirmation); 38 } 39 40 document.querySelectorAll(".auth-input input").forEach(input => { 41 if (input.id === 'password') { 42 input.parentElement.classList.add('pwd-group'); 43 44 const btnEye = document.createElement('button'); 45 btnEye.classList.add('btn-eye'); 46 btnEye.type = 'button'; 47 input.parentElement.appendChild(btnEye); 48 49 const iconEye = document.createElement('i'); 50 iconEye.id = 'password_icon'; 51 iconEye.classList.add('fa-regular', 'fa-eye'); 52 btnEye.appendChild(iconEye); 53 54 btnEye.addEventListener('click', togglePasswordVisibility); 55 } 56 57 input.addEventListener("focus", function() { 58 this.classList.add("focused"); 59 }); 60 61 input.addEventListener("blur", function() { 62 if (this.value === "") 63 this.classList.remove("focused"); 64 }); 65 66 }); 67} 68 69if (document.readyState === "complete") { 70 console.log('document load complete'); 71 onLoad(); 72} 73else document.addEventListener('DOMContentLoaded', onLoad ); 74 75 76 77function togglePasswordVisibility() { 78 const passwordInput = document.getElementById("password"); 79 const passwordIcon = document.getElementById("password_icon"); 80 81 if (passwordInput.type === "password") { 82 passwordInput.type = "text"; 83 passwordIcon.classList.remove("fa-eye"); 84 passwordIcon.classList.add("fa-eye-slash"); 85 } else { 86 passwordInput.type = "password"; 87 passwordIcon.classList.remove("fa-eye-slash"); 88 passwordIcon.classList.add("fa-eye"); 89 } 90} 91 92function displayAuthAlert(message, type = 'error') { 93 const alertText = document.getElementById('alert_text'); 94 if (alertText) { 95 alertText.textContent = ''; 96 const icon = document.createElement('i'); 97 icon.classList.add('alert-icon'); 98 99 switch (type) { 100 case 'error': 101 icon.classList.add('fa-solid', 'fa-exclamation', 'fa-beat', 'fa-lg'); 102 icon.style.color = '#d63638'; 103 alertText.style.borderColor = 'red'; 104 break; 105 106 case 'success': 107 icon.classList.add('fa-solid', 'fa-check', 'fa-lg'); 108 icon.style.color = '#4caf50'; 109 alertText.style.borderColor = 'green'; 110 break; 111 } 112 alertText.appendChild(icon); 113 114 var txt1 = document.createElement("div"); 115 txt1.style.marginTop = '0.5rem'; 116 txt1.innerHTML = translations[message] || message; 117 alertText.appendChild(txt1); 118 119 // alertText.lastChild.textContent = message; 120 alertText.style.visibility = 'visible'; 121 } 122} 123 124function hideAlert() { 125 const alertText = document.getElementById('alert_text'); 126 if (alertText) 127 alertText.style.visibility = 'hidden'; 128} 129 130function postRequest(url, data) { 131 return fetch(url, { 132 //mode: 'cors', 133 method: 'POST', 134 headers: { 135 'Content-Type': 'application/json' 136 }, 137 body: JSON.stringify(data) 138 }).catch(err => { 139 displayAuthAlert('serverError'); 140 console.log(err); 141 }); 142} 143 144function createSessionCookie(sessionId) { 145 // var sessionCookie = "sid=" + sessionId + "; path=/; max-age=86400"; // 24 hours 146 // document.cookie = sessionCookie; 147 createCookie("sid", sessionId); 148 createCookie("sid2", sessionId); 149} 150 151//function getSessionId() { 152// var cookies = document.cookie.split("; "); 153// for (var i = 0; i < cookies.length; i++) { 154// var cookie = cookies[i].split("="); 155// if (cookie[0] === "sid") { 156// return cookie[1]; 157// } 158// } 159// return null; 160//} 161 162function createCookie(key, value) { 163 const age = 60 * 60 * 24 * 7; // 7 days 164 document.cookie = key + "=" + value + "; path=/; max-age=" + age; 165} 166 167function getCookie(key) { 168 const cookies = document.cookie.split("; "); 169 for (let i = 0; i < cookies.length; i++) { 170 const pair = cookies[i].split("="); 171 if (pair[0] === key) 172 return pair[1]; 173 } 174 return null; 175} 176 177function removeAfterLast(text, searchElement) { 178 const lastSpaceIndex = text.lastIndexOf(searchElement); 179 if (lastSpaceIndex > -1) 180 return text.substring(0, lastSpaceIndex); 181 return text; 182} 183 184function getQueryParams(url) { 185 const queryString = url.split('?')[1]; 186 const params = {}; 187 if (queryString) { 188 queryString.split('&').forEach((param) => { 189 const [key, value] = param.split('='); 190 params[key] = decodeURIComponent(value); 191 }); 192 } 193 return params; 194} 195 196async function onRegister(event) { 197 event.preventDefault(); 198 199 const email = document.getElementById('email').value; 200 const fullName = "" /*document.getElementById('name').value*/ ; 201 const password = document.getElementById('password').value; 202 const language = document.getElementById('language').value; 203 204 if (!email || !password || !email.length || !password.length) { 205 displayAuthAlert("emailPasswordRequired"); 206 return; 207 } 208 209 const data = { 210 email: email, 211 fullName: fullName, 212 password: password, 213 language: language, 214 projectTypeId: 2 215 }; 216 const response = await postRequest(endpoint + '/register', data); 217 if (response.ok) { 218 const responseRegister = await response.json(); 219 if (responseRegister.errorCode === 0) { 220 createCookie("regemail", email); 221 222 //document.getElementById('register_form').style.pointerEvents = "none"; 223 document.getElementById('register_form').style.display = "none"; 224 // displayAuthAlert('Registration successful! <a class="highlight" href="login.jsp">Press here to continue</a>', 'success'); 225 // setTimeout(function(){window.location.href = 'login.jsp';},5000); 226 displayAuthAlert('registrationSuccess', 'success'); 227 window.location.href = "email_confirmation.jsp"; 228 } else 229 displayAuthAlert(responseRegister.errorCode === 1 ? "registrationFailureEmailUse" : "registrationFailure"); 230 } else { 231 displayAuthAlert("registrationFailure"); 232 } 233} 234 235function onLogin(event) { 236 event.preventDefault(); 237 hideAlert(); 238 239 var email = document.getElementById('email').value; 240 var password = document.getElementById('password').value; 241 242 if (!email || !password) { 243 displayAuthAlert("emailPasswordRequired"); 244 return; 245 } 246 247 var data = { 248 email: email, 249 password: password, 250 projectTypeId: 2, 251 language: lang 252 }; 253 postRequest(endpoint + '/login', data).then(async response => { 254 if (response.ok) { 255 const responseLogin = await response.json(); 256 if (responseLogin.errorCode === 0) { 257 if (responseLogin.auth) { 258 loginSuccess(responseLogin.auth, responseLogin.content.fullName, responseLogin.content.email, responseLogin.numDomains); 259 } 260 } else if (responseLogin.errorCode === 2) 261 displayAuthAlert('sthWentWrong'); 262 else if (responseLogin.errorCode === 4) 263 displayAuthAlert('incorrectEmailPwd'); 264 else if (responseLogin.errorCode === 16) 265 displayAuthAlert('checkConfirmationEmailMsg'); 266 else 267 displayAuthAlert(responseLogin.message); 268 } else { 269 displayAuthAlert('sthWentWrong'); 270 console.error('Login failed: ' + response.statusText); 271 } 272 }); 273} 274 275function loginSuccess(sid, fullName, email, numDomains) { 276 displayAuthAlert('loginSuccess', 'success'); 277 createSessionCookie(sid); 278 createCookie("name", removeAfterLast(fullName, ' ')); 279 createCookie("email", email); 280 // createCookie("lang", responseLogin.lang); 281 282 setTimeout(() => { 283 const params = new URLSearchParams(window.location.search); 284 if (params.has('redirect')) { 285 window.location.href = params.get('redirect'); 286 } else { 287 // window.location.href = (responseLogin.numProjects ? "dashboard.jsp" : "website_settings.jsp"); 288 289 if (numDomains > 0) { 290 const dontShowInitialWizard = localStorage.getItem('dsiw'); 291 if (dontShowInitialWizard != null && dontShowInitialWizard === '1') 292 window.location.href = "dashboard.jsp"; 293 else 294 window.location.href = "initial_wizard.jsp"; 295 } else { 296 window.location.href = "initial_wizard.jsp"; 297 } 298 } 299 }, 100); 300} 301 302async function onForgotPassword(event) { 303 event.preventDefault(); 304 305 const email = document.getElementById('email').value; 306 if (!email) return; 307 308 // const response = await fetch(endpoint + '/lostpassword/' + email); 309 // const data = {projectTypeId: 2}; 310 311 const response = await postRequest(endpoint + '/lostpassword/' + email + '?projectTypeId=2'); 312 if (response.ok) { 313 const responseBody = await response.json(); 314 if (responseBody.errorCode === 0) 315 displayAuthAlert('emailSent', 'success'); 316 else 317 displayAuthAlert('resetPasswordFailed', 'error'); 318 } else { 319 displayAuthAlert('resetPasswordFailed', 'error'); 320 console.error('Reset password failed: ' + response.statusText); 321 } 322} 323 324async function onResetPassword(event) { 325 event.preventDefault(); 326 327 const email = document.getElementById('email').value; 328 if (!email) return; 329 330 const pw1 = document.getElementById('password').value; 331 const pw2 = document.getElementById('password2').value; 332 333 if (pw1 !== pw2) { 334 displayAuthAlert('passwordsDontMatch', 'error'); 335 return false;
336 } 337 338 const queryParams = getQueryParams(window.location.href); 339 const data = { 340 projectTypeId: 2, 341 email: email, 342 password: pw1, 343 token: queryParams['token'] 344 }; 345 const response = await postRequest(endpoint + '/resetpassword', data); 346 if (response.ok) { 347 const responseBody = await response.json(); 348 if (responseBody.errorCode === 0) { 349 displayAuthAlert('passwordUpdated', 'success'); 350 document.getElementById('reset_pwd_form').style.display = 'none'; 351 } else if (responseBody.errorCode == 10) 352 displayAuthAlert('simplePassword', 'error'); 353 else if (responseBody.errorCode == 9) 354 displayAuthAlert('shortPassword', 'error'); 355 else if (responseBody.errorCode == 3) 356 displayAuthAlert('authFailure', 'error'); 357 else if (responseBody.errorCode == 2) 358 displayAuthAlert('unknownError', 'error'); 359 else 360 displayAuthAlert('unknownError', 'error'); 361 } else { 362 displayAuthAlert('unknownError', 'error'); 363 console.error('Update password failed: ' + response.statusText); 364 } 365} 366 367async function onClaim(event) { 368 event.preventDefault(); 369 370 const email = event.target.email.value; 371 const message = event.target.claim.value; 372 if (!email || !message) return; 373 374 const data = { 375 email: email, 376 message: message, 377 projectTypeId: 2, 378 claim: 1 379 }; 380 postRequest(endpoint + '/contactus', data).then(async response => { 381 if (response.ok) { 382 const responseBody = await response.json(); 383 if (responseBody.statusCode === 0) 384 displayAuthAlert('claimSent', 'success'); 385 else 386 displayAuthAlert(translations["unknownError"] + '<br>' + responseBody.statusMessage, 'error'); 387 } else { 388 displayAuthAlert('unknownError', 'error'); 389 console.error('Error sending claim: ' + response.statusText); 390 } 391 }); 392} 393 394async function onResendConfirmation(event) { 395 event.preventDefault(); 396 397 const email = document.getElementById('email').value; 398 if (!email) return; 399 400 const data = { 401 email: email, 402 projectTypeId: 2 403 }; 404 const response = await postRequest(endpoint + '/resend-confirmation', data); 405 if (response.ok) { 406 const responseResend = await response.json(); 407 if (responseResend.statusCode === 0) 408 displayAuthAlert('confirmationSent', 'success'); 409 else if (responseResend.statusCode === 1) 410 displayAuthAlert('alreadyEnabled', 'success'); 411 else if (responseResend.statusCode === 4) 412 displayAuthAlert('unknownError', 'error'); 413 else 414 displayAuthAlert(translations["unknownError"] + '<br>' + responseResend.statusMessage, 'error'); 415 } else 416 displayAuthAlert('unknownError'); 417}
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.