| 1 |
( function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
Object.assign( mw.Api.prototype, { |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
login: function ( username, password ) { |
| 11 |
const api = this; |
| 12 |
|
| 13 |
const params = { |
| 14 |
action: 'login', |
| 15 |
lgname: username, |
| 16 |
lgpassword: password |
| 17 |
}; |
| 18 |
|
| 19 |
const apiPromise = api.post( params ); |
| 20 |
|
| 21 |
let innerPromise; |
| 22 |
return apiPromise |
| 23 |
.then( ( data ) => { |
| 24 |
params.lgtoken = data.login.token; |
| 25 |
innerPromise = api.post( params ) |
| 26 |
.then( ( response ) => { |
| 27 |
let code; |
| 28 |
if ( response.login.result !== 'Success' ) { |
| 29 |
|
| 30 |
code = response.error && response.error.code || 'unknown'; |
| 31 |
return $.Deferred().reject( code, response ); |
| 32 |
} |
| 33 |
return response; |
| 34 |
} ); |
| 35 |
return innerPromise; |
| 36 |
} ) |
| 37 |
.promise( { |
| 38 |
abort: function () { |
| 39 |
apiPromise.abort(); |
| 40 |
if ( innerPromise ) { |
| 41 |
innerPromise.abort(); |
| 42 |
} |
| 43 |
} |
| 44 |
} ); |
| 45 |
} |
| 46 |
} ); |
| 47 |
|
| 48 |
}() ); |