author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
9 | 1 |
/** |
2 |
* @output wp-admin/js/user-profile.js |
|
3 |
*/ |
|
4 |
||
18 | 5 |
/* global ajaxurl, pwsL10n, userProfileL10n */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
(function($) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
var updateLock = false, |
16 | 8 |
__ = wp.i18n.__, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
9 |
$pass1Row, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
$pass1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
$pass2, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
$weakRow, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
$weakCheckbox, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
$toggleButton, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
$submitButtons, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
$submitButton, |
18 | 17 |
currentPass, |
18 |
$passwordWrapper; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
function generatePassword() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
if ( typeof zxcvbn !== 'function' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
setTimeout( generatePassword, 50 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
return; |
18 | 24 |
} else if ( ! $pass1.val() || $passwordWrapper.hasClass( 'is-open' ) ) { |
25 |
// zxcvbn loaded before user entered password, or generating new password. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
$pass1.val( $pass1.data( 'pw' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
$pass1.trigger( 'pwupdate' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
showOrHideWeakPasswordCheckbox(); |
18 | 29 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
// zxcvbn loaded after the user entered password, check strength. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
check_pass_strength(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
showOrHideWeakPasswordCheckbox(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
|
19 | 35 |
/* |
36 |
* This works around a race condition when zxcvbn loads quickly and |
|
37 |
* causes `generatePassword()` to run prior to the toggle button being |
|
38 |
* bound. |
|
39 |
*/ |
|
40 |
bindToggleButton(); |
|
41 |
||
18 | 42 |
// Install screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) { |
18 | 44 |
// Show the password not masked if admin_password hasn't been posted yet. |
16 | 45 |
$pass1.attr( 'type', 'text' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
} else { |
18 | 47 |
// Otherwise, mask the password. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
$toggleButton.trigger( 'click' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
// Once zxcvbn loads, passwords strength is known. |
16 | 52 |
$( '#pw-weak-text-label' ).text( __( 'Confirm use of weak password' ) ); |
19 | 53 |
|
54 |
// Focus the password field. |
|
55 |
$( $pass1 ).trigger( 'focus' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
function bindPass1() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
currentPass = $pass1.val(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
if ( 1 === parseInt( $pass1.data( 'reveal' ), 10 ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
generatePassword(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
|
9 | 65 |
$pass1.on( 'input' + ' pwupdate', function () { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
if ( $pass1.val() === currentPass ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
currentPass = $pass1.val(); |
16 | 71 |
|
18 | 72 |
// Refresh password strength area. |
16 | 73 |
$pass1.removeClass( 'short bad good strong' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
showOrHideWeakPasswordCheckbox(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
|
16 | 78 |
function resetToggle( show ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
$toggleButton |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
.attr({ |
16 | 81 |
'aria-label': show ? __( 'Show password' ) : __( 'Hide password' ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
}) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
.find( '.text' ) |
16 | 84 |
.text( show ? __( 'Show' ) : __( 'Hide' ) ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
.end() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
.find( '.dashicons' ) |
16 | 87 |
.removeClass( show ? 'dashicons-hidden' : 'dashicons-visibility' ) |
88 |
.addClass( show ? 'dashicons-visibility' : 'dashicons-hidden' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
function bindToggleButton() { |
19 | 92 |
if ( !! $toggleButton ) { |
93 |
// Do not rebind. |
|
94 |
return; |
|
95 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
$toggleButton = $pass1Row.find('.wp-hide-pw'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
$toggleButton.show().on( 'click', function () { |
16 | 98 |
if ( 'password' === $pass1.attr( 'type' ) ) { |
99 |
$pass1.attr( 'type', 'text' ); |
|
100 |
resetToggle( false ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
} else { |
16 | 102 |
$pass1.attr( 'type', 'password' ); |
103 |
resetToggle( true ); |
|
104 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
|
18 | 108 |
/** |
109 |
* Handle the password reset button. Sets up an ajax callback to trigger sending |
|
110 |
* a password reset email. |
|
111 |
*/ |
|
19 | 112 |
function bindPasswordResetLink() { |
18 | 113 |
$( '#generate-reset-link' ).on( 'click', function() { |
114 |
var $this = $(this), |
|
115 |
data = { |
|
116 |
'user_id': userProfileL10n.user_id, // The user to send a reset to. |
|
117 |
'nonce': userProfileL10n.nonce // Nonce to validate the action. |
|
118 |
}; |
|
119 |
||
120 |
// Remove any previous error messages. |
|
121 |
$this.parent().find( '.notice-error' ).remove(); |
|
122 |
||
123 |
// Send the reset request. |
|
124 |
var resetAction = wp.ajax.post( 'send-password-reset', data ); |
|
125 |
||
126 |
// Handle reset success. |
|
127 |
resetAction.done( function( response ) { |
|
128 |
addInlineNotice( $this, true, response ); |
|
129 |
} ); |
|
130 |
||
131 |
// Handle reset failure. |
|
132 |
resetAction.fail( function( response ) { |
|
133 |
addInlineNotice( $this, false, response ); |
|
134 |
} ); |
|
135 |
||
136 |
}); |
|
137 |
||
138 |
} |
|
139 |
||
140 |
/** |
|
141 |
* Helper function to insert an inline notice of success or failure. |
|
142 |
* |
|
143 |
* @param {jQuery Object} $this The button element: the message will be inserted |
|
144 |
* above this button |
|
145 |
* @param {bool} success Whether the message is a success message. |
|
146 |
* @param {string} message The message to insert. |
|
147 |
*/ |
|
148 |
function addInlineNotice( $this, success, message ) { |
|
149 |
var resultDiv = $( '<div />' ); |
|
150 |
||
151 |
// Set up the notice div. |
|
152 |
resultDiv.addClass( 'notice inline' ); |
|
153 |
||
154 |
// Add a class indicating success or failure. |
|
155 |
resultDiv.addClass( 'notice-' + ( success ? 'success' : 'error' ) ); |
|
156 |
||
157 |
// Add the message, wrapping in a p tag, with a fadein to highlight each message. |
|
158 |
resultDiv.text( $( $.parseHTML( message ) ).text() ).wrapInner( '<p />'); |
|
159 |
||
160 |
// Disable the button when the callback has succeeded. |
|
161 |
$this.prop( 'disabled', success ); |
|
162 |
||
163 |
// Remove any previous notices. |
|
164 |
$this.siblings( '.notice' ).remove(); |
|
165 |
||
166 |
// Insert the notice. |
|
167 |
$this.before( resultDiv ); |
|
168 |
} |
|
169 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
function bindPasswordForm() { |
18 | 171 |
var $generateButton, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
$cancelButton; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
|
18 | 174 |
$pass1Row = $( '.user-pass1-wrap, .user-pass-wrap, .reset-pass-submit' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
|
16 | 176 |
// Hide the confirm password field when JavaScript support is enabled. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
$('.user-pass2-wrap').hide(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
$submitButton = $( '#submit, #wp-submit' ).on( 'click', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
updateLock = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
$submitButtons = $submitButton.add( ' #createusersub' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
$weakRow = $( '.pw-weak' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
$weakCheckbox = $weakRow.find( '.pw-checkbox' ); |
18 | 187 |
$weakCheckbox.on( 'change', function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
$submitButtons.prop( 'disabled', ! $weakCheckbox.prop( 'checked' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
$pass1 = $('#pass1'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
if ( $pass1.length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
bindPass1(); |
16 | 194 |
} else { |
195 |
// Password field for the login form. |
|
196 |
$pass1 = $( '#user_pass' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
|
18 | 199 |
/* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
* Fix a LastPass mismatch issue, LastPass only changes pass2. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
* This fixes the issue by copying any changes from the hidden |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
* pass2 field to the pass1 field, then running check_pass_strength. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
*/ |
9 | 205 |
$pass2 = $( '#pass2' ).on( 'input', function () { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
if ( $pass2.val().length > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
$pass1.val( $pass2.val() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
$pass2.val(''); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
currentPass = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
$pass1.trigger( 'pwupdate' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
// Disable hidden inputs to prevent autofill and submission. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
if ( $pass1.is( ':hidden' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
$pass1.prop( 'disabled', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
$pass2.prop( 'disabled', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
$passwordWrapper = $pass1Row.find( '.wp-pwd' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
$generateButton = $pass1Row.find( 'button.wp-generate-pw' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
bindToggleButton(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
$generateButton.show(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
$generateButton.on( 'click', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
updateLock = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
|
18 | 229 |
// Make sure the password fields are shown. |
19 | 230 |
$generateButton.not( '.skip-aria-expanded' ).attr( 'aria-expanded', 'true' ); |
18 | 231 |
$passwordWrapper |
232 |
.show() |
|
233 |
.addClass( 'is-open' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
// Enable the inputs when showing. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
$pass1.attr( 'disabled', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
$pass2.attr( 'disabled', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
|
18 | 239 |
// Set the password to the generated value. |
240 |
generatePassword(); |
|
241 |
||
242 |
// Show generated password in plaintext by default. |
|
243 |
resetToggle ( false ); |
|
244 |
||
245 |
// Generate the next password and cache. |
|
246 |
wp.ajax.post( 'generate-password' ) |
|
247 |
.done( function( data ) { |
|
248 |
$pass1.data( 'pw', data ); |
|
249 |
} ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
$cancelButton = $pass1Row.find( 'button.wp-cancel-pw' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
$cancelButton.on( 'click', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
updateLock = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
// Disable the inputs when hiding to prevent autofill and submission. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
$pass1.prop( 'disabled', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
$pass2.prop( 'disabled', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
|
18 | 260 |
// Clear password field and update the UI. |
261 |
$pass1.val( '' ).trigger( 'pwupdate' ); |
|
16 | 262 |
resetToggle( false ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
|
18 | 264 |
// Hide password controls. |
265 |
$passwordWrapper |
|
266 |
.hide() |
|
267 |
.removeClass( 'is-open' ); |
|
268 |
||
269 |
// Stop an empty password from being submitted as a change. |
|
270 |
$submitButtons.prop( 'disabled', false ); |
|
19 | 271 |
|
272 |
$generateButton.attr( 'aria-expanded', 'false' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
$pass1Row.closest( 'form' ).on( 'submit', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
updateLock = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
$pass1.prop( 'disabled', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
$pass2.prop( 'disabled', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
$pass2.val( $pass1.val() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
} |
0 | 283 |
|
284 |
function check_pass_strength() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
var pass1 = $('#pass1').val(), strength; |
0 | 286 |
|
16 | 287 |
$('#pass-strength-result').removeClass('short bad good strong empty'); |
18 | 288 |
if ( ! pass1 || '' === pass1.trim() ) { |
16 | 289 |
$( '#pass-strength-result' ).addClass( 'empty' ).html( ' ' ); |
0 | 290 |
return; |
291 |
} |
|
292 |
||
16 | 293 |
strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputDisallowedList(), pass1 ); |
0 | 294 |
|
295 |
switch ( strength ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
case -1: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
$( '#pass-strength-result' ).addClass( 'bad' ).html( pwsL10n.unknown ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
break; |
0 | 299 |
case 2: |
5 | 300 |
$('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); |
0 | 301 |
break; |
302 |
case 3: |
|
5 | 303 |
$('#pass-strength-result').addClass('good').html( pwsL10n.good ); |
0 | 304 |
break; |
305 |
case 4: |
|
5 | 306 |
$('#pass-strength-result').addClass('strong').html( pwsL10n.strong ); |
0 | 307 |
break; |
308 |
case 5: |
|
5 | 309 |
$('#pass-strength-result').addClass('short').html( pwsL10n.mismatch ); |
0 | 310 |
break; |
311 |
default: |
|
312 |
$('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); |
|
313 |
} |
|
314 |
} |
|
315 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
function showOrHideWeakPasswordCheckbox() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
var passStrength = $('#pass-strength-result')[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
if ( passStrength.className ) { |
16 | 320 |
$pass1.addClass( passStrength.className ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
if ( $( passStrength ).is( '.short, .bad' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
if ( ! $weakCheckbox.prop( 'checked' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
$submitButtons.prop( 'disabled', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
$weakRow.show(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
} else { |
16 | 327 |
if ( $( passStrength ).is( '.empty' ) ) { |
328 |
$submitButtons.prop( 'disabled', true ); |
|
329 |
$weakCheckbox.prop( 'checked', false ); |
|
330 |
} else { |
|
331 |
$submitButtons.prop( 'disabled', false ); |
|
332 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
$weakRow.hide(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
|
18 | 338 |
$( function() { |
5 | 339 |
var $colorpicker, $stylesheet, user_id, current_user_id, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
select = $( '#display_name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
current_name = select.val(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
greeting = $( '#wp-admin-bar-my-account' ).find( '.display-name' ); |
0 | 343 |
|
9 | 344 |
$( '#pass1' ).val( '' ).on( 'input' + ' pwupdate', check_pass_strength ); |
0 | 345 |
$('#pass-strength-result').show(); |
18 | 346 |
$('.color-palette').on( 'click', function() { |
0 | 347 |
$(this).siblings('input[name="admin_color"]').prop('checked', true); |
348 |
}); |
|
349 |
||
350 |
if ( select.length ) { |
|
18 | 351 |
$('#first_name, #last_name, #nickname').on( 'blur.user_profile', function() { |
0 | 352 |
var dub = [], |
353 |
inputs = { |
|
354 |
display_nickname : $('#nickname').val() || '', |
|
355 |
display_username : $('#user_login').val() || '', |
|
356 |
display_firstname : $('#first_name').val() || '', |
|
357 |
display_lastname : $('#last_name').val() || '' |
|
358 |
}; |
|
359 |
||
360 |
if ( inputs.display_firstname && inputs.display_lastname ) { |
|
5 | 361 |
inputs.display_firstlast = inputs.display_firstname + ' ' + inputs.display_lastname; |
362 |
inputs.display_lastfirst = inputs.display_lastname + ' ' + inputs.display_firstname; |
|
0 | 363 |
} |
364 |
||
365 |
$.each( $('option', select), function( i, el ){ |
|
366 |
dub.push( el.value ); |
|
367 |
}); |
|
368 |
||
369 |
$.each(inputs, function( id, value ) { |
|
5 | 370 |
if ( ! value ) { |
0 | 371 |
return; |
5 | 372 |
} |
0 | 373 |
|
374 |
var val = value.replace(/<\/?[a-z][^>]*>/gi, ''); |
|
375 |
||
5 | 376 |
if ( inputs[id].length && $.inArray( val, dub ) === -1 ) { |
0 | 377 |
dub.push(val); |
378 |
$('<option />', { |
|
379 |
'text': val |
|
380 |
}).appendTo( select ); |
|
381 |
} |
|
382 |
}); |
|
383 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* Replaces "Howdy, *" in the admin toolbar whenever the display name dropdown is updated for one's own profile. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
select.on( 'change', function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
if ( user_id !== current_user_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
|
18 | 393 |
var display_name = this.value.trim() || current_name; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
greeting.text( display_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
} ); |
0 | 397 |
} |
5 | 398 |
|
399 |
$colorpicker = $( '#color-picker' ); |
|
400 |
$stylesheet = $( '#colors-css' ); |
|
401 |
user_id = $( 'input#user_id' ).val(); |
|
402 |
current_user_id = $( 'input[name="checkuser_id"]' ).val(); |
|
403 |
||
404 |
$colorpicker.on( 'click.colorpicker', '.color-option', function() { |
|
405 |
var colors, |
|
406 |
$this = $(this); |
|
407 |
||
408 |
if ( $this.hasClass( 'selected' ) ) { |
|
409 |
return; |
|
410 |
} |
|
411 |
||
412 |
$this.siblings( '.selected' ).removeClass( 'selected' ); |
|
413 |
$this.addClass( 'selected' ).find( 'input[type="radio"]' ).prop( 'checked', true ); |
|
414 |
||
16 | 415 |
// Set color scheme. |
5 | 416 |
if ( user_id === current_user_id ) { |
417 |
// Load the colors stylesheet. |
|
418 |
// The default color scheme won't have one, so we'll need to create an element. |
|
419 |
if ( 0 === $stylesheet.length ) { |
|
420 |
$stylesheet = $( '<link rel="stylesheet" />' ).appendTo( 'head' ); |
|
421 |
} |
|
422 |
$stylesheet.attr( 'href', $this.children( '.css_url' ).val() ); |
|
423 |
||
16 | 424 |
// Repaint icons. |
5 | 425 |
if ( typeof wp !== 'undefined' && wp.svgPainter ) { |
426 |
try { |
|
18 | 427 |
colors = JSON.parse( $this.children( '.icon_colors' ).val() ); |
5 | 428 |
} catch ( error ) {} |
429 |
||
430 |
if ( colors ) { |
|
431 |
wp.svgPainter.setColors( colors ); |
|
432 |
wp.svgPainter.paint(); |
|
433 |
} |
|
434 |
} |
|
435 |
||
16 | 436 |
// Update user option. |
5 | 437 |
$.post( ajaxurl, { |
438 |
action: 'save-user-color-scheme', |
|
439 |
color_scheme: $this.children( 'input[name="admin_color"]' ).val(), |
|
440 |
nonce: $('#color-nonce').val() |
|
441 |
}).done( function( response ) { |
|
442 |
if ( response.success ) { |
|
443 |
$( 'body' ).removeClass( response.data.previousScheme ).addClass( response.data.currentScheme ); |
|
444 |
} |
|
445 |
}); |
|
446 |
} |
|
447 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
bindPasswordForm(); |
19 | 450 |
bindPasswordResetLink(); |
5 | 451 |
}); |
452 |
||
453 |
$( '#destroy-sessions' ).on( 'click', function( e ) { |
|
454 |
var $this = $(this); |
|
455 |
||
456 |
wp.ajax.post( 'destroy-sessions', { |
|
457 |
nonce: $( '#_wpnonce' ).val(), |
|
458 |
user_id: $( '#user_id' ).val() |
|
459 |
}).done( function( response ) { |
|
460 |
$this.prop( 'disabled', true ); |
|
461 |
$this.siblings( '.notice' ).remove(); |
|
462 |
$this.before( '<div class="notice notice-success inline"><p>' + response.message + '</p></div>' ); |
|
463 |
}).fail( function( response ) { |
|
464 |
$this.siblings( '.notice' ).remove(); |
|
465 |
$this.before( '<div class="notice notice-error inline"><p>' + response.message + '</p></div>' ); |
|
466 |
}); |
|
467 |
||
468 |
e.preventDefault(); |
|
0 | 469 |
}); |
470 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
window.generatePassword = generatePassword; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
|
18 | 473 |
// Warn the user if password was generated but not saved. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
$( window ).on( 'beforeunload', function () { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
if ( true === updateLock ) { |
16 | 476 |
return __( 'Your new password has not been saved.' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
} ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
|
18 | 480 |
/* |
481 |
* We need to generate a password as soon as the Reset Password page is loaded, |
|
482 |
* to avoid double clicking the button to retrieve the first generated password. |
|
483 |
* See ticket #39638. |
|
484 |
*/ |
|
485 |
$( function() { |
|
486 |
if ( $( '.reset-pass-submit' ).length ) { |
|
487 |
$( '.reset-pass-submit button.wp-generate-pw' ).trigger( 'click' ); |
|
488 |
} |
|
489 |
}); |
|
490 |
||
0 | 491 |
})(jQuery); |