35 private $passwordReset;
47 parent::__construct( $main, $action );
49 $this->passwordReset = $passwordReset;
53 private $hasAnyRoutes =
null;
59 private function hasAnyRoutes() {
60 if ( $this->hasAnyRoutes ===
null ) {
61 $resetRoutes = $this->
getConfig()->get( MainConfigNames::PasswordResetRoutes );
62 $this->hasAnyRoutes = !empty( $resetRoutes[
'username'] ) || !empty( $resetRoutes[
'email'] );
64 return $this->hasAnyRoutes;
69 if ( !$this->hasAnyRoutes() ) {
70 return 'apihelp-resetpassword-extended-description-noroutes';
72 return parent::getExtendedDescription();
77 if ( !$this->hasAnyRoutes() ) {
78 $this->
dieWithError(
'apihelp-resetpassword-description-noroutes',
'moduledisabled' );
87 $status = $this->passwordReset->isAllowed( $this->
getUser() );
88 if ( !$status->isOK() ) {
89 $this->
dieStatus( Status::wrap( $status ) );
92 $status = $this->passwordReset->execute(
93 $this->
getUser(), $params[
'user'], $params[
'email']
95 if ( !$status->isOK() ) {
96 $status->value =
null;
97 $this->
dieStatus( Status::wrap( $status ) );
101 $result->addValue( [
'resetpassword' ],
'status',
'success' );
105 return $this->hasAnyRoutes();
109 if ( !$this->hasAnyRoutes() ) {
117 if ( !$this->hasAnyRoutes() ) {
123 ParamValidator::PARAM_TYPE =>
'user',
124 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name' ],
127 ParamValidator::PARAM_TYPE =>
'string',
131 $resetRoutes = $this->
getConfig()->get( MainConfigNames::PasswordResetRoutes );
132 if ( empty( $resetRoutes[
'username'] ) ) {
133 unset( $ret[
'user'] );
135 if ( empty( $resetRoutes[
'email'] ) ) {
136 unset( $ret[
'email'] );
145 $resetRoutes = $this->
getConfig()->get( MainConfigNames::PasswordResetRoutes );
147 if ( !empty( $resetRoutes[
'username'] ) ) {
148 $ret[
'action=resetpassword&user=Example&token=123ABC'] =
'apihelp-resetpassword-example-user';
150 if ( !empty( $resetRoutes[
'email'] ) ) {
151 $ret[
'action=resetpassword&user=user@example.com&token=123ABC'] =
152 'apihelp-resetpassword-example-email';
160 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Manage_authentication_data';
This abstract class implements many basic API functions, and is the base of all API classes.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
This is the main API class, used for both external and internal processing.
Reset password, with AuthManager.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getExtendedDescription()
Return the extended help text message.This is additional text to display at the top of the help secti...
getExamplesMessages()
Returns usage examples for this module.Return value has query strings as keys, with values being eith...
isWriteMode()
Indicates whether this module requires write mode.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.Concrete implementatio...
__construct(ApiMain $main, $action, PasswordReset $passwordReset)
needsToken()
Returns the token type this module requires in order to execute.
getHelpUrls()
Return links to more detailed help pages about the module.1.25, returning boolean false is deprecated...
A class containing constants representing the names of configuration variables.
Helper class for the password reset functionality shared by the web UI and the API.