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