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 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23namespace MediaWiki\Deferred;
24
25use MediaWiki\Auth\AuthManager;
26use MediaWiki\Logger\LoggerFactory;
27
28/**
29 * Sends emails to all accounts associated with that email to reset the password
30 * @since 1.35
31 */
32class SendPasswordResetEmailUpdate implements DeferrableUpdate {
33    /** @var AuthManager */
34    private $authManager;
35
36    /** @var array */
37    private $reqs;
38
39    /** @var array */
40    private $logContext;
41
42    /**
43     * @param AuthManager $authManager
44     * @param array $reqs
45     * @param array $logContext
46     */
47    public function __construct( AuthManager $authManager, array $reqs, array $logContext ) {
48        $this->authManager = $authManager;
49        $this->reqs = $reqs;
50        $this->logContext = $logContext;
51    }
52
53    public function doUpdate() {
54        $logger = LoggerFactory::getInstance( 'authentication' );
55        foreach ( $this->reqs as $req ) {
56            // This is adding a new temporary password, not intentionally changing anything
57            // (even though it might technically invalidate an old temporary password).
58            $this->authManager->changeAuthenticationData( $req, /* $isAddition */ true );
59            $logger->info(
60                "{requestingUser} did password reset of {targetUser} and an email was sent",
61                $this->logContext + [ 'targetUser' => $req->username ]
62            );
63        }
64    }
65
66}
67
68/** @deprecated class alias since 1.42 */
69class_alias( SendPasswordResetEmailUpdate::class, 'SendPasswordResetEmailUpdate' );