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