Debian Codegraph @

resources/src/mediawiki.misc-authed-ooui/special.changecredentials.js

raw symbols SCIP
1 /*!
2 * JavaScript for change credentials form.
3 */
4 ( function () {
5 mw.hook( 'htmlform.enhance' ).add( ( $root ) => {
6 const api = new mw.Api();
7
8 $root.find( '.mw-changecredentials-validate-password.oo-ui-fieldLayout' ).each( function () {
9 const self = OO.ui.FieldLayout.static.infuse( $( this ) );
10
11 let currentApiPromise;
12 self.getField().setValidation( ( passwordValue ) => {
13 if ( currentApiPromise ) {
14 currentApiPromise.abort();
15 currentApiPromise = undefined;
16 }
17
18 passwordValue = passwordValue.trim();
19
20 if ( passwordValue === '' ) {
21 self.setErrors( [] );
22 return true;
23 }
24
25 const d = $.Deferred();
26 currentApiPromise = api.post( {
27 action: 'validatepassword',
28 password: passwordValue,
29 formatversion: 2,
30 errorformat: 'html',
31 errorsuselocal: true,
32 uselang: mw.config.get( 'wgUserLanguage' )
33 } ).done( ( resp ) => {
34 const pwinfo = resp.validatepassword,
35 good = pwinfo.validity === 'Good';
36
37 currentApiPromise = undefined;
38
39 let errors;
40 if ( !good ) {
41 errors = pwinfo.validitymessages.map( ( m ) => new OO.ui.HtmlSnippet( m.html ) );
42 }
43 self.setErrors( errors || [] );
44 d.resolve( good );
45 } ).fail( d.reject );
46
47 return d.promise( { abort: currentApiPromise.abort } );
48 } );
49 } );
50 } );
51 }() );