Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| ApiChangeAuthenticationData | |
0.00% |
0 / 32 |
|
0.00% |
0 / 8 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
20 | |||
| isWriteMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| needsToken | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAllowedParams | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| dynamicParameterDocumentation | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getExamplesMessages | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright © 2016 Wikimedia Foundation and contributors |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Api; |
| 10 | |
| 11 | use MediaWiki\Auth\AuthManager; |
| 12 | use MediaWiki\MainConfigNames; |
| 13 | |
| 14 | /** |
| 15 | * Change authentication data with AuthManager |
| 16 | * |
| 17 | * @ingroup API |
| 18 | */ |
| 19 | class ApiChangeAuthenticationData extends ApiBase { |
| 20 | private AuthManager $authManager; |
| 21 | |
| 22 | public function __construct( |
| 23 | ApiMain $main, |
| 24 | string $action, |
| 25 | AuthManager $authManager |
| 26 | ) { |
| 27 | parent::__construct( $main, $action, 'changeauth' ); |
| 28 | $this->authManager = $authManager; |
| 29 | } |
| 30 | |
| 31 | public function execute() { |
| 32 | if ( !$this->getUser()->isNamed() ) { |
| 33 | $this->dieWithError( 'apierror-mustbeloggedin-changeauthenticationdata', 'notloggedin' ); |
| 34 | } |
| 35 | |
| 36 | $helper = new ApiAuthManagerHelper( $this, $this->authManager ); |
| 37 | |
| 38 | // Check security-sensitive operation status |
| 39 | $helper->securitySensitiveOperation( 'ChangeCredentials' ); |
| 40 | |
| 41 | // Fetch the request |
| 42 | $reqs = ApiAuthManagerHelper::blacklistAuthenticationRequests( |
| 43 | $helper->loadAuthenticationRequests( AuthManager::ACTION_CHANGE ), |
| 44 | $this->getConfig()->get( MainConfigNames::ChangeCredentialsBlacklist ) |
| 45 | ); |
| 46 | if ( count( $reqs ) !== 1 ) { |
| 47 | $this->dieWithError( 'apierror-changeauth-norequest', 'badrequest' ); |
| 48 | } |
| 49 | $req = reset( $reqs ); |
| 50 | |
| 51 | // Make the change |
| 52 | $status = $this->authManager->allowsAuthenticationDataChange( $req, true ); |
| 53 | $this->getHookRunner()->onChangeAuthenticationDataAudit( $req, $status ); |
| 54 | if ( !$status->isGood() ) { |
| 55 | $this->dieStatus( $status ); |
| 56 | } |
| 57 | $this->authManager->changeAuthenticationData( $req ); |
| 58 | |
| 59 | $this->getResult()->addValue( null, 'changeauthenticationdata', [ 'status' => 'success' ] ); |
| 60 | } |
| 61 | |
| 62 | /** @inheritDoc */ |
| 63 | public function isWriteMode() { |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | /** @inheritDoc */ |
| 68 | public function needsToken() { |
| 69 | return 'csrf'; |
| 70 | } |
| 71 | |
| 72 | /** @inheritDoc */ |
| 73 | public function getAllowedParams() { |
| 74 | return ApiAuthManagerHelper::getStandardParams( AuthManager::ACTION_CHANGE, |
| 75 | 'request' |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | /** @inheritDoc */ |
| 80 | public function dynamicParameterDocumentation() { |
| 81 | return [ 'api-help-authmanagerhelper-additional-params', AuthManager::ACTION_CHANGE ]; |
| 82 | } |
| 83 | |
| 84 | /** @inheritDoc */ |
| 85 | protected function getExamplesMessages() { |
| 86 | return [ |
| 87 | 'action=changeauthenticationdata' . |
| 88 | '&changeauthrequest=MediaWiki%5CAuth%5CPasswordAuthenticationRequest' . |
| 89 | '&password=ExamplePassword&retype=ExamplePassword&changeauthtoken=123ABC' |
| 90 | => 'apihelp-changeauthenticationdata-example-password', |
| 91 | ]; |
| 92 | } |
| 93 | |
| 94 | /** @inheritDoc */ |
| 95 | public function getHelpUrls() { |
| 96 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Manage_authentication_data'; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /** @deprecated class alias since 1.43 */ |
| 101 | class_alias( ApiChangeAuthenticationData::class, 'ApiChangeAuthenticationData' ); |