Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
10 / 11
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SendPasswordResetEmailUpdate
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 doUpdate
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Send an email to reset the password
4 *
5 * @license GPL-2.0-or-later
6 * @file
7 */
8
9namespace MediaWiki\Deferred;
10
11use MediaWiki\Auth\AuthManager;
12use MediaWiki\Auth\TemporaryPasswordAuthenticationRequest;
13use MediaWiki\Logger\LoggerFactory;
14
15/**
16 * Sends emails to all accounts associated with that email to reset the password
17 * @since 1.35
18 */
19class SendPasswordResetEmailUpdate implements DeferrableUpdate {
20    /** @var AuthManager */
21    private $authManager;
22
23    /** @var TemporaryPasswordAuthenticationRequest[] */
24    private $reqs;
25
26    /** @var array */
27    private $logContext;
28
29    /**
30     * @param AuthManager $authManager
31     * @param TemporaryPasswordAuthenticationRequest[] $reqs
32     * @param array $logContext
33     */
34    public function __construct( AuthManager $authManager, array $reqs, array $logContext ) {
35        $this->authManager = $authManager;
36        $this->reqs = $reqs;
37        $this->logContext = $logContext;
38    }
39
40    public function doUpdate() {
41        $logger = LoggerFactory::getInstance( 'authentication' );
42        foreach ( $this->reqs as $req ) {
43            // This is adding a new temporary password, not intentionally changing anything
44            // (even though it might technically invalidate an old temporary password).
45            $this->authManager->changeAuthenticationData( $req, /* $isAddition */ true );
46            $logger->info(
47                "{requestingUser} did password reset of {targetUser} and an email was sent",
48                $this->logContext + [ 'targetUser' => $req->username ]
49            );
50        }
51    }
52
53}
54
55/** @deprecated class alias since 1.42 */
56class_alias( SendPasswordResetEmailUpdate::class, 'SendPasswordResetEmailUpdate' );