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
22 namespace MediaWiki\Auth
;
28 * Check if the user is blocked, and prevent authentication if so.
33 class CheckBlocksSecondaryAuthenticationProvider
extends AbstractSecondaryAuthenticationProvider
{
36 protected $blockDisablesLogin = null;
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 ) {
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() ] )
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();
82 $block->mReason ?
: \Message
::newFromKey( 'blockednoreason' )->text(),
86 if ( $block->getType() === \Block
::TYPE_RANGE
) {
87 $errorMessage = 'cantcreateaccount-range-text';
88 $errorParams[] = $this->manager
->getRequest()->getIP();
90 $errorMessage = 'cantcreateaccount-text';
93 return StatusValue
::newFatal(
94 new \
Message( $errorMessage, $errorParams )
97 return StatusValue
::newGood();