MediaWiki  master
CheckBlocksSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1 <?php
22 namespace MediaWiki\Auth;
23 
24 use Config;
26 use StatusValue;
27 
35 
37  protected $blockDisablesLogin = null;
38 
44  public function __construct( $params = [] ) {
45  if ( isset( $params['blockDisablesLogin'] ) ) {
46  $this->blockDisablesLogin = (bool)$params['blockDisablesLogin'];
47  }
48  }
49 
50  public function setConfig( Config $config ) {
51  parent::setConfig( $config );
52 
53  if ( $this->blockDisablesLogin === null ) {
54  $this->blockDisablesLogin = $this->config->get( 'BlockDisablesLogin' );
55  }
56  }
57 
58  public function getAuthenticationRequests( $action, array $options ) {
59  return [];
60  }
61 
62  public function beginSecondaryAuthentication( $user, array $reqs ) {
63  // @TODO Partial blocks should not prevent the user from logging in.
64  // see: https://phabricator.wikimedia.org/T208895
65  if ( !$this->blockDisablesLogin ) {
67  } elseif ( $user->getBlock() ) {
69  new \Message( 'login-userblocked', [ $user->getName() ] )
70  );
71  } else {
73  }
74  }
75 
76  public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
78  }
79 
80  public function testUserForCreation( $user, $autocreate, array $options = [] ) {
81  $block = $user->isBlockedFromCreateAccount();
82  if ( $block ) {
83  if ( $block->getReason() ) {
84  $reason = $block->getReason();
85  } else {
86  $msg = \Message::newFromKey( 'blockednoreason' );
87  if ( !\RequestContext::getMain()->getUser()->isSafeToLoad() ) {
88  $msg->inContentLanguage();
89  }
90  $reason = $msg->text();
91  }
92 
93  $errorParams = [
94  $block->getTarget(),
95  $reason,
96  $block->getByName()
97  ];
98 
99  if ( $block->getType() === DatabaseBlock::TYPE_RANGE ) {
100  $errorMessage = 'cantcreateaccount-range-text';
101  $errorParams[] = $this->manager->getRequest()->getIP();
102  } else {
103  $errorMessage = 'cantcreateaccount-text';
104  }
105 
106  return StatusValue::newFatal(
107  new \Message( $errorMessage, $errorParams )
108  );
109  } else {
110  return StatusValue::newGood();
111  }
112  }
113 
114 }
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Definition: StatusValue.php:69
Check if the user is blocked, and prevent authentication if so.
The Message class provides methods which fulfil two basic services:
Definition: Message.php:162
string $action
Cache what action this request is.
Definition: MediaWiki.php:42
beginSecondaryAuthentication( $user, array $reqs)
Start an authentication flow.
static getMain()
Get the RequestContext object associated with the main request.
Interface for configuration instances.
Definition: Config.php:28
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
A base class that implements some of the boilerplate for a SecondaryAuthenticationProvider.
getUser()
beginSecondaryAccountCreation( $user, $creator, array $reqs)
Start an account creation flow.
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition: Message.php:410
testUserForCreation( $user, $autocreate, array $options=[])
Determine whether an account may be created.