3 namespace MediaWiki\Auth
;
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;
21 * @param array $params
22 * - sendConfirmationEmail: (bool) send an email asking the user to confirm their email
23 * address after a successful registration
25 public function __construct( $params = [] ) {
26 if ( isset( $params['sendConfirmationEmail'] ) ) {
27 $this->sendConfirmationEmail
= (bool)$params['sendConfirmationEmail'];
31 public function setConfig( Config
$config ) {
32 parent
::setConfig( $config );
34 if ( $this->sendConfirmationEmail
=== null ) {
35 $this->sendConfirmationEmail
= $this->config
->get( 'EnableEmail' )
36 && $this->config
->get( '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 $status = $user->sendConfirmationMail();
55 $user->saveSettings();
56 if ( $status->isGood() ) {
57 // TODO show 'confirmemail_oncreate' success message
59 // TODO show 'confirmemail_sendfailed' error message
60 $this->logger
->warning( 'Could not send confirmation email: ' .
61 $status->getWikiText( false, false, 'en' ) );
65 return AuthenticationResponse
::newPass();