MediaWiki master
EmailNotificationSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Auth;
4
7
16{
19
20 private IConnectionProvider $dbProvider;
21
28 public function __construct( IConnectionProvider $dbProvider, $params = [] ) {
29 if ( isset( $params['sendConfirmationEmail'] ) ) {
30 $this->sendConfirmationEmail = (bool)$params['sendConfirmationEmail'];
31 }
32 $this->dbProvider = $dbProvider;
33 }
34
35 protected function postInitSetup() {
36 $this->sendConfirmationEmail ??= $this->config->get( MainConfigNames::EnableEmail )
37 && $this->config->get( MainConfigNames::EmailAuthentication );
38 }
39
41 public function getAuthenticationRequests( $action, array $options ) {
42 return [];
43 }
44
46 public function beginSecondaryAuthentication( $user, array $reqs ) {
48 }
49
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->dbProvider->getPrimaryDatabase()->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.There is no guarantee this will be called in a successful account crea...
beginSecondaryAuthentication( $user, array $reqs)
Start an authentication flow.Note that this may be called for a user even if beginSecondaryAccountCre...
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.Possible values for $action depend on whether th...
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.