2 * Make the two-step login easier.
4 * @author Niklas Laxström
5 * @class mw.Api.plugin.login
11 $.extend( mw.Api.prototype, {
13 * @param {string} username
14 * @param {string} password
15 * @return {jQuery.Promise} See mw.Api#post
17 login: function ( username, password ) {
18 var params, apiPromise, innerPromise,
27 apiPromise = api.post( params );
30 .then( function ( data ) {
31 params.lgtoken = data.login.token;
32 innerPromise = api.post( params )
33 .then( function ( data ) {
35 if ( data.login.result !== 'Success' ) {
36 // Set proper error code whenever possible
37 code = data.error && data.error.code || 'unknown';
38 return $.Deferred().reject( code, data );
57 * @mixins mw.Api.plugin.login
60 }( mediaWiki, jQuery ) );