Move remaining LoadBalancer classes to Rdbms
[mediawiki.git] / includes / auth / CheckBlocksSecondaryAuthenticationProvider.php
blobf7a7ec193df73c0907ba90b79af71364af930c78
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Auth
22 namespace MediaWiki\Auth;
24 use Config;
25 use StatusValue;
27 /**
28 * Check if the user is blocked, and prevent authentication if so.
30 * @ingroup Auth
31 * @since 1.27
33 class CheckBlocksSecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider {
35 /** @var bool */
36 protected $blockDisablesLogin = null;
38 /**
39 * @param array $params
40 * - blockDisablesLogin: (bool) Whether blocked accounts can log in,
41 * defaults to $wgBlockDisablesLogin
43 public function __construct( $params = [] ) {
44 if ( isset( $params['blockDisablesLogin'] ) ) {
45 $this->blockDisablesLogin = (bool)$params['blockDisablesLogin'];
49 public function setConfig( Config $config ) {
50 parent::setConfig( $config );
52 if ( $this->blockDisablesLogin === null ) {
53 $this->blockDisablesLogin = $this->config->get( 'BlockDisablesLogin' );
57 public function getAuthenticationRequests( $action, array $options ) {
58 return [];
61 public function beginSecondaryAuthentication( $user, array $reqs ) {
62 if ( !$this->blockDisablesLogin ) {
63 return AuthenticationResponse::newAbstain();
64 } elseif ( $user->isBlocked() ) {
65 return AuthenticationResponse::newFail(
66 new \Message( 'login-userblocked', [ $user->getName() ] )
68 } else {
69 return AuthenticationResponse::newPass();
73 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
74 return AuthenticationResponse::newAbstain();
77 public function testUserForCreation( $user, $autocreate, array $options = [] ) {
78 $block = $user->isBlockedFromCreateAccount();
79 if ( $block ) {
80 $errorParams = [
81 $block->getTarget(),
82 $block->mReason ?: \Message::newFromKey( 'blockednoreason' )->text(),
83 $block->getByName()
86 if ( $block->getType() === \Block::TYPE_RANGE ) {
87 $errorMessage = 'cantcreateaccount-range-text';
88 $errorParams[] = $this->manager->getRequest()->getIP();
89 } else {
90 $errorMessage = 'cantcreateaccount-text';
93 return StatusValue::newFatal(
94 new \Message( $errorMessage, $errorParams )
96 } else {
97 return StatusValue::newGood();