Skip to content

Commit

Permalink
add createAccount() method
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Jan 28, 2021
1 parent 24b2bd8 commit b96c5a8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build/bot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ export declare class mwn {
* @returns {Promise<void>}
*/
logout(): Promise<void>;
/**
* Create an account. Only works on wikis without extensions like
* ConfirmEdit enabled (hence doesn't work on WMF wikis).
* @param username
* @param password
*/
createAccount(username: string, password: string): Promise<any>;
/**
* Get basic info about the logged-in user
* @param [options]
Expand Down
27 changes: 27 additions & 0 deletions build/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,33 @@ class mwn {
this.csrfToken = '%notoken%';
});
}
/**
* Create an account. Only works on wikis without extensions like
* ConfirmEdit enabled (hence doesn't work on WMF wikis).
* @param username
* @param password
*/
async createAccount(username, password) {
if (!this.state.createaccounttoken) { // not logged in
await this.getTokens();
}
return this.request({
action: 'createaccount',
createreturnurl: 'https://example.com',
createtoken: this.state.createaccounttoken,
username: username,
password: password,
retype: password
}).then(json => {
let data = json.createaccount;
if (data.status === 'FAIL') {
return Promise.reject(data);
}
else { // status === 'PASS' or other value
return data;
}
});
}
/**
* Get basic info about the logged-in user
* @param [options]
Expand Down
27 changes: 27 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,33 @@ export class mwn {
});
}

/**
* Create an account. Only works on wikis without extensions like
* ConfirmEdit enabled (hence doesn't work on WMF wikis).
* @param username
* @param password
*/
async createAccount(username: string, password: string): Promise<any> {
if (!this.state.createaccounttoken) { // not logged in
await this.getTokens();
}
return this.request({
action: 'createaccount',
createreturnurl: 'https://example.com',
createtoken: this.state.createaccounttoken,
username: username,
password: password,
retype: password
}).then(json => {
let data = json.createaccount;
if (data.status === 'FAIL') {
return Promise.reject(data);
} else { // status === 'PASS' or other value
return data;
}
});
}

/**
* Get basic info about the logged-in user
* @param [options]
Expand Down

0 comments on commit b96c5a8

Please sign in to comment.