MediaWiki REL1_37
EmailNotificationSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Auth;
4
6
15{
18
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}
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.
Database cluster connection, tracking, load balancing, and transaction manager interface.
const DB_PRIMARY
Definition defines.php:27