| 1 |
<?php |
| 2 |
|
| 3 |
s |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\Api; |
| 24 |
|
| 25 |
use MediaWiki\Auth\AuthManager; |
| 26 |
use MediaWiki\MainConfigNames; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class ApiChangeAuthenticationData extends ApiBase { |
| 34 |
private AuthManager $authManager; |
| 35 |
|
| 36 |
public function __construct( |
| 37 |
ApiMain $main, |
| 38 |
string $action, |
| 39 |
AuthManager $authManager |
| 40 |
) { |
| 41 |
parent::__construct( $main, $action, 'changeauth' ); |
| 42 |
$this->authManager = $authManager; |
| 43 |
} |
| 44 |
|
| 45 |
public function execute() { |
| 46 |
if ( !$this->getUser()->isNamed() ) { |
| 47 |
$this->dieWithError( 'apierror-mustbeloggedin-changeauthenticationdata', 'notloggedin' ); |
| 48 |
} |
| 49 |
|
| 50 |
$this->checkUserRightsAny( 'editmyprivateinfo' ); |
| 51 |
|
| 52 |
$helper = new ApiAuthManagerHelper( $this, $this->authManager ); |
| 53 |
|
| 54 |
|
| 55 |
$helper->securitySensitiveOperation( 'ChangeCredentials' ); |
| 56 |
|
| 57 |
|
| 58 |
$reqs = ApiAuthManagerHelper::blacklistAuthenticationRequests( |
| 59 |
$helper->loadAuthenticationRequests( AuthManager::ACTION_CHANGE ), |
| 60 |
$this->getConfig()->get( MainConfigNames::ChangeCredentialsBlacklist ) |
| 61 |
); |
| 62 |
if ( count( $reqs ) !== 1 ) { |
| 63 |
$this->dieWithError( 'apierror-changeauth-norequest', 'badrequest' ); |
| 64 |
} |
| 65 |
$req = reset( $reqs ); |
| 66 |
|
| 67 |
|
| 68 |
$status = $this->authManager->allowsAuthenticationDataChange( $req, true ); |
| 69 |
$this->getHookRunner()->onChangeAuthenticationDataAudit( $req, $status ); |
| 70 |
if ( !$status->isGood() ) { |
| 71 |
$this->dieStatus( $status ); |
| 72 |
} |
| 73 |
$this->authManager->changeAuthenticationData( $req ); |
| 74 |
|
| 75 |
$this->getResult()->addValue( null, 'changeauthenticationdata', [ 'status' => 'success' ] ); |
| 76 |
} |
| 77 |
|
| 78 |
public function isWriteMode() { |
| 79 |
return true; |
| 80 |
} |
| 81 |
|
| 82 |
public function needsToken() { |
| 83 |
return 'csrf'; |
| 84 |
} |
| 85 |
|
| 86 |
public function getAllowedParams() { |
| 87 |
return ApiAuthManagerHelper::getStandardParams( AuthManager::ACTION_CHANGE, |
| 88 |
'request' |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
public function dynamicParameterDocumentation() { |
| 93 |
return [ 'api-help-authmanagerhelper-additional-params', AuthManager::ACTION_CHANGE ]; |
| 94 |
} |
| 95 |
|
| 96 |
protected function getExamplesMessages() { |
| 97 |
return [ |
| 98 |
'action=changeauthenticationdata' . |
| 99 |
'&changeauthrequest=MediaWiki%5CAuth%5CPasswordAuthenticationRequest' . |
| 100 |
'&password=ExamplePassword&retype=ExamplePassword&changeauthtoken=123ABC' |
| 101 |
=> 'apihelp-changeauthenticationdata-example-password', |
| 102 |
]; |
| 103 |
} |
| 104 |
|
| 105 |
public function getHelpUrls() { |
| 106 |
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Manage_authentication_data'; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
class_alias( ApiChangeAuthenticationData::class, 'ApiChangeAuthenticationData' ); |