1jQuery(document).ready(function ($) { 2 3 4InitializeAjaxLoginForms(); 5 6/** 7 * 8 * Facebook Login 9 * 10 */ 11 12 //trigger Facebook login 13 14$('body').on('click', '.fb-login-button', function() { 15 FBLogin(); 16 return false; 17 }); 18 19function inizializzaLoginFacebook() { 20 21 if ($('.fb-login-button').length) { 22 $.ajaxSetup({ cache: true }); 23 $.getScript('https://connect.facebook.net/'+ajax_auth_object.locale+'/sdk.js', function(){ 24 FB.init({ 25 appId : ajax_auth_object.facebook_id, 26 cookie : true, 27 xfbml : true, 28 version : 'v3.2' 29 }); 30 }); 31 } 32} 33 34// This is called with the results from from FB.getLoginStatus(). 35function statusChangeCallback(response) { 36 37 if (response.status === 'connected') { 38 // Logged into your app and Facebook. 39 // we need to hide FB login button 40 $('#fblogin').hide(); 41 //fetch data from facebook 42 getUserInfo(); 43 } else if (response.status === 'not_authorized') { 44 // The person is logged into Facebook, but not your app. 45 $('#status').html('Please log into this app.'); 46 } else { 47 // The person is not logged into Facebook, so we're not sure if 48 // they are logged into this app or not. 49 $('#status').html('Please log into facebook'); 50 } 51} 52 53// This function is called when someone finishes with the Login 54// Button. See the onlogin handler attached to it in the sample code below. 55function checkLoginState() { 56 FB.getLoginStatus(function(response) { 57 statusChangeCallback(response); 58 }); 59} 60 61function FBLogin() { 62 63 showToast(ajax_auth_object.loadingmessage,'<div class="swal-loading-css-big-relative"></div>',false); 64 FB.login(function(response) { 65 if (response.authResponse) 66 { 67 getUserInfo(); //Get User Information. 68 } else 69 { 70 showToast(ajax_auth_object.facebook_error_1,'<i class="fa fa-exclamation"></i>',true); 71 } 72 },{scope: 'public_profile,email'}); 73} 74 75function FBLogout() { 76 77 FB.logout(function(response) { 78 //$('#fblogin').show(); //showing login button again 79 //$('#fbstatus').hide(); //hiding the status 80 }); 81} 82 83function getUserInfo() { 84 85 FB.api('/me', {fields: 'first_name,last_name,email,hometown,link,picture'}, function(response) { 86 87 88 $.ajax({ 89 type: "POST", 90 dataType: 'json', 91 data: response, 92 url: ajax_auth_object.ajaxurl + '?action=swal-fblogin', 93 success: function(data) { 94 if (data.loggedin == true) { 95 showToast(data.message,'<i class="fa fa-check"></i>',true); 96 document.location.href = ajax_auth_object.redirecturl; 97 ClosePopup(); 98 } else { 99 showToast(data.message,'<i class="fa fa-exclamation"></i>',true); 100 } 101 } 102 }); 103 104 }); 105 106} 107 108 109/** 110 * 111 * Twitter Login 112 * 113 */ 114 115 $('body').on('click', '.twitter-login-button', function(e) { 116 117 e.preventDefault; 118 119 $.ajax({ 120 type: "POST", 121 dataType: 'json', 122 data: response, 123 url: ajax_auth_object.ajaxurl + '?action=swal-twlogin', 124 success: function(data) { 125 if (data.loggedin == true) { 126 showToast(data.message,'<i class="fa fa-check"></i>',true); 127 document.location.href = ajax_auth_object.redirecturl; 128 ClosePopup(); 129 } else { 130 showToast(data.message,'<i class="fa fa-exclamation"></i>',true); 131 } 132 } 133 }); 134 return false; 135 }); 136 137 138/** 139 * 140 * Other non Ajax Login 141 * this is just to show a loader as the login process is fully in PHP 142 * 143 */ 144 $('body').on('click', '.google-login-button, .linkedin-login-button, .instagram-login-button', function(e) { 145 showToast(ajax_auth_object.loadingmessage,'<div class="swal-loading-css-big-relative"></div>',false); 146 }); 147 148 149/** 150 * 151 * Initialize all the forms 152 * 153 */ 154function InitializeAjaxLoginForms() { 155 156 InitializeAjaxLoginSubmit(); 157 inizializzaLoginFacebook(); 158 /* 159 if ($('.g-recaptcha').length) { 160 //grecaptcha.reset(); 161 var sitekey = $('.g-recaptcha').data('sitekey'); 162 var captchaWidgetId = grecaptcha.render( 'myCaptcha', { 163 'sitekey' : sitekey, 164 'theme' : ajax_auth_object.recaptchatheme, 165 }); 166 } 167 */ 168} 169 170 171 /** 172 * 173 * Function to open Login Popup 174 * 175 */ 176 $('.sw-open-login').click(function(e) { 177 if (!$('.wrapper-ajax-forms').length) { 178 return true; 179 } 180 e.preventDefault(); 181 if ($('.swal_form_tabs').length) { 182 $('.swal_form_tabs a').removeClass('active'); 183 $('.pop_login').addClass('active'); 184 } 185 186 var collegamento = ajax_auth_object.ajaxurl + '?action=getLoginForms'; 187 if ($('#popup-wrapper-ajax-auth #swal-login').length || $('#popup-wrapper-ajax-auth .wrapper-logout').length) { 188 189 openpopupauth(collegamento,false); 190 } 191 }); 192 193 /** 194 * 195 * Function to open Register Popup 196 * 197 */ 198 $('.sw-open-register').click(function(e) { 199 if (!$('.wrapper-ajax-forms').length) { 200 return true; 201 } 202 e.preventDefault(); 203 if ($('.swal_form_tabs').length) { 204 $('.swal_form_tabs a').removeClass('active'); 205 $('#pop_signup').addClass('active'); 206 } 207 var collegamento = ajax_auth_object.ajaxurl + '?action=getLoginForms'; 208 if ($('#popup-wrapper-ajax-auth #swal-register').length || $('#popup-wrapper-ajax-auth .wrapper-logout').length) { 209 210 OpenRegisterForm(); 211 openpopupauth(collegamento,false); 212 } 213 }); 214 215 /** 216 * 217 * Function to open Forgot Password Popup 218 * 219 */ 220 $('.sw-open-forgot-password').click(function(e) { 221 if (!$('.wrapper-ajax-forms').length) { 222 return true; 223 } 224 e.preventDefault(); 225 if ($('.swal_form_tabs').length) { 226 $('.swal_form_tabs a').removeClass('active'); 227 $('.pop_login').addClass('active'); 228 } 229 var collegamento = ajax_auth_object.ajaxurl + '?action=getLoginForms'; 230 if ($('#popup-wrapper-ajax-auth #forgot_password').length || $('#popup-wrapper-ajax-auth .wrapper-logout').length) { 231 232 OpenPasswordForm(); 233 openpopupauth(collegamento,false); 234 } 235 }); 236 237 238 /** 239 * 240 * Function to open Logout Popup 241 * 242 */
243 $('.swal-logout-menu-item,.open_logout,.woocommerce-MyAccount-navigation-link--customer-logout').click(function(e) { 244 e.preventDefault(); 245 var collegamento = ajax_auth_object.ajaxurl + '?action=getLoginForms'; 246 247 openpopupauth(collegamento,false); 248 249 }); 250 251 252 /** 253 * 254 * Avoid that popup closes if clicked inside it. 255 * 256 */ 257 $('body').on('click', '#popup-wrapper-ajax-auth', function(e) { 258 e.stopPropagation(); 259 }) 260 261/** 262* 263* On click to the links shows the selected form and hides all the others 264* 265*/ 266 $('body').on('click', '#sw-wrapper-ajax-login .pop_login, #sw-wrapper-ajax-login #pop_signup, #sw-wrapper-ajax-login #pop_forgot', function(e) { 267 e.preventDefault(); 268 formToFadeOut = ''; 269 formToFadeOut2 = ''; 270 formtoFadeIn = ''; 271 if ($('.swal_form_tabs').length) { 272 $('.swal_form_tabs a').removeClass('active'); 273 } 274 275 if ($(this).attr('class') == 'pop_login') { 276 if ($('.swal_form_tabs').length) { 277 $(this).addClass('active'); 278 } 279 formToFadeOut = $('#sw-wrapper-ajax-login #wrapper-forgot_password'); 280 if ($('#sw-wrapper-ajax-login #wrapper-register').length) { 281 formToFadeOut2 = $('#sw-wrapper-ajax-login #wrapper-register'); 282 } 283 formtoFadeIn = $('#sw-wrapper-ajax-login #wrapper-login'); 284 } 285 if ($(this).attr('id') == 'pop_signup') { 286 if ($('.swal_form_tabs').length) { 287 $(this).addClass('active'); 288 } 289 formToFadeOut = $('#sw-wrapper-ajax-login #wrapper-login'); 290 formToFadeOut2 = $('#sw-wrapper-ajax-login #wrapper-forgot_password'); 291 formtoFadeIn = $('#sw-wrapper-ajax-login #wrapper-register'); 292 } 293 if ($(this).attr('id') == 'pop_forgot') { 294 if ($('.swal_form_tabs').length) { 295 $('.pop_login').addClass('active'); 296 } 297 formToFadeOut = $('#sw-wrapper-ajax-login #wrapper-login'); 298 299 if ($('#sw-wrapper-ajax-login #wrapper-register').length) { 300 formToFadeOut2 = $('#sw-wrapper-ajax-login #wrapper-register'); 301 } 302 formtoFadeIn = $('#sw-wrapper-ajax-login #wrapper-forgot_password'); 303 } 304 if (formToFadeOut2) { 305 // Check if has to disable fade animation 306 if (ajax_auth_object.swal_disable_fade == 0) { 307 formToFadeOut2.fadeOut(300, function () { 308 formToFadeOut.fadeOut(300, function () { 309 formtoFadeIn.fadeIn(300); 310 }); 311 }); 312 } else { 313 formToFadeOut2.hide(); 314 formToFadeOut.hide(); 315 formtoFadeIn.show(); 316 } 317 318 } else { 319 formToFadeOut.fadeOut(300, function () { 320 formtoFadeIn.fadeIn(300); 321 }); 322 } 323 324 }); 325 326/** 327* 328* Set up login form as default form when the popup has been closed. 329* It avoids to show the other forms instead of login when it's opened again. 330*/ 331function OpenLoginForm() { 332 var formToFadeOut = $('#sw-wrapper-ajax-login #wrapper-register'); 333 var formToFadeOut2 = $('#sw-wrapper-ajax-login #wrapper-forgot_password'); 334 var formtoFadeIn = $('#sw-wrapper-ajax-login #wrapper-login'); 335 formToFadeOut.hide(); 336 formToFadeOut2.hide(); 337 formtoFadeIn.show(); 338} 339 340function OpenRegisterForm() { 341 var formToFadeOut = $('#sw-wrapper-ajax-login #wrapper-login'); 342 var formToFadeOut2 = $('#sw-wrapper-ajax-login #wrapper-forgot_password'); 343 var formtoFadeIn = $('#sw-wrapper-ajax-login #wrapper-register'); 344 formToFadeOut.hide(); 345 formToFadeOut2.hide(); 346 formtoFadeIn.show(); 347} 348function OpenPasswordForm() { 349 var formToFadeOut = $('#sw-wrapper-ajax-login #wrapper-login'); 350 var formToFadeOut2 = $('#sw-wrapper-ajax-login #wrapper-register'); 351 var formtoFadeIn = $('#sw-wrapper-ajax-login #wrapper-forgot_password'); 352 formToFadeOut.hide(); 353 formToFadeOut2.hide(); 354 formtoFadeIn.show(); 355} 356 357 358// Append the loader to the button or element with 'add-loader-onclick' on click. 359 360 $('body').on('click', '.add-loader-onclick', function() { 361 //$(this).attr("disabled", true).html("<span>"+txt_button_sending+"</span>"); 362 $(this).append("<div class='loading-css'></div>"); 363 }); 364 365 366 367/** 368 * 369 * Opens ajax modal popup 370 * 371 * @preload: true = preloads the page on the DOM but keeps it hidden 372 * 373 */ 374function openpopupauth(pagina,preload) { 375 376 var hide_class = ''; 377 378 recaptcha_version = $('#swal_recaptcha_register_version').val(); 379 380 // wrapper per il popop a pagina con larghezza definita 381 var tipowrapper = '<div id="popup-wrapper-ajax-auth"'+hide_class+'><div class="swal-loading-css-big"></div></div>'; 382 var divwrappage = '#popup-wrapper-ajax-auth'; 383
384 showOverlayAuth(preload); 385 386 //variabili 387 var $maschera = $(".login_overlay"); 388 389 //se nel DOM non è gia presente il div del popup lo aggiunge 390 if (!$(divwrappage).length) { 391 $maschera.append($(tipowrapper).hide().fadeIn(500)); 392 } 393 394 var $wrappage = $(divwrappage); 395 396 //se il form non è gia presente nella pagina web allora lo carica via ajax 397 if (!$('#sw-wrapper-ajax-login').length ) { 398 $wrappage.load(pagina, function() { 399 400 InitializeAjaxLoginForms(); 401 402 }).hide().fadeIn(500); 403 } else { 404 405 //InitializeAjaxLoginForms(); 406 if (recaptcha_version == '0') { 407 grecaptcha.reset(); 408 } 409 410 } 411 412 return false; 413} 414 415 416 417$('body').on('click', '.close-popup, div.login_overlay', function(e) { 418 e.preventDefault(); 419 hideOverlayAuth(); 420 }); 421 422//funzione chiudi popup 423function ClosePopup() { 424 $('#popup-wrapper-ajax-auth').fadeOut('slow', function (){ 425 $(this).remove(); 426 }); 427} 428 429 430/** 431 * 432 * Show & Hide overlay 433 * 434 */ 435 436function showOverlayAuth(preload) { 437 // if overlay div is not already on the DOM then adds it 438 if (!$('.login_overlay').length) { 439 $('body').prepend('<div class="login_overlay"></div>'); 440 } 441 // if preload is true doesn't do overlay fadein 442 if (!preload) { 443 $('body').css('overflow','hidden') 444 $('.login_overlay').hide().fadeIn(200); 445 } 446 } 447 448function hideOverlayAuth() { 449 $('div.login_overlay').fadeOut(300, function() { 450 //$(this).remove(); 451 $('body').css('overflow','auto'); 452 OpenLoginForm(); 453 }); 454 } 455 456 457/** 458 * 459 * Show Toast message 460 * 461 * @autofadeout: true = automatically fadeout the toast message after 2 seconds; 462 * 463 */ 464function showToast(testo,icona,autofadeout) { 465 466 fadeout = ''; 467 468 if (autofadeout) { 469 fadeout = ' fadeout'; 470 } 471 if ($(".swal-toast").length) { 472 $(".swal-toast").html(icona+testo); 473 if (autofadeout) { 474 $(".swal-toast").delay(2000).fadeOut("slow", function() { 475 $(this).remove(); 476 }); 477 } 478 } else { 479 $('body').append($('<div class="swal-toast'+fadeout+'">'+icona+testo+'</div>').hide().fadeIn('normal')); 480 $('.fadeout').delay(2000).fadeOut("slow", function() { 481 $(this).remove(); 482 }); 483 } 484 } 485 486 487/** 488 * 489 * Fadeout and remove Toast message 490 * 491 */ 492function hideToast() { 493 494 $('.swal-toast').fadeOut("slow", function() { 495 $(this).remove(); 496 }); 497 } 498 499/** 500 * 501 * Show message into a div 502 * 503 */ 504function showMessage(text,selector) { 505 506 if ($(selector).length) { 507 $(selector).html(nl2br(text)); 508 $(selector).hide().fadeIn('normal'); 509 } 510 } 511 512/** 513 * 514 * Escape line break 515 * 516 */ 517function nl2br (str, is_xhtml) { 518 var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br/>' : '<br>'; 519 return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2'); 520} 521 522/** 523 * 524 * Remove a parameter from form data 525 * 526 */ 527function RemoveParameterFromFormData( formData, name ) { 528 529 var newdata = formData.replace( new RegExp( `&${name}=[^&]*|${name}=[^&]*&` ), '' ); 530 531 return newdata; 532 } 533 534/** 535 * 536 * Show/Hide password 537 * 538 */ 539$('body').on('click','.swal-toggle-password', function (e) { 540 541 $(this).toggleClass("fa-eye fa-eye-slash"); 542 var input = $($(this).attr("toggle")); 543 if (input.attr("type") == "password") { 544 input.attr("type", "text"); 545 } else { 546 input.attr("type", "password"); 547 } 548}); 549 550 551/** 552 * 553 * Perform Logout 554 * 555 */ 556$('body').on('click','#logout-button', function (e) { 557 558 e.preventDefault(); 559 560 showToast(ajax_auth_object.logoutmessage,'<div class="swal-loading-css-big-relative"></div>',false); 561 document.location.href = ajax_auth_object.redirecturllogout; 562 ClosePopup(); 563 564}); 565 566 567/** 568 * 569 * Handle Ajax form submit 570 * 571 */ 572function HandleAjaxFormSubmit(action,redirect,dataForm,token) { 573 574 var submit = $("form#swal-login button, form#swal-register button"); 575 576 // disable button onsubmit to avoid double submision 577 submit.attr("disabled", "disabled").addClass('disabled'); 578 579 var recaptcha_version = $('#swal_recaptcha_register_version').val(); 580 581 // Compose dataForm with the extra fields 582 dataForm = dataForm + '&action='+action; 583 584 if (token != '') { 585 dataForm = dataForm +'&g-recaptcha-response='+token; 586 } 587 588 $.ajax({ 589 type: 'POST', 590 dataType: 'json', 591 url: ajax_auth_object.ajaxurl, 592 data: dataForm, 593 success: function (data) { 594 595 if (data.loggedin == true) { 596 showToast(data.message,'<i class="fa fa-check"></i>',true); 597 if (redirect) { 598 if (redirect == 'show_message') { 599 // show message 600 showMessage(ajax_auth_object.registermessage,'#swal_register_form_message'); 601 $('#swal_wrapper_register_fields').fadeOut('normal'); 602 603 // enable button 604 submit.removeAttr("disabled").removeClass('disabled'); 605 606 } else if (redirect == 'go_to_login') { 607 // show message 608 showMessage(ajax_auth_object.registermessage,'#swal_login_form_message'); 609 // enable button 610 submit.removeAttr("disabled").removeClass('disabled'); 611 OpenLoginForm(); 612 613 } else { 614 document.location = redirect; 615 ClosePopup(); 616 } 617 618 } else { 619 document.location = ajax_auth_object.redirecturl; 620 ClosePopup(); 621 } 622 623 } else { 624 if (recaptcha_version == '0') { 625 grecaptcha.reset(); 626 } 627 if (data.message == '2fa_required') { 628 629 // show 2fa field and hide username and password fields 630 manage2faInputFields(); 631 } else { 632 showToast(data.message,'<i class="fa fa-exclamation"></i>',true); 633 634 } 635 submit.removeAttr("disabled").removeClass('disabled'); 636 637 } 638 } 639 }); // close $.ajax 640 641 return false;
642} 643 644 645/** 646 * 647 * Perform AJAX login/register on form submit 648 * 649 */ 650function InitializeAjaxLoginSubmit() { 651 652 $('form#swal-login, form#swal-register').on('submit', function (e) { 653 654 e.preventDefault(); 655 656 if (!$(this).valid()) return false; 657 658 if($(this).find('input[name="action"]').val() == 'update-user' ){ 659 this.submit(); 660 return; 661 } 662 663 664 showToast(ajax_auth_object.loadingmessage,'<div class="swal-loading-css-big-relative"></div>',false); 665 666 action = ''; 667 recaptcha_version = ''; 668 token = ''; 669 redirect = ''; 670 671 // Remove the action parameter from data form, it will be added later 672 var dataForm = RemoveParameterFromFormData( $(this).serialize(), 'action' ); 673 674 if ($(this).attr('id') == 'swal-login') { 675 676 action = 'ajaxlogin'; 677 redirect = $('form#swal-login #redirect_to').val(); 678 679 // Submit for via Ajax 680 HandleAjaxFormSubmit(action,redirect,dataForm,token); 681 682 683 } else if ($(this).attr('id') == 'swal-register') { 684 685 action = 'ajaxregister'; 686 recaptcha_version = $('#swal_recaptcha_register_version').val(); 687 redirect = $('form#swal-register #swal_register_page_to_redirect').val(); 688 689 // reCAPTCHA enabled 690 if (ajax_auth_object.enablerecaptcha == '1') { 691 692 if (recaptcha_version == '1') { 693 694 // reCAPTCHA v3 695 grecaptcha.ready(function() { 696 grecaptcha.execute(ajax_auth_object.recaptchakey, {action: 'register'}).then(function(token) { 697 698 // add token to the hidden field 699 //$('#swal_recaptcha_register').val(token); 700 701 // Submit form via Ajax 702 HandleAjaxFormSubmit(action,redirect,dataForm,token); 703 704 }); 705 }); 706 } else if (recaptcha_version == '0') { 707 708 // reCAPTCHA v2 709 HandleAjaxFormSubmit(action,redirect,dataForm,token); 710 } 711 } else { 712 // reCAPTCHA not enabled 713 714 // Submit form via Ajax without reCAPTCHA control 715 HandleAjaxFormSubmit(action,redirect,dataForm,token); 716 } 717 } 718 719 }); 720 721 722 /** 723 * 724 * Perform AJAX forgot password on form submit 725 * 726 */ 727 $('form#forgot_password').on('submit', function(e){ 728 729 e.preventDefault(); 730 731 if (!$(this).valid()) return false; 732 733 showToast(ajax_auth_object.loadingmessage,'<div class="swal-loading-css-big-relative"></div>',false); 734 735 $('p.status').fadeOut('normal'); 736 737 var submit = $("#forgot_password button"); 738 739 // disable button onsubmit to avoid double submision 740 submit.attr("disabled", "disabled").addClass('disabled'); 741 742 form = $(this); 743 $.ajax({ 744 type: 'POST', 745 dataType: 'json', 746 url: ajax_auth_object.ajaxurl, 747 data: { 748 'action': 'ajaxforgotpassword', 749 'user_login': $('#user_login').val(), 750 'security': $('#forgotsecurity').val(), 751 }, 752 success: function(data){ 753 754 if (data.loggedin == true) { 755 showToast(data.message,'<i class="fa fa-check"></i>',true); 756 } else { 757 showToast(data.message,'<i class="fa fa-exclamation"></i>',true); 758 } 759 submit.removeAttr("disabled").removeClass('disabled'); 760 } 761 }); 762 763 return false; 764 }); 765 766 767 /** 768 * 769 * Perform AJAX reset password 770 * 771 */ 772 $("form#resetPasswordForm").on('submit', function(e){ 773 774 e.preventDefault(); 775 776 if (!$(this).valid()) return false; 777 778 showToast(ajax_auth_object.loadingmessage,'<div class="swal-loading-css-big-relative"></div>',false); 779 780 var submit = $("div#resetPassword #wp-submit"), 781 message = $("div#resetPassword #message"); 782 783 784 // disable button onsubmit to avoid double submision 785 submit.attr("disabled", "disabled").addClass('disabled'); 786 message.fadeOut(200); 787 788 $.ajax({ 789 type: 'POST', 790 dataType: 'json', 791 url: ajax_auth_object.ajaxurl, 792 data: { 793 'action': 'reset_pass', 794 'resetsecurity': $('#resetsecurity').val(), 795 'pass1': $('#pass1').val(), 796 'pass2': $('#pass2').val(), 797 'user_key': $('#user_key').val(), 798 'user_login_reset': $('#user_login_reset').val(), 799 }, 800 success: function(data){ 801 802 submit.removeAttr("disabled").removeClass('disabled'); 803 804 if (data.loggedin == true) { 805 showToast(data.message,'<i class="fa fa-check"></i>',false); 806 document.location.href = ajax_auth_object.redirecturllogin+'/?password=changed'; 807 } else { 808 //showToast(data.message,'<i class="fa fa-exclamation"></i>',true); 809 $('html, body').stop().animate({ 810 scrollTop: $('[id="message"]').offset().top -100 811 }, 500); 812 // display return data only for errors 813 message.html( data.message ).fadeIn('normal'); 814 hideToast(); 815 } 816 817 }, 818 error: function () { 819 showToast(ajax_auth_object.facebook_error_2,'<i class="fa fa-exclamation"></i>',true); 820 submit.removeAttr("disabled").removeClass('disabled'); 821 } 822 }); 823 824 return false;
825 }); 826 827 828 829 /** 830 * Password strength function 831 */ 832 function checkPasswordStrength( $pass1, 833 $pass2, 834 $strengthResult, 835 $submitButton, 836 blacklistArray ) { 837 var pass1 = $pass1.val(); 838 var pass2 = $pass2.val(); 839 840 // Reset the form & meter 841 $submitButton.attr( 'disabled', 'disabled' ); 842 $strengthResult.removeClass( 'short bad good strong' ); 843 844 // Extend our blacklist array with those from the inputs & site data 845 blacklistArray = blacklistArray.concat( wp.passwordStrength.userInputBlacklist() ) 846 847 // Get the password strength 848 var strength = wp.passwordStrength.meter( pass1, blacklistArray, pass2 ); 849 850 // Add the strength meter results 851 switch ( strength ) { 852 853 case 2: 854 $strengthResult.addClass( 'bad' ).html( pwsL10n.bad ); 855 break; 856 857 case 3: 858 $strengthResult.addClass( 'good' ).html( pwsL10n.good ); 859 break; 860 861 case 4: 862 $strengthResult.addClass( 'strong' ).html( pwsL10n.strong ); 863 break; 864 865 case 5: 866 $strengthResult.addClass( 'short' ).html( pwsL10n.mismatch ); 867 break; 868 869 default: 870 $strengthResult.addClass( 'short' ).html( pwsL10n.short ); 871 872 } 873 874 // The meter function returns a result even if pass2 is empty, 875 // enable only the submit button if the password is strong and 876 // both passwords are filled up 877 if ( 4 === strength && '' !== pass2.trim() ) { 878 $submitButton.removeAttr( 'disabled' ); 879 } 880 881 return strength; 882 } 883 884 /** 885 * 886 * Perform password check 887 * 888 */ 889 $( 'body' ).on( 'keyup', 'input[name=pass1], input[name=pass2]', 890 function( event ) { 891 checkPasswordStrength( 892 $('input[name=pass1]'), // First password field 893 $('input[name=pass2]'), // Second password field 894 $('#password-strength'), // Strength meter 895 $('input[type=submit]'), // Submit button 896 ['black', 'listed', 'word'] // Blacklisted words 897 ); 898 }); 899 900 901 /** 902 * 903 * Client side form validation 904 * 905 */ 906 if (jQuery("#swal-register").length) 907 jQuery("#swal-register").validate({ 908 rules:{ 909 password2:{ equalTo:'#signonpassword'} 910 } 911 }); 912 913 if (jQuery("#resetPasswordForm").length) { 914 jQuery("#resetPasswordForm").validate({ 915 rules:{ 916 pass2:{ equalTo:'#pass1'} 917 } 918 }); 919 } 920 else if (jQuery("#swal-login").length) 921 jQuery("#swal-login").validate(); 922 923 if(jQuery('#forgot_password').length) 924 jQuery('#forgot_password').validate(); 925 926} // close InitializeAjaxLoginSubmit function 927 928 929 930 /** 931 * 932 * reset login form. remove 2fa field and show username and password fielfds 933 * 934 */ 935 function manage2faInputFields() { 936 937 var field = '<label for="username">'+ajax_auth_object.swal_2fa_label+'</label><div><input type="text" id="swal_2fa_code" name="swal_2fa_code" class="required" autocomplete="off"/><a href="#" class="swal_reset_2fa"><i class="fa fa-arrow-left" aria-hidden="true"></i> '+ajax_auth_object.swal_2fa_back+'</a></div>'; 938 939 if ($('.swal_2fa_wrapper').length ) { 940 $('.swal-login-fields').hide(); 941 $('.swal_2fa_wrapper').append(field).hide().fadeIn(500); 942 hideToast(); 943 } 944 } 945 946 /** 947 * 948 * Hide username and password fields and show 2fa field 949 * 950 */ 951 952 $('body').on('click','.swal_reset_2fa', function(e) { 953 954 e.preventDefault(); 955 956 $('.swal_2fa_wrapper').empty(); 957 $('#swal_2fa_code').attr('value', ''); 958 $('#password').attr('value', ''); 959 $('.swal-login-fields').fadeIn(500); 960 }); 961 962 963 964}); 965 966function InitializeRecaptcha() { 967 968 if (jQuery('.g-recaptcha').length) { 969 var sitekey = jQuery('.g-recaptcha').data('sitekey'); 970 var captchaWidgetId = grecaptcha.render( 'myCaptcha', { 971 'sitekey' : sitekey, 972 'theme' : ajax_auth_object.recaptchatheme, 973 }); 974 } 975}
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.