MediaWiki  master
PasswordReset Class Reference

Helper class for the password reset functionality shared by the web UI and the API. More...

Inheritance diagram for PasswordReset:
Collaboration diagram for PasswordReset:

Public Member Functions

 __construct (ServiceOptions $config, LoggerInterface $logger, AuthManager $authManager, HookContainer $hookContainer, ILoadBalancer $loadBalancer, PermissionManager $permissionManager, UserFactory $userFactory, UserNameUtils $userNameUtils, UserOptionsLookup $userOptionsLookup)
 This class is managed by MediaWikiServices, don't instantiate directly. More...
 
 execute (User $performingUser, $username=null, $email=null)
 Do a password reset. More...
 
 isAllowed (User $user)
 Check if a given user has permission to use this functionality. More...
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Protected Member Functions

 getUsersByEmail ( $email)
 

Private Member Functions

 isBlocked (User $user)
 Check whether the user is blocked. More...
 

Private Attributes

AuthManager $authManager
 
ServiceOptions $config
 
HookRunner $hookRunner
 
ILoadBalancer $loadBalancer
 
MapCacheLRU $permissionCache
 In-process cache for isAllowed lookups, by username. More...
 
PermissionManager $permissionManager
 
UserFactory $userFactory
 
UserNameUtils $userNameUtils
 
UserOptionsLookup $userOptionsLookup
 

Detailed Description

Helper class for the password reset functionality shared by the web UI and the API.

Requires the TemporaryPasswordPrimaryAuthenticationProvider and the EmailNotificationSecondaryAuthenticationProvider (or something providing equivalent functionality) to be enabled.

Definition at line 44 of file PasswordReset.php.

Constructor & Destructor Documentation

◆ __construct()

PasswordReset::__construct ( ServiceOptions  $config,
LoggerInterface  $logger,
AuthManager  $authManager,
HookContainer  $hookContainer,
ILoadBalancer  $loadBalancer,
PermissionManager  $permissionManager,
UserFactory  $userFactory,
UserNameUtils  $userNameUtils,
UserOptionsLookup  $userOptionsLookup 
)

This class is managed by MediaWikiServices, don't instantiate directly.

Parameters
ServiceOptions$config
LoggerInterface$logger
AuthManager$authManager
HookContainer$hookContainer
ILoadBalancer$loadBalancer
PermissionManager$permissionManager
UserFactory$userFactory
UserNameUtils$userNameUtils
UserOptionsLookup$userOptionsLookup

Definition at line 100 of file PasswordReset.php.

References $authManager, $config, $loadBalancer, $permissionManager, $userFactory, $userNameUtils, $userOptionsLookup, and MediaWiki\Config\ServiceOptions\assertRequiredOptions().

Member Function Documentation

◆ execute()

PasswordReset::execute ( User  $performingUser,
  $username = null,
  $email = null 
)

Do a password reset.

Authorization is the caller's responsibility.

Process the form. At this point we know that the user passes all the criteria in userCanExecute(), and if the data array contains 'Username', etc, then Username resets are allowed.

Since
1.29 Fourth argument for displayPassword removed.
Parameters
User$performingUserThe user that does the password reset
string | null$usernameThe user whose password is reset
string | null$emailAlternative way to specify the user
Returns
StatusValue
Exceptions
LogicExceptionWhen the user is not allowed to perform the action
MWExceptionOn unexpected DB errors

Definition at line 184 of file PasswordReset.php.

References $userOptionsLookup, DeferredUpdates\addUpdate(), User\getId(), User\getName(), User\getRequest(), getUsersByEmail(), isAllowed(), StatusValue\newFatal(), Message\newFromSpecifier(), StatusValue\newGood(), User\pingLimiter(), and Sanitizer\validateEmail().

◆ getUsersByEmail()

PasswordReset::getUsersByEmail (   $email)
protected
Note
This is protected to allow configuring in tests. This class is not stable to extend.
Parameters
string$email
Returns
User[]
Exceptions
MWExceptionOn unexpected database errors

Definition at line 371 of file PasswordReset.php.

References $res, DB_REPLICA, and User\getQueryInfo().

Referenced by execute().

◆ isAllowed()

PasswordReset::isAllowed ( User  $user)

Check if a given user has permission to use this functionality.

Parameters
User$user
Since
1.29 Second argument for displayPassword removed.
Returns
StatusValue

Definition at line 133 of file PasswordReset.php.

References User\getName(), isBlocked(), StatusValue\newFatal(), and StatusValue\newGood().

Referenced by execute().

◆ isBlocked()

PasswordReset::isBlocked ( User  $user)
private

Check whether the user is blocked.

Ignores certain types of system blocks that are only meant to force users to log in.

Parameters
User$user
Returns
bool
Since
1.30

Definition at line 356 of file PasswordReset.php.

References User\getBlock(), and User\getGlobalBlock().

Referenced by isAllowed().

Member Data Documentation

◆ $authManager

AuthManager PasswordReset::$authManager
private

Definition at line 51 of file PasswordReset.php.

Referenced by __construct().

◆ $config

ServiceOptions PasswordReset::$config
private

Definition at line 48 of file PasswordReset.php.

Referenced by __construct().

◆ $hookRunner

HookRunner PasswordReset::$hookRunner
private

Definition at line 54 of file PasswordReset.php.

◆ $loadBalancer

ILoadBalancer PasswordReset::$loadBalancer
private

Definition at line 57 of file PasswordReset.php.

Referenced by __construct().

◆ $permissionCache

MapCacheLRU PasswordReset::$permissionCache
private

In-process cache for isAllowed lookups, by username.

Contains a StatusValue object

Definition at line 76 of file PasswordReset.php.

◆ $permissionManager

PermissionManager PasswordReset::$permissionManager
private

Definition at line 60 of file PasswordReset.php.

Referenced by __construct().

◆ $userFactory

UserFactory PasswordReset::$userFactory
private

Definition at line 63 of file PasswordReset.php.

Referenced by __construct().

◆ $userNameUtils

UserNameUtils PasswordReset::$userNameUtils
private

Definition at line 66 of file PasswordReset.php.

Referenced by __construct().

◆ $userOptionsLookup

UserOptionsLookup PasswordReset::$userOptionsLookup
private

Definition at line 69 of file PasswordReset.php.

Referenced by __construct(), and execute().

◆ CONSTRUCTOR_OPTIONS

const PasswordReset::CONSTRUCTOR_OPTIONS
Initial value:
= [
'AllowRequiringEmailForResets',
'EnableEmail',
'PasswordResetRoutes',
]

Definition at line 81 of file PasswordReset.php.


The documentation for this class was generated from the following file: