3 namespace MediaWiki\Auth
;
5 use MediaWiki\MainConfigNames
;
6 use Wikimedia\Rdbms\IConnectionProvider
;
9 * Handles email notification / email address confirmation for account creation.
11 * Set 'no-email' to true (via AuthManager::setAuthenticationSessionData) to skip this provider.
12 * Primary providers doing so are expected to take care of email address confirmation.
14 class EmailNotificationSecondaryAuthenticationProvider
15 extends AbstractSecondaryAuthenticationProvider
18 protected $sendConfirmationEmail;
20 private IConnectionProvider
$dbProvider;
23 * @param IConnectionProvider $dbProvider
24 * @param array $params
25 * - sendConfirmationEmail: (bool) send an email asking the user to confirm their email
26 * address after a successful registration
28 public function __construct( IConnectionProvider
$dbProvider, $params = [] ) {
29 if ( isset( $params['sendConfirmationEmail'] ) ) {
30 $this->sendConfirmationEmail
= (bool)$params['sendConfirmationEmail'];
32 $this->dbProvider
= $dbProvider;
35 protected function postInitSetup() {
36 $this->sendConfirmationEmail ??
= $this->config
->get( MainConfigNames
::EnableEmail
)
37 && $this->config
->get( MainConfigNames
::EmailAuthentication
);
40 public function getAuthenticationRequests( $action, array $options ) {
44 public function beginSecondaryAuthentication( $user, array $reqs ) {
45 return AuthenticationResponse
::newAbstain();
48 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
50 $this->sendConfirmationEmail
52 && !$this->manager
->getAuthenticationSessionData( 'no-email' )
54 // TODO show 'confirmemail_oncreate'/'confirmemail_sendfailed' message
55 $this->dbProvider
->getPrimaryDatabase()->onTransactionCommitOrIdle(
56 function () use ( $user ) {
57 $user = $user->getInstanceForUpdate();
58 $status = $user->sendConfirmationMail();
59 $user->saveSettings();
60 if ( !$status->isGood() ) {
61 $this->logger
->warning( 'Could not send confirmation email: ' .
62 $status->getWikiText( false, false, 'en' ) );
69 return AuthenticationResponse
::newPass();