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
40 public function getAuthenticationRequests( $action, array $options ) {
41 return [];
42 }
43
44 public function beginSecondaryAuthentication( $user, array $reqs ) {
46 }
47
48 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
49 if (
50 $this->sendConfirmationEmail
51 && $user->getEmail()
52 && !$this->manager->getAuthenticationSessionData( 'no-email' )
53 ) {
54 // TODO show 'confirmemail_oncreate'/'confirmemail_sendfailed' message
55 $this->dbProvider->getPrimaryDatabase()->onTransactionCommitOrIdle(
56 function () use ( $user ) {
57 $user = $user->getInstanceForUpdate();
58 $status = $user->sendConfirmationMail();
59 $user->saveSettings();
60 if ( !$status->isGood() ) {
61 $this->logger->warning( 'Could not send confirmation email: ' .
62 $status->getWikiText( false, false, 'en' ) );
63 }
64 },
65 __METHOD__
66 );
67 }
68
70 }
71}
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.