Merge "phpunit: Don't override --bootstrap if supplied"
[mediawiki.git] / resources / src / mediawiki.misc-authed-ooui / special.changecredentials.js
blob8dac4bf626e91a171833411870793cd6c799a417
1 /*!
2  * JavaScript for change credentials form.
3  */
4 ( function () {
5         mw.hook( 'htmlform.enhance' ).add( ( $root ) => {
6                 const api = new mw.Api();
8                 $root.find( '.mw-changecredentials-validate-password.oo-ui-fieldLayout' ).each( function () {
9                         const self = OO.ui.FieldLayout.static.infuse( $( this ) );
11                         let currentApiPromise;
12                         self.getField().setValidation( ( passwordValue ) => {
13                                 if ( currentApiPromise ) {
14                                         currentApiPromise.abort();
15                                         currentApiPromise = undefined;
16                                 }
18                                 passwordValue = passwordValue.trim();
20                                 if ( passwordValue === '' ) {
21                                         self.setErrors( [] );
22                                         return true;
23                                 }
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';
37                                         currentApiPromise = undefined;
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 );
47                                 return d.promise( { abort: currentApiPromise.abort } );
48                         } );
49                 } );
50         } );
51 }() );