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