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
) {
17 var params
, apiPromise
, innerPromise
,
26 apiPromise
= api
.post( params
);
29 .then( function ( data
) {
30 params
.lgtoken
= data
.login
.token
;
31 innerPromise
= api
.post( params
)
32 .then( function ( data
) {
34 if ( data
.login
.result
!== 'Success' ) {
35 // Set proper error code whenever possible
36 code
= data
.error
&& data
.error
.code
|| 'unknown';
37 return $.Deferred().reject( code
, data
);
56 * @mixins mw.Api.plugin.login
59 }( mediaWiki
, jQuery
) );