Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createAccount() #135

Merged
merged 2 commits into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ Gets information about a specific user (including rights, current block, groups)

Gets information about specific users (including rights, current block, groups) - [read more](https://www.mediawiki.org/wiki/API:Users)

### bot.createAccount(username, password, callback)

Create account using given credentials - [read more](https://www.mediawiki.org/wiki/API:Account_creation)

### bot.move(from, to, summary, callback)

Moves (aka renames) given article - [read more](http://www.mediawiki.org/wiki/API:Move)
Expand Down
18 changes: 18 additions & 0 deletions examples/createAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Example script on how to create account
*
* @see https://www.mediawiki.org/wiki/API:Account_creation
*/

const bot = require('..'),
client = new bot('config.js');

// create account
client.createAccount("user123", "password123", function(err, userData) {
if (err) {
console.log(err);
return;
}

console.log(JSON.stringify(userData, null, '\t'));
});
26 changes: 26 additions & 0 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,32 @@ module.exports = (function() {
});
},

createAccount(username, password, callback) {
// @see https://www.mediawiki.org/wiki/API:Account_creation
const self = this;
this.log(`creating account ${username}`);
this.api.call({
action: 'query',
meta: 'tokens',
type: 'createaccount'
}, function(err, data ) {
self.api.call({
action: 'createaccount',
createreturnurl: `${self.api.protocol}://${self.api.server}:${self.api.port}/`,
createtoken: data.tokens.createaccounttoken,
username: username,
password: password,
retype: password,
}, function(err, data ) {
if (err) {
callback(err);
return;
}
callback(data);
}, 'POST');
});
},

move(from, to, summary, callback) {
const self = this;

Expand Down