| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Auth; |
| 4 |
|
| 5 |
use MediaWiki\MainConfigNames; |
| 6 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class EmailNotificationSecondaryAuthenticationProvider |
| 15 |
extends AbstractSecondaryAuthenticationProvider |
| 16 |
{ |
| 17 |
|
| 18 |
protected $sendConfirmationEmail; |
| 19 |
|
| 20 |
|
| 21 |
private $dbProvider; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public function __construct( IConnectionProvider $dbProvider, $params = [] ) { |
| 30 |
if ( isset( $params['sendConfirmationEmail'] ) ) { |
| 31 |
$this->sendConfirmationEmail = (bool)$params['sendConfirmationEmail']; |
| 32 |
} |
| 33 |
$this->dbProvider = $dbProvider; |
| 34 |
} |
| 35 |
|
| 36 |
protected function postInitSetup() { |
| 37 |
$this->sendConfirmationEmail ??= $this->config->get( MainConfigNames::EnableEmail ) |
| 38 |
&& $this->config->get( MainConfigNames::EmailAuthentication ); |
| 39 |
} |
| 40 |
|
| 41 |
public function getAuthenticationRequests( $action, array $options ) { |
| 42 |
return []; |
| 43 |
} |
| 44 |
|
| 45 |
public function beginSecondaryAuthentication( $user, array $reqs ) { |
| 46 |
return AuthenticationResponse::newAbstain(); |
| 47 |
} |
| 48 |
|
| 49 |
public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) { |
| 50 |
if ( |
| 51 |
$this->sendConfirmationEmail |
| 52 |
&& $user->getEmail() |
| 53 |
&& !$this->manager->getAuthenticationSessionData( 'no-email' ) |
| 54 |
) { |
| 55 |
|
| 56 |
$this->dbProvider->getPrimaryDatabase()->onTransactionCommitOrIdle( |
| 57 |
function () use ( $user ) { |
| 58 |
$user = $user->getInstanceForUpdate(); |
| 59 |
$status = $user->sendConfirmationMail(); |
| 60 |
$user->saveSettings(); |
| 61 |
if ( !$status->isGood() ) { |
| 62 |
$this->logger->warning( 'Could not send confirmation email: ' . |
| 63 |
$status->getWikiText( false, false, 'en' ) ); |
| 64 |
} |
| 65 |
}, |
| 66 |
__METHOD__ |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
return AuthenticationResponse::newPass(); |
| 71 |
} |
| 72 |
} |