Go to the documentation of this file.
29 use Psr\Log\LoggerAwareInterface;
30 use Psr\Log\LoggerAwareTrait;
31 use Psr\Log\LoggerInterface;
64 'AllowRequiringEmailForResets',
66 'PasswordResetRoutes',
83 LoggerInterface $logger =
null
90 wfDeprecated(
'Not passing LoadBalancer to ' . __METHOD__,
'1.34' );
91 $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
96 wfDeprecated(
'Not passing LoggerInterface to ' . __METHOD__,
'1.34' );
97 $logger = LoggerFactory::getInstance(
'authentication' );
99 $this->logger = $logger;
113 $resetRoutes = $this->config->get(
'PasswordResetRoutes' );
116 if ( !is_array( $resetRoutes ) || !in_array(
true, $resetRoutes,
true ) ) {
120 ( $providerStatus = $this->authManager->allowsAuthenticationDataChange(
122 && !$providerStatus->isGood()
126 $providerStatus->getMessage() );
127 } elseif ( !$this->config->get(
'EnableEmail' ) ) {
130 } elseif ( !$this->permissionManager->userHasRight( $user,
'editmyprivateinfo' ) ) {
163 User $performingUser, $username =
null, $email =
null
165 if ( !$this->
isAllowed( $performingUser )->isGood() ) {
166 throw new LogicException(
'User ' . $performingUser->
getName()
167 .
' is not allowed to reset passwords' );
170 $username = $username ??
'';
171 $email = $email ??
'';
173 $resetRoutes = $this->config->get(
'PasswordResetRoutes' )
174 + [
'username' =>
false,
'email' => false ];
175 if ( $resetRoutes[
'username'] && $username ) {
176 $method =
'username';
178 } elseif ( $resetRoutes[
'email'] && $email ) {
179 if ( !Sanitizer::validateEmail( $email ) ) {
193 'Username' => $username,
195 'Email' => $method ===
'email' ? $email :
null,
197 if ( !
Hooks::run(
'SpecialPasswordResetOnSubmit', [ &$users, $data, &$error ] ) ) {
201 $firstUser = $users[0] ??
null;
202 $requireEmail = $this->config->get(
'AllowRequiringEmailForResets' )
203 && $method ===
'username'
205 && $firstUser->getBoolOption(
'requireemail' );
206 if ( $requireEmail ) {
207 if ( $email ===
'' ) {
211 if ( !Sanitizer::validateEmail( $email ) ) {
217 if ( $performingUser->
pingLimiter(
'mailpassword' ) ) {
222 if ( $method ===
'email' ) {
230 if ( !$firstUser instanceof
User || !$firstUser->
getId() ) {
236 if ( !$firstUser->getEmail() ) {
242 if ( $requireEmail && $firstUser->getEmail() !== $email ) {
254 Hooks::run(
'User::mailPasswordInternal', [ &$performingUser, &$ip, &$firstUser ] );
258 foreach ( $users as $user ) {
259 $req = TemporaryPasswordAuthenticationRequest::newRandom();
260 $req->username = $user->getName();
261 $req->mailpassword =
true;
262 $req->caller = $performingUser->
getName();
263 $status = $this->authManager->allowsAuthenticationDataChange( $req,
true );
266 } elseif ( $result->isGood() ) {
269 if (
$status->getValue() ===
'ignored' ) {
277 'requestingIp' => $ip,
278 'requestingUser' => $performingUser->
getName(),
279 'targetUsername' => $username,
280 'targetEmail' => $email,
281 'actualUser' => $firstUser->getName(),
284 if ( !$result->isGood() ) {
286 "{requestingUser} attempted password reset of {actualUser} but failed",
287 $logContext + [
'errors' => $result->getErrors() ]
293 foreach ( $reqs as $req ) {
296 $this->authManager->changeAuthenticationData( $req,
true );
300 "{requestingUser} did password reset of {actualUser}",
319 return $block->appliesToPasswordReset();
329 $res = $this->loadBalancer->getConnectionRef(
DB_REPLICA )->select(
330 $userQuery[
'tables'],
331 $userQuery[
'fields'],
332 [
'user_email' => $email ],
340 throw new MWException(
'Unknown database error in ' . __METHOD__ );
344 foreach (
$res as $row ) {
const CONSTRUCTOR_OPTIONS
static newFatal( $message,... $parameters)
Factory function for fatal errors.
getId()
Get the user's ID.
ServiceOptions Config $config
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
pingLimiter( $action='edit', $incrBy=1)
Primitive rate limits: enforce maximum actions per time period to put a brake on flooding.
static newFromRow( $row, $data=null)
Create a new user object from a user row.
getRequest()
Get the WebRequest object to use with this object.
MapCacheLRU $permissionCache
In-process cache for isAllowed lookups, by username.
Interface for configuration instances.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
ILoadBalancer $loadBalancer
lookupUser( $username)
User object creation helper for testability.
Handles a simple LRU key/value map with a maximum number of entries.
getBlock( $fromReplica=true)
Get the block affecting the user, or null if the user is not blocked.
__construct( $config, AuthManager $authManager, PermissionManager $permissionManager, ILoadBalancer $loadBalancer=null, LoggerInterface $logger=null)
This class is managed by MediaWikiServices, don't instantiate directly.
isAllowed(User $user)
Check if a given user has permission to use this functionality.
static newGood( $value=null)
Factory function for good results.
getGlobalBlock( $ip='')
Check if user is blocked on all wikis.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new user object.
PermissionManager $permissionManager
isBlocked(User $user)
Check whether the user is blocked.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
execute(User $performingUser, $username=null, $email=null)
Do a password reset.
Helper class for the password reset functionality shared by the web UI and the API.
getName()
Get the user name, or the IP of an anonymous user.