X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/03f2fa83c13c1b532284205fa7efcab9b8b2c41f..4ea0dca21bda49aab5ccb91ec12bb4ef5924ed3e:/wp-admin/js/user-profile.js diff --git a/wp-admin/js/user-profile.js b/wp-admin/js/user-profile.js index 52508448..650fbd5d 100644 --- a/wp-admin/js/user-profile.js +++ b/wp-admin/js/user-profile.js @@ -30,20 +30,30 @@ function generatePassword() { if ( typeof zxcvbn !== 'function' ) { setTimeout( generatePassword, 50 ); - } else { + return; + } else if ( ! $pass1.val() ) { + // zxcvbn loaded before user entered password. $pass1.val( $pass1.data( 'pw' ) ); - $pass1.trigger( 'pwupdate' ).trigger( 'wp-check-valid-field' ); - if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) { - $pass1Wrap.addClass( 'show-password' ); - } else { - $toggleButton.trigger( 'click' ); - } + $pass1.trigger( 'pwupdate' ); + showOrHideWeakPasswordCheckbox(); + } + else { + // zxcvbn loaded after the user entered password, check strength. + check_pass_strength(); + showOrHideWeakPasswordCheckbox(); + } + + if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) { + $pass1Wrap.addClass( 'show-password' ); + } else { + $toggleButton.trigger( 'click' ); } + + // Once zxcvbn loads, passwords strength is known. + $( '#pw-weak-text-label' ).html( userProfileL10n.warnWeak ); } function bindPass1() { - var passStrength = $('#pass-strength-result')[0]; - currentPass = $pass1.val(); $pass1Wrap = $pass1.parent(); @@ -82,19 +92,7 @@ $pass1Text.val( currentPass ); } $pass1.add( $pass1Text ).removeClass( 'short bad good strong' ); - - if ( passStrength.className ) { - $pass1.add( $pass1Text ).addClass( passStrength.className ); - if ( 'short' === passStrength.className || 'bad' === passStrength.className ) { - if ( ! $weakCheckbox.prop( 'checked' ) ) { - $submitButtons.prop( 'disabled', true ); - } - $weakRow.show(); - } else { - $submitButtons.prop( 'disabled', false ); - $weakRow.hide(); - } - } + showOrHideWeakPasswordCheckbox(); } ); } @@ -251,6 +249,10 @@ $generateButton.show(); $passwordWrapper.hide(); + $weakRow.hide( 0, function () { + $weakCheckbox.removeProp( 'checked' ); + } ); + // Disable the inputs when hiding to prevent autofill and submission. $pass1.prop( 'disabled', true ); $pass2.prop( 'disabled', true ); @@ -258,12 +260,14 @@ resetToggle(); - // Clear password field to prevent update - $pass1.val( '' ).trigger( 'pwupdate' ); - $submitButtons.prop( 'disabled', false ); + if ( $pass1Row.closest( 'form' ).is( '#your-profile' ) ) { + // Clear password field to prevent update + $pass1.val( '' ).trigger( 'pwupdate' ); + $submitButtons.prop( 'disabled', false ); + } } ); - $pass1Row.closest('form').on( 'submit', function () { + $pass1Row.closest( 'form' ).on( 'submit', function () { updateLock = false; $pass1.prop( 'disabled', false ); @@ -285,6 +289,9 @@ strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 ); switch ( strength ) { + case -1: + $( '#pass-strength-result' ).addClass( 'bad' ).html( pwsL10n.unknown ); + break; case 2: $('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); break; @@ -302,6 +309,23 @@ } } + function showOrHideWeakPasswordCheckbox() { + var passStrength = $('#pass-strength-result')[0]; + + if ( passStrength.className ) { + $pass1.add( $pass1Text ).addClass( passStrength.className ); + if ( 'short' === passStrength.className || 'bad' === passStrength.className ) { + if ( ! $weakCheckbox.prop( 'checked' ) ) { + $submitButtons.prop( 'disabled', true ); + } + $weakRow.show(); + } else { + $submitButtons.prop( 'disabled', false ); + $weakRow.hide(); + } + } + } + $(document).ready( function() { var $colorpicker, $stylesheet, user_id, current_user_id, select = $( '#display_name' );