3 namespace MediaWiki\Auth
;
8 * Handles email notification / email address confirmation for account creation.
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.
13 class EmailNotificationSecondaryAuthenticationProvider
14 extends AbstractSecondaryAuthenticationProvider
17 protected $sendConfirmationEmail;
20 * @param array $params
21 * - sendConfirmationEmail: (bool) send an email asking the user to confirm their email
22 * address after a successful registration
24 public function __construct( $params = [] ) {
25 if ( isset( $params['sendConfirmationEmail'] ) ) {
26 $this->sendConfirmationEmail
= (bool)$params['sendConfirmationEmail'];
30 public function setConfig( Config
$config ) {
31 parent
::setConfig( $config );
33 if ( $this->sendConfirmationEmail
=== null ) {
34 $this->sendConfirmationEmail
= $this->config
->get( 'EnableEmail' )
35 && $this->config
->get( 'EmailAuthentication' );
39 public function getAuthenticationRequests( $action, array $options ) {
43 public function beginSecondaryAuthentication( $user, array $reqs ) {
44 return AuthenticationResponse
::newAbstain();
47 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
49 $this->sendConfirmationEmail
51 && !$this->manager
->getAuthenticationSessionData( 'no-email' )
53 // TODO show 'confirmemail_oncreate'/'confirmemail_sendfailed' message
54 wfGetDB( DB_MASTER
)->onTransactionIdle(
55 function () use ( $user ) {
56 $user = $user->getInstanceForUpdate();
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' ) );
68 return AuthenticationResponse
::newPass();