Gergő Tisza has uploaded a new change for review.
https://gerrit.wikimedia.org/r/290269
Change subject: Update account creation code for AuthManager
......................................................................
Update account creation code for AuthManager
Bug: T135884
Change-Id: Iaf1db8846c8c79a4b8b8bc68a749d5b1ce054a52
---
M lib/mediawiki_api/client.rb
1 file changed, 36 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/ruby/api
refs/changes/69/290269/1
diff --git a/lib/mediawiki_api/client.rb b/lib/mediawiki_api/client.rb
index 5a4d80d..706683e 100644
--- a/lib/mediawiki_api/client.rb
+++ b/lib/mediawiki_api/client.rb
@@ -41,7 +41,41 @@
end
end
- def create_account(username, password, token = nil)
+ def create_account(username, password)
+ params = { modules: 'createaccount' }
+ d = action(:paraminfo, params).data
+ params = d['modules'] && d['modules'][0] && d['modules'][0]['parameters']
+ if !params || !params.map
+ raise CreateAccountError, 'unexpected API response format'
+ end
+ params = params.map{ |o| o['name'] }
+
+ if params.include? 'requests'
+ create_account_new(username, password)
+ else
+ create_account_old(username, password)
+ end
+ end
+
+ def create_account_new(username, password)
+ # post-AuthManager
+ data = action(:query, { meta: 'tokens', type: 'createaccount' } ).data
+ token = data['tokens'] && data['tokens']['createaccounttoken']
+ if !token
+ raise CreateAccountError, 'failed to get createaccount API token'
+ end
+
+ data = action(:createaccount, {
+ username: username,
+ password: password,
+ retype: password,
+ createreturnurl: 'http://example.com', # won't be used but must be a
valid URL
+ createtoken: token
+ } ).data
+ end
+
+ def create_account_old(username, password, token = nil)
+ # pre-AuthManager
params = { name: username, password: password, token_type: false }
params[:token] = token unless token.nil?
@@ -52,7 +86,7 @@
@logged_in = true
@tokens.clear
when 'NeedToken'
- data = create_account(username, password, data['token'])
+ data = create_account_old(username, password, data['token'])
else
raise CreateAccountError, data['result']
end
--
To view, visit https://gerrit.wikimedia.org/r/290269
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaf1db8846c8c79a4b8b8bc68a749d5b1ce054a52
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/ruby/api
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits