getAuthenticationRequests()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MediaWiki\Auth;
4
5
use Config;
6
7
/**
8
 * Handles email notification / email address confirmation for account creation.
9
 *
10
 * Set 'no-email' to true (via AuthManager::setAuthenticationSessionData) to skip this provider.
11
 * Primary providers doing so are expected to take care of email address confirmation.
12
 */
13
class EmailNotificationSecondaryAuthenticationProvider
14
	extends AbstractSecondaryAuthenticationProvider
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
15
{
16
	/** @var bool */
17
	protected $sendConfirmationEmail;
18
19
	/**
20
	 * @param array $params
21
	 *  - sendConfirmationEmail: (bool) send an email asking the user to confirm their email
22
	 *    address after a successful registration
23
	 */
24
	public function __construct( $params = [] ) {
25
		if ( isset( $params['sendConfirmationEmail'] ) ) {
26
			$this->sendConfirmationEmail = (bool)$params['sendConfirmationEmail'];
27
		}
28
	}
29
30
	public function setConfig( Config $config ) {
31
		parent::setConfig( $config );
32
33
		if ( $this->sendConfirmationEmail === null ) {
34
			$this->sendConfirmationEmail = $this->config->get( 'EnableEmail' )
35
				&& $this->config->get( 'EmailAuthentication' );
36
		}
37
	}
38
39
	public function getAuthenticationRequests( $action, array $options ) {
40
		return [];
41
	}
42
43
	public function beginSecondaryAuthentication( $user, array $reqs ) {
44
		return AuthenticationResponse::newAbstain();
45
	}
46
47
	public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
48
		if (
49
			$this->sendConfirmationEmail
50
			&& $user->getEmail()
51
			&& !$this->manager->getAuthenticationSessionData( 'no-email' )
52
		) {
53
			// TODO show 'confirmemail_oncreate'/'confirmemail_sendfailed' message
54
			wfGetDB( DB_MASTER )->onTransactionIdle(
55
				function () use ( $user ) {
56
					$user = $user->getInstanceForUpdate();
0 ignored issues
show
Bug introduced by
Consider using a different name than the imported variable $user, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
57
					$status = $user->sendConfirmationMail();
58
					$user->saveSettings();
59
					if ( !$status->isGood() ) {
60
						$this->logger->warning( 'Could not send confirmation email: ' .
61
							$status->getWikiText( false, false, 'en' ) );
62
					}
63
				},
64
				__METHOD__
65
			);
66
		}
67
68
		return AuthenticationResponse::newPass();
69
	}
70
}
71