MediaWiki REL1_34
ApiChangeAuthenticationData.php
Go to the documentation of this file.
1<?php
24
31
32 public function __construct( ApiMain $main, $action ) {
33 parent::__construct( $main, $action, 'changeauth' );
34 }
35
36 public function execute() {
37 if ( !$this->getUser()->isLoggedIn() ) {
38 $this->dieWithError( 'apierror-mustbeloggedin-changeauthenticationdata', 'notloggedin' );
39 }
40
41 $helper = new ApiAuthManagerHelper( $this );
42 $manager = AuthManager::singleton();
43
44 // Check security-sensitive operation status
45 $helper->securitySensitiveOperation( 'ChangeCredentials' );
46
47 // Fetch the request
49 $helper->loadAuthenticationRequests( AuthManager::ACTION_CHANGE ),
50 $this->getConfig()->get( 'ChangeCredentialsBlacklist' )
51 );
52 if ( count( $reqs ) !== 1 ) {
53 $this->dieWithError( 'apierror-changeauth-norequest', 'badrequest' );
54 }
55 $req = reset( $reqs );
56
57 // Make the change
58 $status = $manager->allowsAuthenticationDataChange( $req, true );
59 Hooks::run( 'ChangeAuthenticationDataAudit', [ $req, $status ] );
60 if ( !$status->isGood() ) {
61 $this->dieStatus( $status );
62 }
63 $manager->changeAuthenticationData( $req );
64
65 $this->getResult()->addValue( null, 'changeauthenticationdata', [ 'status' => 'success' ] );
66 }
67
68 public function isWriteMode() {
69 return true;
70 }
71
72 public function needsToken() {
73 return 'csrf';
74 }
75
76 public function getAllowedParams() {
77 return ApiAuthManagerHelper::getStandardParams( AuthManager::ACTION_CHANGE,
78 'request'
79 );
80 }
81
83 return [ 'api-help-authmanagerhelper-additional-params', AuthManager::ACTION_CHANGE ];
84 }
85
86 protected function getExamplesMessages() {
87 return [
88 'action=changeauthenticationdata' .
89 '&changeauthrequest=MediaWiki%5CAuth%5CPasswordAuthenticationRequest' .
90 '&password=ExamplePassword&retype=ExamplePassword&changeauthtoken=123ABC'
91 => 'apihelp-changeauthenticationdata-example-password',
92 ];
93 }
94
95 public function getHelpUrls() {
96 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Manage_authentication_data';
97 }
98}
Helper class for AuthManager-using API modules.
static getStandardParams( $action,... $wantedParams)
Fetch the standard parameters this helper recognizes.
static blacklistAuthenticationRequests(array $reqs, array $blacklist)
Filter out authentication requests by class name.
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:42
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:2014
getResult()
Get the result object.
Definition ApiBase.php:640
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition ApiBase.php:2086
Change authentication data with AuthManager.
getExamplesMessages()
Returns usage examples for this module.
getHelpUrls()
Return links to more detailed help pages about the module.
isWriteMode()
Indicates whether this module requires write mode.
needsToken()
Returns the token type this module requires in order to execute.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
dynamicParameterDocumentation()
Indicate if the module supports dynamically-determined parameters that cannot be included in self::ge...
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:41
This serves as the entry point to the authentication system.