1var $ = jQuery 2import { initializeApp } from "https://www.gstatic.com/firebasejs/9.18.0/firebase-app.js" 3import jsCookie from "https://cdn.jsdelivr.net/npm/[email protected]/+esm" 4import { 5 getAuth, 6 createUserWithEmailAndPassword, 7 sendEmailVerification, 8 onAuthStateChanged, 9 signInWithEmailAndPassword, 10 signOut, 11 linkWithCredential, 12 EmailAuthProvider, 13 updateEmail, 14 updatePassword, 15 reauthenticateWithCredential, 16 sendPasswordResetEmail, 17} from "https://www.gstatic.com/firebasejs/9.18.0/firebase-auth.js" 18 19import { 20 getFirestore, 21 setDoc, 22 Timestamp, 23 doc, 24 getDoc, 25 getCountFromServer, 26 addDoc, 27 collection, 28} from "https://www.gstatic.com/firebasejs/9.18.0/firebase-firestore.js" 29 30const it = async (url, body) => { 31 console.log(body) 32 const response = await fetch(url, { 33 headers: { 34 accept: "application/json", 35 "api-key": "50110f8c21e74c7ea2b4444ecd1ac05c", 36 }, 37 body: JSON.stringify(body), 38 method: "POST", 39 mode: "cors", 40 credentials: "include", 41 }) 42 const result = await response.json() 43 console.log(result) 44} 45 46const firebaseErrors = (error) => { 47 let title, description 48 switch (error.code) { 49 case "auth/email-already-in-use": 50 title = "Username already in use" 51 description = "Please enter another username" 52 break 53 54 case "auth/username-exists": 55 title = "Username already in use" 56 description = "Please enter another username" 57 break 58 59 case "auth/email-already-in-use": 60 title = "Email already in use" 61 description = "The email you entered already exists." 62 break 63 64 case "auth/too-many-requests": 65 title = "Too many attempts" 66 description = 67 "You have too many requests at the moment. Please try again later." 68 break 69 70 case "auth/user-not-found": 71 title = "User not found" 72 description = 73 "The email you have entered is not yet registered. Please check your details and try again." 74 break 75 76 case "auth/weak-password": 77 title = "Password should be at least 6 characters" 78 description = "Password should be at least 6 characters" 79 break 80 81 case "auth/wrong-password": 82 title = "Incorrect password" 83 description = "You have entered a wrong password. Please try again." 84 break 85 86 case "auth/user-not-found": 87 title = "Email address not found." 88 description = "You have entered a wrong email. Please try again." 89 break 90 91 default: 92 title = "An error occurred." 93 description = error.message 94 } 95 96 return { 97 title, 98 description, 99 } 100} 101 102var urlParams = new URLSearchParams(window.location.search) 103 104function isValidUrl(urlString) { 105 var urlPattern = new RegExp( 106 "^(https?:\\/\\/)?" + // validate protocol 107 "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // validate domain name 108 "((\\d{1,3}\\.){3}\\d{1,3}))" + // validate OR ip (v4) address 109 "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // validate port and path 110 "(\\?[;&a-z\\d%_.~+=-]*)?" + // validate query string 111 "(\\#[-a-z\\d_]*)?$", 112 "i" 113 ) // validate fragment locator 114 return !!urlPattern.test(urlString) 115} 116 117const firebaseConfig = { 118 apiKey: "AIzaSyA-q6UUgcuBUiTcxgJjZXASS95cEckhq6A", 119 authDomain: "freelancers-union-22bfc.firebaseapp.com", 120 projectId: "freelancers-union-22bfc", 121 storageBucket: "freelancers-union-22bfc.appspot.com", 122 messagingSenderId: "75007507718", 123 appId: "1:75007507718:web:d1909986e82262e2173287", 124} 125 126// Initialize Firebase 127export const app = initializeApp(firebaseConfig) 128export const auth = getAuth(app) 129export const db = getFirestore(app) 130 131let profile = null 132let loggedUser = null 133 134$(window).bind("hashchange", function () { 135 var hash = window.location.hash.replace(/^#/, "") 136 if (hash == "password") { 137 $(".white-box.steps").hide() 138 $(".changePassword").show() 139 } 140 if (hash == "email") { 141 $(".white-box.steps").hide() 142 $(".changeEmail").show() 143 } 144 if (hash == "hubnewsletter") { 145 $(".white-box.steps").hide() 146 $(".hubnewsletter").show() 147 } 148 if (hash == "deleteaccount") { 149 $(".white-box.steps").hide() 150 $(".deleteaccount").show() 151 } 152 if (hash == "profile") { 153 $(".white-box.steps").hide() 154 $(".profileSection").show() 155 } 156 if (hash == "getembedcode") { 157 $(".white-box.steps").hide() 158 $(".getembedcode").show() 159 } 160}) 161function parseDob(dob) { 162 if (!dob) { 163 return [null, null] 164 } 165 const patterns = [ 166 /(\d{2})-(\d{4})/, // MM-YYYY 167 /(\d{4})\/(\d{2})/, // YYYY/MM 168 ] 169 for (const pattern of patterns) { 170 const match = dob.match(pattern) 171 if (match) { 172 const groups = match.slice(1) 173 if (groups.length === 2) { 174 if (groups[0].length === 4) { 175 // YYYY/MM 176 return [parseInt(groups[0]), parseInt(groups[1])] 177 } else { 178 // MM-YYYY 179 return [parseInt(groups[1]), parseInt(groups[0])] 180 } 181 } 182 } 183 } 184 return [null, null] 185} 186 187$(".steps").hide() 188 189onAuthStateChanged(auth, async (user) => { 190 if (user) { 191 console.log("USER:", user) 192 loggedUser = user 193 194 const current = location.pathname 195 if (!jsCookie.get("firebase_user_email")) { 196 console.log("no cookie but session") 197 const datetime = user.metadata.lastLoginAt 198 const currentDate = new Date() 199 const currentDatetime = currentDate.getTime() 200 const differenceInMinutes = Math.floor( 201 (currentDatetime - datetime) / 60000 202 ) 203 console.log(differenceInMinutes) 204 if (differenceInMinutes > 5) { 205 signOut(auth).then(() => { 206 loggedUser = null 207 }) 208 } 209 } 210 211 let docRef = doc(db, "users", user.uid) 212 let docSnap = await getDoc(docRef) 213 if (docSnap.exists()) { 214 } else { 215 console.log("creating new profile") 216 const response = await fetch( 217 `/wp-content/themes/bd-gutenberg/users.php?email=${loggedUser.email}` 218 ) 219 const text = await response.text() 220 await setDoc( 221 doc(db, "users", loggedUser.uid), 222 { user_id: text, email: loggedUser.email, timestamp: Timestamp.now() }, 223 { merge: true } 224 ) 225 docSnap = await getDoc(docRef) 226 } 227 if (docSnap.exists()) { 228 const profile = docSnap.data() 229 230 $("#login").hide() 231 $(".profileLoader").hide() 232 $(".profileSection").show() 233 $(".loader").hide() 234 $(".user-meta-wrapper").show() 235 $(".data-section").show() 236 $("#fullName").html(`${profile.firstName} ${profile.lastName}`) 237 for (let index = 0; index < Object.keys(profile).length; index++) { 238 const element = Object.keys(profile)[index] 239 $(`#${element}`).val(profile[element]) 240 } 241 $(".insurance-zipcode").html(profile.zip) 242 $.ajax({ 243 url: `/wp-content/themes/bd-gutenberg/fb-auth.php?zip=${profile.zip}`, 244 method: "GET", 245 }).done(async function (res) { 246 console.log("ZIP Updated:", res) 247 }) 248 $("#memberID").html(profile.user_id) 249 let cAt = profile.createdAt 250 ? profile.createdAt.seconds * 1000 251 : profile.timestamp.seconds * 1000 252 console.log(cAt) 253 $("#signupDate").html( 254 //new Date(user.metadata.creationTime).toLocaleDateString('en-US') 255 new Date(cAt).toLocaleDateString("en-US") 256 ) 257 } 258 $("#email-address").val(user.email) 259 initializeSlimSelect() 260 } else { 261 if (window.location.pathname.includes("profile")) { 262 //window.location.href = '/login/' 263 } 264 loggedUser = null 265 initializeSlimSelect() 266 } 267}) 268 269window.loginUser = async function loginUser(email, password) { 270 // let user = await signInWithEmailAndPassword(email, password) 271} 272 273$("#login-form").submit(async function (e) { 274 e.preventDefault() 275 signInWithEmailAndPassword( 276 auth, 277 $("#email-address").val(), 278 $("#password").val() 279 ) 280 .then(() => { 281 console.log("logged in....") 282 }) 283 .catch((error) => { 284 let { title } = firebaseErrors(error) 285 alert(title) 286 }) 287}) 288 289$("#firstName").blur(async function () { 290 if ($(this).val() == "") { 291 showError(this, "First Name can not be blank") 292 } else { 293 hideError(this) 294 } 295}) 296 297$("#lastName").blur(async function () { 298 if ($(this).val() == "") { 299 showError(this, "Last Name can not be blank") 300 } else { 301 hideError(this) 302 } 303}) 304 305$("#phone").blur(async function () { 306 let phReg = /^\d*(?:\.\d{1,2})?$/ 307 if (phReg.test($(this).val()) && $(this).val().length == 10) { 308 hideError(this) 309 } else { 310 showError(this, "Invalid Phone Number") 311 } 312}) 313 314$("#zip").blur(async function () { 315 let phReg = /^[0-9]{4,5}$/ 316 if (phReg.test($(this).val())) { 317 // hideError(this) 318 // Then verify zipcode exists in database 319 try { 320 const zipcode = $(this).val() 321 const response = await fetch( 322 `/wp-content/themes/bd-gutenberg/zipinfo.php?zip=${zipcode}` 323 ) 324 const result = await response.json() 325 console.log(result) 326 if (result === null) { 327 showError(this, "Invalid Zipcode") 328 } else { 329 hideError(this) 330 } 331 } catch (error) { 332 console.error("Error checking zipcode:", error) 333 } 334 } else { 335 showError(this, "Invalid Zipcode") 336 } 337}) 338 339$("#websiteUrl").blur(async function () { 340 if ($(this).val() != "") { 341 if (isValidUrl($(this).val())) { 342 hideError(this) 343 } else { 344 showError(this, "Invalid URL") 345 } 346 } 347}) 348 349$("#pass").blur(async function () { 350 let mediumPassword = new RegExp( 351 "((?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.{6,}))|((?=.*[a-z])(?=.*[A-Z])(?=.*[^A-Za-z0-9])(?=.{8,}))" 352 ) 353 354 if ($(this).val().length < 7) { 355 showError(this, "Password must be aleast 8 characters long") 356 } else { 357 if (mediumPassword.test($(this).val())) { 358 hideError(this) 359 } else { 360 showError( 361 this, 362 "Password must contain at least one capital letter and one special character" 363 ) 364 } 365 } 366}) 367 368$("body").on("click", "#save-profile", function (e) { 369 e.preventDefault() 370 const values = $(this).closest("form").serializeJSON() 371 372 let [dob_year, dob_month] = parseDob(values.dob) 373 if (dob_year) { 374 values.dob_year = dob_year 375 } 376 if (dob_month && dob_month < 13 && dob_month > 0) {
377 values.dob_month = dob_month 378 } 379 380 setDoc(doc(db, "users", loggedUser.uid), values, { merge: true }) 381 382 $(this).html("...") 383 $.ajax({ 384 url: `/wp-content/themes/bd-gutenberg/fb-auth.php?zip=${values.zip}`, 385 method: "GET", 386 }).done(async function (res) { 387 console.log("ZIP Updated:", res) 388 $("#save-profile").html("Saved!") 389 }) 390 391 setTimeout(function () { 392 $("#save-profile").html("Save") 393 }, 5000) 394}) 395 396$("body").on("click", "#save-new-email", async function (e) { 397 e.preventDefault() 398 $(this).html("...") 399 let el = $(this) 400 const newEmail = $("#NewEmail").val() 401 const currentPass = $("#emailCurrentPass").val() 402 403 if (newEmail == "" || currentPass == "") { 404 showError($("#emailCurrentPass"), "Current Password and Email required!") 405 $("#save-new-email").html("Save") 406 return false 407 } 408 const credential = EmailAuthProvider.credential(loggedUser.email, currentPass) 409 const user = auth.currentUser 410 411 await reauthenticateWithCredential(user, credential) 412 .then(async (data) => { 413 await updateEmail(user, newEmail) 414 .then(async (data) => { 415 setDoc( 416 doc(db, "users", loggedUser.uid), 417 { email: newEmail }, 418 { merge: true } 419 ) 420 $("#save-new-email").html("Updated!") 421 setTimeout(function () { 422 window.location.href = "/logout" 423 }, 1000) 424 }) 425 .catch((error) => { 426 let { title } = firebaseErrors(error) 427 showError($("#emailCurrentPass"), title) 428 $("#save-new-email").html("Save") 429 console.log(error) 430 }) 431 }) 432 .catch((error) => { 433 let { title } = firebaseErrors(error) 434 showError($("#emailCurrentPass"), title) 435 $("#save-new-email").html("Save") 436 console.log(error) 437 }) 438 439 setTimeout(function () { 440 $("#save-new-email").html("Save") 441 }, 5000) 442}) 443 444$("body").on("click", "#save-change-password", async function (e) { 445 e.preventDefault() 446 $(this).html("...") 447 const oldPass = $("#oldPass") 448 const NewPass = $("#NewPass") 449 const ConfirmNewPass = $("#ConfirmNewPass") 450 hideError(oldPass) 451 hideError(NewPass) 452 453 if ( 454 oldPass.val() == "" || 455 NewPass.val() == "" || 456 ConfirmNewPass.val() == "" 457 ) { 458 showError(oldPass, "Password required!") 459 $("#save-change-password").html("Change Password") 460 return false 461 } 462 if (NewPass.val() != ConfirmNewPass.val()) { 463 showError(NewPass, "New and confirm password does not match!") 464 $("#save-change-password").html("Change Password") 465 return false 466 } 467 const credential = EmailAuthProvider.credential( 468 loggedUser.email, 469 oldPass.val() 470 ) 471 const user = auth.currentUser 472 473 await reauthenticateWithCredential(user, credential) 474 .then(async (data) => { 475 await updatePassword(user, NewPass.val()) 476 .then(async (data) => { 477 $("#save-change-password").html("Password updated!") 478 // window.location.href = '/logout' 479 }) 480 .catch((error) => { 481 let { title } = firebaseErrors(error) 482 showError(oldPass, title) 483 $("#save-change-password").html("Change Password") 484 console.log(error) 485 }) 486 }) 487 .catch((error) => { 488 let { title } = firebaseErrors(error) 489 showError(oldPass, title) 490 $("#save-change-password").html("Change Password") 491 console.log(error) 492 }) 493 494 setTimeout(function () { 495 $("#save-change-password").html("Change Password") 496 }, 5000) 497}) 498 499function isValidDOB(dob) { 500 var regex = /^(0[1-9]|1[0-2])-\d{4}$/ 501 return regex.test(dob) 502} 503 504// Validations here... 505$("body").on("click", '.step2 [type="submit"]', function (e) { 506 e.preventDefault() 507 $("#alert_message").html("") 508 let step2Pass = true 509 const dob_input = $("#dob") 510 const gender_input = $("#gender") 511 const industry_input = $("#industry") 512 const freelancing_input = $("#freelancingTime") 513 514 hideError(dob_input) 515 hideError(gender_input) 516 hideError(industry_input) 517 hideError(freelancing_input) 518 519 if (loggedUser) { 520 const { industry, freelancingTime, dob, gender } = $(this) 521 .closest("form") 522 .serializeJSON() 523 const UserData = { 524 industry, 525 freelancingTime, 526 dob, 527 gender, 528 } 529 530 console.log("UserData:", UserData) 531 532 if (!isValidDOB(dob_input.val())) { 533 showError(dob_input, "Invalid Birth Date") 534 return false 535 } 536 537 if ($("#gender").val() == "") { 538 showError(gender_input, "Please make a selection") 539 return false 540 } 541 542 if ($("#industry").val() == "") { 543 showError(industry_input, "Please make a selection") 544 return false 545 } 546 if ($("#freelancingTime").val() == "") { 547 showError(freelancing_input, "Please make a selection") 548 return false 549 } 550 551 step2Pass = true 552 console.log("step2Pass:", step2Pass) 553 if (step2Pass) { 554 let [dob_year, dob_month] = parseDob(UserData.dob) 555 if (dob_year) { 556 UserData.dob_year = dob_year 557 } 558 if (dob_month && dob_month < 13 && dob_month > 0) {
559 UserData.dob_month = dob_month 560 } 561 setDoc(doc(db, "users", loggedUser.uid), UserData, { merge: true }).catch( 562 (error) => { 563 let { title } = firebaseErrors(error) 564 $("#alert_message").html( 565 '<div class="alert alert-danger">' + title + "</div>" 566 ) 567 $(".step2").find("button[type='submit']").prop("disabled", false) 568 $(".step2") 569 .find("button[type='submit']") 570 .html(`Next <i class=" fa-solid fa-arrow-right-long"></i> `) 571 } 572 ) 573 574 $(".step").hide() 575 $(".step3").show() 576 $(".progressbar-list").removeClass("active") 577 $("#progressList-3").addClass("active") 578 } 579 } 580}) 581 582$("body").on("click", '.step3 [type="submit"]', function (e) { 583 e.preventDefault() 584 $("#alert_message").html("") 585 if (loggedUser) { 586 const { websiteUrl, raceEthnicity, reference } = $(this) 587 .closest("form") 588 .serializeJSON() 589 const UserData = { 590 websiteUrl, 591 raceEthnicity, 592 reference, 593 } 594 setDoc(doc(db, "users", loggedUser.uid), UserData, { merge: true }).catch( 595 (error) => { 596 let { title } = firebaseErrors(error) 597 $("#alert_message").html( 598 '<div class="alert alert-danger">' + title + "</div>" 599 ) 600 } 601 ) 602 603 $(".step").hide() 604 $("#alert_message").html( 605 '<div class="alert alert-success">You have successfully registered.</div>' 606 ) 607 608 setTimeout(function () { 609 window.location.href = "/" 610 }, 2000) 611 612 $("#progressBar").addClass("d-none") 613 } 614}) 615 616$("body").on("click", ".step2 .back", function () { 617 $(".step").hide() 618 $(".step3").show() 619 $(".progressbar-list").removeClass("active") 620 $("#progressList-3").addClass("active") 621}) 622 623$("body").on("click", ".step3 .back", function () { 624 $(".step").hide() 625 $(".step2").show() 626 627 $(".progressbar-list").removeClass("active") 628 $("#progressList-2").addClass("active") 629}) 630 631$("#logout").click(function (e) { 632 e.preventdefault 633 if (loggedUser) { 634 const auth = getAuth() 635 signOut(auth) 636 .then(() => { 637 // Sign-out successful. 638 loggedUser = null 639 window.location.replace("/logout/") 640 }) 641 .catch((error) => { 642 // An error happened. 643 }) 644 } 645}) 646 647$("#signup").submit(async function (e) { 648 e.preventDefault() 649 $("#alert_message").html("") 650 const { firstName, lastName, email, pass, phone, zip } = 651 $("#signup").serializeJSON() 652 653 $("#signup-btn").find("button[type='submit']").prop("disabled", true) 654 $("#signup-btn").html(`Please Wait...`) 655 656 try { 657 const response = await createUserWithEmailAndPassword(auth, email, pass) 658 console.log("Response:", response) 659 const profileInfo = { 660 firstName, 661 lastName, 662 email, 663 phone, 664 zip, 665 roles: ["user"], 666 timestamp: Timestamp.now(), 667 } 668 console.log(profileInfo) 669 670 await setDoc(doc(db, "users", response.user.uid), profileInfo).catch( 671 (error) => { 672 let { title } = firebaseErrors(error) 673 $("#alert_message").html( 674 '<div class="alert alert-danger"> ' + title + "</div>" 675 ) 676 $("#signup").find("button[type='submit']").prop("disabled", false) 677 $("#signup-btn").html( 678 `Get Started <i class=" fa-solid fa-arrow-right-long"></i> ` 679 ) 680 } 681 ) 682 $.ajax({ 683 url: `/wp-content/themes/bd-gutenberg/users.php?email=${email}`, 684 method: "GET", 685 }).done(async function (user_id) { 686 await setDoc( 687 doc(db, "users", response.user.uid), 688 { user_id: user_id }, 689 { merge: true } 690 ) 691 $(".step").hide() 692 $(".step2").show() 693 $(".progressbar-list").removeClass("active") 694 $("#progressList-2").addClass("active") 695 696 // if ($(".page-template-t-join").length == 0) { 697 window.location.href = "/join?step2" 698 // } 699 }) 700 jQuery.ajax({ 701 type: "POST", 702 url: _wpUtilSettings.ajax.url, 703 data: { 704 action: "get_fb_login", 705 email: email, 706 password: pass, 707 }, 708 success: function (res) { 709 //window.location.href = '/profile' 710 }, 711 }) 712 } catch (error) { 713 $("#signup").find("button[type='submit']").removeAttr("disabled") 714 $("#signup") 715 .find("button[type='submit']") 716 .html(`Get Started <i class="fas fa-long-arrow-alt-right"></i>`) 717 let { title } = firebaseErrors(error) 718 $("#email-address").parent(".fl-form-group2").addClass("error") 719 $("#email-address").next(".notice").html(title) 720 $("#alert_message").html( 721 '<div class="alert alert-danger"><b>Error!</b> ' + title + "</div>" 722 ) 723 $("#signup").find("button[type='submit']").prop("disabled", false) 724 $("#signup-btn").html( 725 `Get Started <i class=" fa-solid fa-arrow-right-long"></i> ` 726 ) 727 } 728}) 729$("#loginForm").on("submit", function (e) { 730 e.preventDefault() 731 $("#alert_message").html("") 732 $(this).find("button").attr("disabled") 733 const { email, password } = $(this).serializeJSON() 734 const auth = getAuth() 735 $(this).find("button").html("Please Wait....") 736 signInWithEmailAndPassword(auth, email, password) 737 .then((userCredential) => { 738 const user = userCredential.user 739 loggedUser = user 740 741 jQuery.ajax({ 742 type: "POST", 743 url: _wpUtilSettings.ajax.url, 744 data: { 745 action: "get_fb_login", 746 email: email, 747 password: password, 748 }, 749 success: async function (res) { 750 const docRef = doc(db, "users", user.uid) 751 const docSnap = await getDoc(docRef) 752 if (docSnap.exists()) { 753 const profile = docSnap.data() 754 if (urlParams.has("redirect_to")) { 755 $.ajax({ 756 url: `/wp-content/themes/bd-gutenberg/fb-auth.php?zip=${profile.zip}`, 757 method: "GET", 758 }).done(async function (res) {
759 window.location.href = urlParams.get("redirect_to") 760 }) 761 } else { 762 window.location.href = "/profile/" 763 } 764 $("#alert_message").html( 765 '<div class="alert alert-success"><b>Success!</b> You have logged in successfully.</div>' 766 ) 767 } else { 768 window.location.href = "/" 769 } 770 }, 771 }) 772 }) 773 .catch((error) => { 774 const errorCode = error.code 775 const errorMessage = error.message 776 let { title } = firebaseErrors(error) 777 if (title.includes("Incorrect password")) { 778 jQuery.ajax({ 779 type: "POST", 780 url: _wpUtilSettings.ajax.url, 781 data: { 782 action: "check_password_reset", 783 email: email, 784 }, 785 success: async function (res) { 786 if (res == "showReset") { 787 $("#alert_message").html( 788 '<div class="alert alert-danger"><b>Your password has expired.</b> Please reset your password to continue.<a class="btn-with-icon ep-btn orange-btn next mt-2" href="https://freelancersunion.org/forgot-password/?email=' + 789 email + 790 '">Reset Password Now</a></div>' 791 ) 792 } else { 793 $("#alert_message").html( 794 '<div class="alert alert-danger">' + title + "</div>" 795 ) 796 } 797 }, 798 }) 799 } else { 800 $("#alert_message").html( 801 '<div class="alert alert-danger">' + title + "</div>" 802 ) 803 } 804 $(this).find("button").removeAttr("disabled") 805 $(this) 806 .find("button") 807 .html('Login <i class="fa-solid fa-arrow-right-long"></i>') 808 }) 809}) 810 811$("body").on("submit", "#forgotPassword", function (e) { 812 e.preventDefault() 813 const { email } = $(this).serializeJSON() 814 $("#forgotPassword").find("button").html("Please Wait...") 815 $("#forgotPassword").find("button").prop("disbled", true) 816 const auth = getAuth() 817 sendPasswordResetEmail(auth, email) 818 .then(() => { 819 $("#alert_message").html( 820 '<div class="alert alert-success">Password reset email sent! Please check your email to set a new password.</div>' 821 ) 822 $("#forgotPassword") 823 .find("button") 824 .html('Reset Password <i class="fa-solid fa-arrow-right-long"></i>') 825 $("#forgotPassword").find("button").prop("disbled", false) 826 }) 827 .catch((error) => { 828 const errorCode = error.code 829 const errorMessage = error.message 830 let { title } = firebaseErrors(error) 831 $("#alert_message").html( 832 '<div class="alert alert-danger"><b>Error!</b> ' + title + "</div>" 833 ) 834 $("#forgotPassword") 835 .find("button") 836 .html('Reset Password <i class="fa-solid fa-arrow-right-long"></i>') 837 $("#forgotPassword").find("button").prop("disbled", false) 838 }) 839}) 840 841function showError(element, message) { 842 console.log(message) 843 $(element).parent(".fl-form-group2").addClass("error") 844 $(element).next(".notice").html(message) 845 $(element).siblings(".notice").html(message) 846 $("#signup-btn").prop("disabled", true) 847} 848// function hideError(element) { 849// $(element).parent(".fl-form-group2").removeClass("error") 850// $("#signup-btn").removeAttr("disabled") 851// $(element).next(".notice").html(" ") 852// $(element).siblings(".notice").html(" ") 853// } 854 855function hideError(element) { 856 // Remove error class from the current field 857 $(element).parent(".fl-form-group2").removeClass("error") 858 859 // Clear the error message 860 $(element).next(".notice").html(" ") 861 $(element).siblings(".notice").html(" ") 862 863 // Check if there are any visible error notices on the page 864 const hasVisibleErrors = 865 $(".fl-form-group2.error").length > 0 || 866 ($(".notice:visible").text().trim() !== "" && 867 $(".notice:visible").text().trim() !== " ") 868 869 // Only enable the submit button if there are no visible errors 870 if (!hasVisibleErrors) { 871 $("#signup-btn").removeAttr("disabled") 872 } 873} 874 875$("#email-address").blur(function () { 876 // Email regex pattern 877 const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ 878 879 if ($(this).val() === "") { 880 showError(this, "Email address cannot be blank") 881 } else if (!emailRegex.test($(this).val())) { 882 showError(this, "Please enter a valid email address") 883 } else { 884 hideError(this) 885 } 886}) 887 888$("#firstName").blur(async function () { 889 if ($(this).val() == "") { 890 showError(this, "First Name can not be blank") 891 } else { 892 hideError(this) 893 } 894}) 895 896$("#lastName").blur(async function () { 897 if ($(this).val() == "") { 898 showError(this, "Last Name can not be blank") 899 } else { 900 hideError(this) 901 } 902}) 903 904$("#pass").blur(async function () { 905 let mediumPassword = new RegExp( 906 "((?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.{6,}))|((?=.*[a-z])(?=.*[A-Z])(?=.*[^A-Za-z0-9])(?=.{8,}))" 907 ) 908 909 if ($(this).val().length < 7) { 910 showError(this, "Password must be aleast 8 characters long") 911 } else { 912 if (mediumPassword.test($(this).val())) { 913 hideError(this) 914 } else { 915 showError( 916 this, 917 "Password must contain at least one capital letter and one special character" 918 ) 919 } 920 } 921}) 922 923function initializeSlimSelect() { 924 const selects = [ 925 "#industry", 926 "#freelancingTime", 927 "#raceEthnicity", 928 "#gender", 929 "#reference", 930 ]
931 selects.forEach((select) => { 932 new SlimSelect({ 933 select: select, 934 settings: { 935 showSearch: false, 936 placeholderText: " ", 937 }, 938 }) 939 }) 940}
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.