MediaWiki REL1_37
SpecialUserLogin.php
Go to the documentation of this file.
1<?php
26
33 protected static $allowedActions = [
34 AuthManager::ACTION_LOGIN,
35 AuthManager::ACTION_LOGIN_CONTINUE
36 ];
37
38 protected static $messages = [
39 'authform-newtoken' => 'nocookiesforlogin',
40 'authform-notoken' => 'sessionfailure',
41 'authform-wrongtoken' => 'sessionfailure',
42 ];
43
48 parent::__construct( 'Userlogin' );
49 $this->setAuthManager( $authManager );
50 }
51
52 public function doesWrites() {
53 return true;
54 }
55
56 protected function getLoginSecurityLevel() {
57 return false;
58 }
59
60 protected function getDefaultAction( $subPage ) {
61 return AuthManager::ACTION_LOGIN;
62 }
63
64 public function getDescription() {
65 return $this->msg( 'login' )->text();
66 }
67
68 public function setHeaders() {
69 // override the page title if we are doing a forced reauthentication
70 parent::setHeaders();
71 if ( $this->securityLevel && $this->getUser()->isRegistered() ) {
72 $this->getOutput()->setPageTitle( $this->msg( 'login-security' ) );
73 }
74 }
75
76 protected function isSignup() {
77 return false;
78 }
79
80 protected function beforeExecute( $subPage ) {
81 if ( $subPage === 'signup' || $this->getRequest()->getText( 'type' ) === 'signup' ) {
82 // B/C for old account creation URLs
83 $title = SpecialPage::getTitleFor( 'CreateAccount' );
84 $query = array_diff_key( $this->getRequest()->getValues(),
85 array_fill_keys( [ 'type', 'title' ], true ) );
86 $url = $title->getFullURL( $query, false, PROTO_CURRENT );
87 $this->getOutput()->redirect( $url );
88 return false;
89 }
90 return parent::beforeExecute( $subPage );
91 }
92
104 protected function successfulAction( $direct = false, $extraMessages = null ) {
105 global $wgSecureLogin;
106
107 $user = $this->targetUser ?: $this->getUser();
108 $session = $this->getRequest()->getSession();
109
110 if ( $direct ) {
111 $user->touch();
112
113 $this->clearToken();
114
115 if ( $user->requiresHTTPS() ) {
116 $this->mStickHTTPS = true;
117 }
118 $session->setForceHTTPS( $wgSecureLogin && $this->mStickHTTPS );
119
120 // If the user does not have a session cookie at this point, they probably need to
121 // do something to their browser.
122 if ( !$this->hasSessionCookie() ) {
123 $this->mainLoginForm( [ /*?*/ ], $session->getProvider()->whyNoSession() );
124 // TODO something more specific? This used to use nocookieslogin
125 return;
126 }
127 }
128
129 # Run any hooks; display injected HTML if any, else redirect
130 $injected_html = '';
131 $this->getHookRunner()->onUserLoginComplete(
132 $user, $injected_html, $direct );
133
134 if ( $injected_html !== '' || $extraMessages ) {
135 $this->showSuccessPage( 'success', $this->msg( 'loginsuccesstitle' ),
136 'loginsuccess', $injected_html, $extraMessages );
137 } else {
138 $helper = new LoginHelper( $this->getContext() );
139 $helper->showReturnToPage( 'successredirect', $this->mReturnTo, $this->mReturnToQuery,
140 $this->mStickHTTPS );
141 }
142 }
143
144 protected function getToken() {
145 return $this->getRequest()->getSession()->getToken( '', 'login' );
146 }
147
148 protected function clearToken() {
149 return $this->getRequest()->getSession()->resetToken( 'login' );
150 }
151
152 protected function getTokenName() {
153 return 'wpLoginToken';
154 }
155
156 protected function getGroupName() {
157 return 'login';
158 }
159
160 protected function logAuthResult( $success, $status = null ) {
161 LoggerFactory::getInstance( 'authevents' )->info( 'Login attempt', [
162 'event' => 'login',
163 'successful' => $success,
164 'status' => strval( $status ),
165 ] );
166 }
167}
$wgSecureLogin
This is to let user authenticate using https when they come from http.
const PROTO_CURRENT
Definition Defines.php:195
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.
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,...
AuthManager null $authManager
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
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.
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.