| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use LoginHelper; |
| 24 |
use MediaWiki\Auth\AuthManager; |
| 25 |
use MediaWiki\Logger\LoggerFactory; |
| 26 |
use MediaWiki\MainConfigNames; |
| 27 |
use MediaWiki\SpecialPage\LoginSignupSpecialPage; |
| 28 |
use MediaWiki\SpecialPage\SpecialPage; |
| 29 |
use StatusValue; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
class SpecialUserLogin extends LoginSignupSpecialPage { |
| 38 |
|
| 39 |
protected static $allowedActions = [ |
| 40 |
AuthManager::ACTION_LOGIN, |
| 41 |
AuthManager::ACTION_LOGIN_CONTINUE |
| 42 |
]; |
| 43 |
|
| 44 |
|
| 45 |
protected static $messages = [ |
| 46 |
'authform-newtoken' => 'nocookiesforlogin', |
| 47 |
'authform-notoken' => 'sessionfailure', |
| 48 |
'authform-wrongtoken' => 'sessionfailure', |
| 49 |
]; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public function __construct( AuthManager $authManager ) { |
| 55 |
parent::__construct( 'Userlogin' ); |
| 56 |
$this->setAuthManager( $authManager ); |
| 57 |
} |
| 58 |
|
| 59 |
public function doesWrites() { |
| 60 |
return true; |
| 61 |
} |
| 62 |
|
| 63 |
public function isListed() { |
| 64 |
return $this->getAuthManager()->canAuthenticateNow(); |
| 65 |
} |
| 66 |
|
| 67 |
protected function getLoginSecurityLevel() { |
| 68 |
return false; |
| 69 |
} |
| 70 |
|
| 71 |
protected function getDefaultAction( $subPage ) { |
| 72 |
return AuthManager::ACTION_LOGIN; |
| 73 |
} |
| 74 |
|
| 75 |
public function getDescription() { |
| 76 |
return $this->msg( 'login' ); |
| 77 |
} |
| 78 |
|
| 79 |
public function setHeaders() { |
| 80 |
|
| 81 |
parent::setHeaders(); |
| 82 |
if ( $this->securityLevel && $this->getUser()->isRegistered() ) { |
| 83 |
$this->getOutput()->setPageTitleMsg( $this->msg( 'login-security' ) ); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
protected function isSignup() { |
| 88 |
return false; |
| 89 |
} |
| 90 |
|
| 91 |
protected function beforeExecute( $subPage ) { |
| 92 |
if ( $subPage === 'signup' || $this->getRequest()->getText( 'type' ) === 'signup' ) { |
| 93 |
|
| 94 |
$title = SpecialPage::getTitleFor( 'CreateAccount' ); |
| 95 |
$query = array_diff_key( $this->getRequest()->getValues(), |
| 96 |
array_fill_keys( [ 'type', 'title' ], true ) ); |
| 97 |
$url = $title->getFullURL( $query, false, PROTO_CURRENT ); |
| 98 |
$this->getOutput()->redirect( $url ); |
| 99 |
return false; |
| 100 |
} |
| 101 |
return parent::beforeExecute( $subPage ); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
protected function successfulAction( $direct = false, $extraMessages = null ) { |
| 116 |
$secureLogin = $this->getConfig()->get( MainConfigNames::SecureLogin ); |
| 117 |
|
| 118 |
$user = $this->targetUser ?: $this->getUser(); |
| 119 |
$session = $this->getRequest()->getSession(); |
| 120 |
|
| 121 |
$injected_html = ''; |
| 122 |
if ( $direct ) { |
| 123 |
$user->touch(); |
| 124 |
|
| 125 |
$this->clearToken(); |
| 126 |
|
| 127 |
if ( $user->requiresHTTPS() ) { |
| 128 |
$this->mStickHTTPS = true; |
| 129 |
} |
| 130 |
$session->setForceHTTPS( $secureLogin && $this->mStickHTTPS ); |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
if ( !$this->hasSessionCookie() ) { |
| 135 |
$this->mainLoginForm( [ ], $session->getProvider()->whyNoSession() ); |
| 136 |
|
| 137 |
return; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
$this->getHookRunner()->onUserLoginComplete( |
| 142 |
$user, $injected_html, $direct ); |
| 143 |
} |
| 144 |
|
| 145 |
if ( $injected_html !== '' || $extraMessages ) { |
| 146 |
$this->showSuccessPage( 'success', $this->msg( 'loginsuccesstitle' ), |
| 147 |
'loginsuccess', $injected_html, $extraMessages ); |
| 148 |
} else { |
| 149 |
$helper = new LoginHelper( $this->getContext() ); |
| 150 |
$helper->showReturnToPage( 'successredirect', $this->mReturnTo, $this->mReturnToQuery, |
| 151 |
$this->mStickHTTPS, $this->mReturnToAnchor ); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
protected function getToken() { |
| 156 |
return $this->getRequest()->getSession()->getToken( '', 'login' ); |
| 157 |
} |
| 158 |
|
| 159 |
protected function clearToken() { |
| 160 |
$this->getRequest()->getSession()->resetToken( 'login' ); |
| 161 |
} |
| 162 |
|
| 163 |
protected function getTokenName() { |
| 164 |
return 'wpLoginToken'; |
| 165 |
} |
| 166 |
|
| 167 |
protected function getGroupName() { |
| 168 |
return 'login'; |
| 169 |
} |
| 170 |
|
| 171 |
protected function logAuthResult( $success, $status = null ) { |
| 172 |
LoggerFactory::getInstance( 'authevents' )->info( 'Login attempt', [ |
| 173 |
'event' => 'login', |
| 174 |
'successful' => $success, |
| 175 |
'status' => strval( $status ), |
| 176 |
] ); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
class_alias( SpecialUserLogin::class, 'SpecialUserLogin' ); |