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
;
24 use MediaWiki\MainConfigNames
;
25 use MediaWiki\Message\Message
;
28 * Check if the user is blocked, and prevent authentication if so.
30 * Not all scenarios are covered by this class, AuthManager does some block checks itself
31 * via AuthManager::authorizeCreateAccount().
36 class CheckBlocksSecondaryAuthenticationProvider
extends AbstractSecondaryAuthenticationProvider
{
39 protected $blockDisablesLogin = null;
42 * @param array $params
43 * - blockDisablesLogin: (bool) Whether blocked accounts can log in,
44 * defaults to $wgBlockDisablesLogin
46 public function __construct( $params = [] ) {
47 if ( isset( $params['blockDisablesLogin'] ) ) {
48 $this->blockDisablesLogin
= (bool)$params['blockDisablesLogin'];
53 protected function postInitSetup() {
54 $this->blockDisablesLogin ??
= $this->config
->get( MainConfigNames
::BlockDisablesLogin
);
58 public function getAuthenticationRequests( $action, array $options ) {
63 public function beginSecondaryAuthentication( $user, array $reqs ) {
64 if ( !$this->blockDisablesLogin
) {
65 return AuthenticationResponse
::newAbstain();
67 $block = $user->getBlock();
68 // Ignore IP blocks and partial blocks, $wgBlockDisablesLogin was meant for
69 // blocks banning specific users.
70 if ( $block && $block->isSitewide() && $block->isBlocking( $user ) ) {
71 return AuthenticationResponse
::newFail(
72 new Message( 'login-userblocked', [ $user->getName() ] )
75 return AuthenticationResponse
::newPass();
80 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
81 return AuthenticationResponse
::newAbstain();