Module: MediaWiki::Auth
- Included in:
- Butt
- Defined in:
- lib/mediawiki/auth.rb
Instance Method Summary collapse
-
#create_account(username, password, language = 'en', reason = nil) ⇒ Boolean
Creates an account using the standard procedure.
-
#create_account_email(username, email, language = 'en', reason = nil) ⇒ Boolean
Creates an account using the random password sent by email procedure.
-
#login(username, password) ⇒ Boolean
Logs the user into the wiki.
-
#logout ⇒ Boolean
Logs the current user out.
Instance Method Details
#create_account(username, password, language = 'en', reason = nil) ⇒ Boolean
Creates an account using the standard procedure. Use the language code, not the name.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mediawiki/auth.rb', line 68 def create_account(username, password, language = 'en', reason = nil) params = { name: username, password: password, language: language, token: get_token('createaccount') } params[:reason] = reason unless reason.nil? result = post(params) unless result['error'].nil? raise MediaWiki::Butt::AuthenticationError.new(result['error']['code']) end result['createaccount']['result'] == 'Success' end |
#create_account_email(username, email, language = 'en', reason = nil) ⇒ Boolean
Creates an account using the random password sent by email procedure.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/mediawiki/auth.rb', line 92 def create_account_email(username, email, language = 'en', reason = nil) params = { name: username, email: email, mailpassword: 'value', language: language, token: get_token('createaccount') } params[:reason] = reason unless reason.nil? result = post(params) unless result['error'].nil? raise MediaWiki::Butt::AuthenticationError.new(result['error']['code']) end result['createaccount']['result'] == 'Success' end |
#login(username, password) ⇒ Boolean
Logs the user into the wiki. This is generally required for editing and getting restricted data.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mediawiki/auth.rb', line 12 def login(username, password) # Save the assertion value while trying to log in, because otherwise the assertion will prevent us from logging in assertion_value = @assertion.clone @assertion = nil params = { action: 'login', lgname: username, lgpassword: password, lgtoken: get_token('login') } response = post(params) @assertion = assertion_value result = response['login']['result'] if result == 'Success' @name = response['login']['lgusername'] @logged_in = true return true end raise MediaWiki::Butt::AuthenticationError.new(result) end |
#logout ⇒ Boolean
Logs the current user out.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mediawiki/auth.rb', line 43 def logout if @logged_in params = { action: 'logout' } post(params) @logged_in = false true else false end end |