MediaWiki master
EmailNotificationSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Auth;
4
7
16{
19
21 private $dbProvider;
22
29 public function __construct( IConnectionProvider $dbProvider, $params = [] ) {
30 if ( isset( $params['sendConfirmationEmail'] ) ) {
31 $this->sendConfirmationEmail = (bool)$params['sendConfirmationEmail'];
32 }
33 $this->dbProvider = $dbProvider;
34 }
35
36 protected function postInitSetup() {
37 $this->sendConfirmationEmail ??= $this->config->get( MainConfigNames::EnableEmail )
38 && $this->config->get( MainConfigNames::EmailAuthentication );
39 }
40
41 public function getAuthenticationRequests( $action, array $options ) {
42 return [];
43 }
44
45 public function beginSecondaryAuthentication( $user, array $reqs ) {
47 }
48
49 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
50 if (
51 $this->sendConfirmationEmail
52 && $user->getEmail()
53 && !$this->manager->getAuthenticationSessionData( 'no-email' )
54 ) {
55 // TODO show 'confirmemail_oncreate'/'confirmemail_sendfailed' message
56 $this->dbProvider->getPrimaryDatabase()->onTransactionCommitOrIdle(
57 function () use ( $user ) {
58 $user = $user->getInstanceForUpdate();
59 $status = $user->sendConfirmationMail();
60 $user->saveSettings();
61 if ( !$status->isGood() ) {
62 $this->logger->warning( 'Could not send confirmation email: ' .
63 $status->getWikiText( false, false, 'en' ) );
64 }
65 },
66 __METHOD__
67 );
68 }
69
71 }
72}
array $params
The job parameters.
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()
Provide primary and replica IDatabase connections.