MediaWiki  master
EmailNotificationSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Auth;
4 
7 
16 {
19 
21  private $loadBalancer;
22 
29  public function __construct( ILoadBalancer $loadBalancer, $params = [] ) {
30  if ( isset( $params['sendConfirmationEmail'] ) ) {
31  $this->sendConfirmationEmail = (bool)$params['sendConfirmationEmail'];
32  }
33  $this->loadBalancer = $loadBalancer;
34  }
35 
36  protected function postInitSetup() {
37  if ( $this->sendConfirmationEmail === null ) {
38  $this->sendConfirmationEmail = $this->config->get( MainConfigNames::EnableEmail )
39  && $this->config->get( MainConfigNames::EmailAuthentication );
40  }
41  }
42 
43  public function getAuthenticationRequests( $action, array $options ) {
44  return [];
45  }
46 
47  public function beginSecondaryAuthentication( $user, array $reqs ) {
49  }
50 
51  public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
52  if (
53  $this->sendConfirmationEmail
54  && $user->getEmail()
55  && !$this->manager->getAuthenticationSessionData( 'no-email' )
56  ) {
57  // TODO show 'confirmemail_oncreate'/'confirmemail_sendfailed' message
58  $this->loadBalancer->getConnectionRef( DB_PRIMARY )->onTransactionCommitOrIdle(
59  function () use ( $user ) {
60  $user = $user->getInstanceForUpdate();
61  $status = $user->sendConfirmationMail();
62  $user->saveSettings();
63  if ( !$status->isGood() ) {
64  $this->logger->warning( 'Could not send confirmation email: ' .
65  $status->getWikiText( false, false, 'en' ) );
66  }
67  },
68  __METHOD__
69  );
70  }
71 
73  }
74 }
A base class that implements some of the boilerplate for a SecondaryAuthenticationProvider.
Handles email notification / email address confirmation for account creation.
postInitSetup()
A provider can override this to do any necessary setup after init() is called.
beginSecondaryAccountCreation( $user, $creator, array $reqs)
Start an account creation flow.
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
A class containing constants representing the names of configuration variables.
const EnableEmail
Name constant for the EnableEmail setting, for use with Config::get()
const EmailAuthentication
Name constant for the EmailAuthentication setting, for use with Config::get()
string null $action
Cache what action this request is.
Definition: MediaWiki.php:47
Database cluster connection, tracking, load balancing, and transaction manager interface.
const DB_PRIMARY
Definition: defines.php:27