2 * Make the two-step login easier.
3 * @author Niklas Laxström
4 * @class mw.Api.plugin.login
10 $.extend( mw.Api.prototype, {
12 * @param {string} username
13 * @param {string} password
14 * @return {jQuery.Promise} See mw.Api#post
16 login: function ( username, password ) {
18 deferred = $.Deferred(),
27 request = api.post( params );
28 request.fail( deferred.reject );
29 request.done( function ( data ) {
30 params.lgtoken = data.login.token;
32 .fail( deferred.reject )
33 .done( function ( data ) {
35 if ( data.login && data.login.result === 'Success' ) {
36 deferred.resolve( data );
38 // Set proper error code whenever possible
39 code = data.error && data.error.code || 'unknown';
40 deferred.reject( code, data );
45 return deferred.promise( { abort: request.abort } );
51 * @mixins mw.Api.plugin.login
54 }( mediaWiki, jQuery ) );