1 | <?php |
||
30 | class ApiChangeAuthenticationData extends ApiBase { |
||
31 | |||
32 | public function __construct( ApiMain $main, $action ) { |
||
35 | |||
36 | public function execute() { |
||
37 | if ( !$this->getUser()->isLoggedIn() ) { |
||
38 | $this->dieUsage( 'Must be logged in to change authentication data', '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 |
||
48 | $reqs = ApiAuthManagerHelper::blacklistAuthenticationRequests( |
||
49 | $helper->loadAuthenticationRequests( AuthManager::ACTION_CHANGE ), |
||
50 | $this->getConfig()->get( 'ChangeCredentialsBlacklist' ) |
||
51 | ); |
||
52 | if ( count( $reqs ) !== 1 ) { |
||
53 | $this->dieUsage( 'Failed to create change request', '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() { |
||
71 | |||
72 | public function needsToken() { |
||
75 | |||
76 | public function getAllowedParams() { |
||
81 | |||
82 | public function dynamicParameterDocumentation() { |
||
85 | |||
86 | protected function getExamplesMessages() { |
||
94 | |||
95 | public function getHelpUrls() { |
||
98 | } |
||
99 |
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.