MediaWiki 1.40.4
SpecialUserLogin.php
Go to the documentation of this file.
1<?php
27
34 protected static $allowedActions = [
35 AuthManager::ACTION_LOGIN,
36 AuthManager::ACTION_LOGIN_CONTINUE
37 ];
38
39 protected static $messages = [
40 'authform-newtoken' => 'nocookiesforlogin',
41 'authform-notoken' => 'sessionfailure',
42 'authform-wrongtoken' => 'sessionfailure',
43 ];
44
48 public function __construct( AuthManager $authManager ) {
49 parent::__construct( 'Userlogin' );
50 $this->setAuthManager( $authManager );
51 }
52
53 public function doesWrites() {
54 return true;
55 }
56
57 public function isListed() {
58 return $this->getAuthManager()->canAuthenticateNow();
59 }
60
61 protected function getLoginSecurityLevel() {
62 return false;
63 }
64
65 protected function getDefaultAction( $subPage ) {
66 return AuthManager::ACTION_LOGIN;
67 }
68
69 public function getDescription() {
70 return $this->msg( 'login' )->text();
71 }
72
73 public function setHeaders() {
74 // override the page title if we are doing a forced reauthentication
75 parent::setHeaders();
76 if ( $this->securityLevel && $this->getUser()->isRegistered() ) {
77 $this->getOutput()->setPageTitle( $this->msg( 'login-security' ) );
78 }
79 }
80
81 protected function isSignup() {
82 return false;
83 }
84
85 protected function beforeExecute( $subPage ) {
86 if ( $subPage === 'signup' || $this->getRequest()->getText( 'type' ) === 'signup' ) {
87 // B/C for old account creation URLs
88 $title = SpecialPage::getTitleFor( 'CreateAccount' );
89 $query = array_diff_key( $this->getRequest()->getValues(),
90 array_fill_keys( [ 'type', 'title' ], true ) );
91 $url = $title->getFullURL( $query, false, PROTO_CURRENT );
92 $this->getOutput()->redirect( $url );
93 return false;
94 }
95 return parent::beforeExecute( $subPage );
96 }
97
109 protected function successfulAction( $direct = false, $extraMessages = null ) {
110 $secureLogin = $this->getConfig()->get( MainConfigNames::SecureLogin );
111
112 $user = $this->targetUser ?: $this->getUser();
113 $session = $this->getRequest()->getSession();
114
115 if ( $direct ) {
116 $user->touch();
117
118 $this->clearToken();
119
120 if ( $user->requiresHTTPS() ) {
121 $this->mStickHTTPS = true;
122 }
123 $session->setForceHTTPS( $secureLogin && $this->mStickHTTPS );
124
125 // If the user does not have a session cookie at this point, they probably need to
126 // do something to their browser.
127 if ( !$this->hasSessionCookie() ) {
128 $this->mainLoginForm( [ /*?*/ ], $session->getProvider()->whyNoSession() );
129 // TODO something more specific? This used to use nocookieslogin
130 return;
131 }
132 }
133
134 # Run any hooks; display injected HTML if any, else redirect
135 $injected_html = '';
136 $this->getHookRunner()->onUserLoginComplete(
137 $user, $injected_html, $direct );
138
139 if ( $injected_html !== '' || $extraMessages ) {
140 $this->showSuccessPage( 'success', $this->msg( 'loginsuccesstitle' ),
141 'loginsuccess', $injected_html, $extraMessages );
142 } else {
143 $helper = new LoginHelper( $this->getContext() );
144 $helper->showReturnToPage( 'successredirect', $this->mReturnTo, $this->mReturnToQuery,
145 $this->mStickHTTPS );
146 }
147 }
148
149 protected function getToken() {
150 return $this->getRequest()->getSession()->getToken( '', 'login' );
151 }
152
153 protected function clearToken() {
154 return $this->getRequest()->getSession()->resetToken( 'login' );
155 }
156
157 protected function getTokenName() {
158 return 'wpLoginToken';
159 }
160
161 protected function getGroupName() {
162 return 'login';
163 }
164
165 protected function logAuthResult( $success, $status = null ) {
166 LoggerFactory::getInstance( 'authevents' )->info( 'Login attempt', [
167 'event' => 'login',
168 'successful' => $success,
169 'status' => strval( $status ),
170 ] );
171 }
172}
const PROTO_CURRENT
Definition Defines.php:198
string $subPage
Subpage of the special page.
getRequest()
Get the WebRequest being used for this instance.
Helper functions for the login form that need to be shared with other special pages (such as CentralA...
Holds shared logic for login and account creation pages.
mainLoginForm(array $requests, $msg='', $msgtype='error')
showSuccessPage( $type, $title, $msgname, $injected_html, $extraMessages)
Show the success page.
hasSessionCookie()
Check if a session cookie is present.
This serves as the entry point to the authentication system.
PSR-3 logger instance factory.
A class containing constants representing the names of configuration variables.
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
setAuthManager(AuthManager $authManager)
Set the injected AuthManager from the special page constructor.
Implements Special:UserLogin.
getDescription()
Returns the name that goes in the <h1> in the special page itself, and also the name that will be l...
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getDefaultAction( $subPage)
Get the default action for this special page, if none is given via URL/POST data.
logAuthResult( $success, $status=null)
Logs to the authmanager-stats channel.
isListed()
Whether this special page is listed in Special:SpecialPages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getTokenName()
Returns the name of the CSRF token (under which it should be found in the POST or GET data).
__construct(AuthManager $authManager)
successfulAction( $direct=false, $extraMessages=null)
Run any hooks registered for logins, then HTTP redirect to $this->mReturnTo (or Main Page if that's u...
doesWrites()
Indicates whether this special page may perform database writes.
getToken()
Returns the CSRF token.