10 function wfSpecialUserlogin( $par = '' ) {
12 if( session_id() == '' ) {
16 $form = new LoginForm( $wgRequest, $par );
21 * implements Special:Login
22 * @ingroup SpecialPage
29 const WRONG_PLUGIN_PASS
= 3;
35 const CREATE_BLOCKED
= 9;
38 var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
39 var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword;
40 var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
41 var $mSkipCookieCheck, $mReturnToQuery;
43 private $mExtUser = null;
47 * @param WebRequest $request A WebRequest object passed by reference
49 function LoginForm( &$request, $par = '' ) {
50 global $wgAuth, $wgHiddenPrefs, $wgEnableEmail, $wgRedirectOnLogin;
52 $this->mType
= ( $par == 'signup' ) ?
$par : $request->getText( 'type' ); # Check for [[Special:Userlogin/signup]]
53 $this->mName
= $request->getText( 'wpName' );
54 $this->mPassword
= $request->getText( 'wpPassword' );
55 $this->mRetype
= $request->getText( 'wpRetype' );
56 $this->mDomain
= $request->getText( 'wpDomain' );
57 $this->mReturnTo
= $request->getVal( 'returnto' );
58 $this->mReturnToQuery
= $request->getVal( 'returntoquery' );
59 $this->mCookieCheck
= $request->getVal( 'wpCookieCheck' );
60 $this->mPosted
= $request->wasPosted();
61 $this->mCreateaccount
= $request->getCheck( 'wpCreateaccount' );
62 $this->mCreateaccountMail
= $request->getCheck( 'wpCreateaccountMail' )
64 $this->mMailmypassword
= $request->getCheck( 'wpMailmypassword' )
66 $this->mLoginattempt
= $request->getCheck( 'wpLoginattempt' );
67 $this->mAction
= $request->getVal( 'action' );
68 $this->mRemember
= $request->getCheck( 'wpRemember' );
69 $this->mLanguage
= $request->getText( 'uselang' );
70 $this->mSkipCookieCheck
= $request->getCheck( 'wpSkipCookieCheck' );
72 if ( $wgRedirectOnLogin ) {
73 $this->mReturnTo
= $wgRedirectOnLogin;
74 $this->mReturnToQuery
= '';
77 if( $wgEnableEmail ) {
78 $this->mEmail
= $request->getText( 'wpEmail' );
82 if( !in_array( 'realname', $wgHiddenPrefs ) ) {
83 $this->mRealName
= $request->getText( 'wpRealName' );
85 $this->mRealName
= '';
88 if( !$wgAuth->validDomain( $this->mDomain
) ) {
89 $this->mDomain
= 'invaliddomain';
91 $wgAuth->setDomain( $this->mDomain
);
93 # When switching accounts, it sucks to get automatically logged out
94 $returnToTitle = Title
::newFromText( $this->mReturnTo
);
95 if( is_object( $returnToTitle ) && $returnToTitle->isSpecial( 'Userlogout' ) ) {
96 $this->mReturnTo
= '';
97 $this->mReturnToQuery
= '';
102 if ( !is_null( $this->mCookieCheck
) ) {
103 $this->onCookieRedirectCheck( $this->mCookieCheck
);
105 } else if( $this->mPosted
) {
106 if( $this->mCreateaccount
) {
107 return $this->addNewAccount();
108 } else if ( $this->mCreateaccountMail
) {
109 return $this->addNewAccountMailPassword();
110 } else if ( $this->mMailmypassword
) {
111 return $this->mailPassword();
112 } else if ( ( 'submitlogin' == $this->mAction
) ||
$this->mLoginattempt
) {
113 return $this->processLogin();
116 $this->mainLoginForm( '' );
122 function addNewAccountMailPassword() {
125 if ( $this->mEmail
== '' ) {
126 $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName
) ) );
130 $u = $this->addNewaccountInternal();
136 // Wipe the initial password and mail a temporary one
137 $u->setPassword( null );
139 $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
141 wfRunHooks( 'AddNewAccount', array( $u, true ) );
142 $u->addNewUserLogEntry();
144 $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) );
145 $wgOut->setRobotPolicy( 'noindex,nofollow' );
146 $wgOut->setArticleRelated( false );
148 if( WikiError
::isError( $result ) ) {
149 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
151 $wgOut->addWikiMsg( 'accmailtext', $u->getName(), $u->getEmail() );
152 $wgOut->returnToMain( false );
161 function addNewAccount() {
162 global $wgUser, $wgEmailAuthentication;
164 # Create the account and abort if there's a problem doing so
165 $u = $this->addNewAccountInternal();
169 # If we showed up language selection links, and one was in use, be
170 # smart (and sensible) and save that language as the user's preference
171 global $wgLoginLanguageSelector;
172 if( $wgLoginLanguageSelector && $this->mLanguage
)
173 $u->setOption( 'language', $this->mLanguage
);
175 # Send out an email authentication message if needed
176 if( $wgEmailAuthentication && User
::isValidEmailAddr( $u->getEmail() ) ) {
178 $error = $u->sendConfirmationMail();
179 if( WikiError
::isError( $error ) ) {
180 $wgOut->addWikiMsg( 'confirmemail_sendfailed', $error->getMessage() );
182 $wgOut->addWikiMsg( 'confirmemail_oncreate' );
186 # Save settings (including confirmation token)
189 # If not logged in, assume the new account as the current one and set
190 # session cookies then show a "welcome" message or a "need cookies"
192 if( $wgUser->isAnon() ) {
194 $wgUser->setCookies();
195 wfRunHooks( 'AddNewAccount', array( $wgUser, false ) );
196 $wgUser->addNewUserLogEntry();
197 if( $this->hasSessionCookie() ) {
198 return $this->successfulCreation();
200 return $this->cookieRedirectCheck( 'new' );
203 # Confirm that the account was created
205 $self = SpecialPage
::getTitleFor( 'Userlogin' );
206 $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) );
207 $wgOut->setArticleRelated( false );
208 $wgOut->setRobotPolicy( 'noindex,nofollow' );
209 $wgOut->addHTML( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) );
210 $wgOut->returnToMain( false, $self );
211 wfRunHooks( 'AddNewAccount', array( $u, false ) );
212 $u->addNewUserLogEntry();
220 function addNewAccountInternal() {
221 global $wgUser, $wgOut;
222 global $wgMemc, $wgAccountCreationThrottle;
223 global $wgAuth, $wgMinimalPasswordLength;
224 global $wgEmailConfirmToEdit;
226 // If the user passes an invalid domain, something is fishy
227 if( !$wgAuth->validDomain( $this->mDomain
) ) {
228 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
232 // If we are not allowing users to login locally, we should be checking
233 // to see if the user is actually able to authenticate to the authenti-
234 // cation server before they create an account (otherwise, they can
235 // create a local account and login as any domain user). We only need
236 // to check this for domains that aren't local.
237 if( 'local' != $this->mDomain
&& $this->mDomain
!= '' ) {
238 if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName
) ||
!$wgAuth->authenticate( $this->mName
, $this->mPassword
) ) ) {
239 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
244 if ( wfReadOnly() ) {
245 $wgOut->readOnlyPage();
250 if ( !$wgUser->isAllowed( 'createaccount' ) ) {
251 $this->userNotPrivilegedMessage();
253 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
254 $this->userBlockedMessage();
259 if ( $wgUser->isDnsBlacklisted( $ip, true /* check $wgProxyWhitelist */ ) ) {
260 $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' );
264 # Now create a dummy user ($u) and check if it is valid
265 $name = trim( $this->mName
);
266 $u = User
::newFromName( $name, 'creatable' );
267 if ( WikiError
::isError( $u ) ) {
268 $this->mainLoginForm( wfMsg( $u->getMessage() ) );
272 if ( !is_object( $u ) ) {
273 $this->mainLoginForm( wfMsg( 'noname' ) );
277 if ( 0 != $u->idForName() ) {
278 $this->mainLoginForm( wfMsg( 'userexists' ) );
282 if ( 0 != strcmp( $this->mPassword
, $this->mRetype
) ) {
283 $this->mainLoginForm( wfMsg( 'badretype' ) );
287 # check for minimal password length
288 $valid = $u->getPasswordValidity( $this->mPassword
);
289 if ( $valid !== true ) {
290 if ( !$this->mCreateaccountMail
) {
291 $this->mainLoginForm( wfMsgExt( $valid, array( 'parsemag' ), $wgMinimalPasswordLength ) );
294 # do not force a password for account creation by email
295 # set invalid password, it will be replaced later by a random generated password
296 $this->mPassword
= null;
300 # if you need a confirmed email address to edit, then obviously you
301 # need an email address.
302 if ( $wgEmailConfirmToEdit && empty( $this->mEmail
) ) {
303 $this->mainLoginForm( wfMsg( 'noemailtitle' ) );
307 if( !empty( $this->mEmail
) && !User
::isValidEmailAddr( $this->mEmail
) ) {
308 $this->mainLoginForm( wfMsg( 'invalidemailaddress' ) );
312 # Set some additional data so the AbortNewAccount hook can be used for
313 # more than just username validation
314 $u->setEmail( $this->mEmail
);
315 $u->setRealName( $this->mRealName
);
318 if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) {
319 // Hook point to add extra creation throttles and blocks
320 wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
321 $this->mainLoginForm( $abortError );
325 if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) {
326 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
327 $value = $wgMemc->get( $key );
329 $wgMemc->set( $key, 0, 86400 );
331 if ( $value >= $wgAccountCreationThrottle ) {
332 $this->throttleHit( $wgAccountCreationThrottle );
335 $wgMemc->incr( $key );
338 if( !$wgAuth->addUser( $u, $this->mPassword
, $this->mEmail
, $this->mRealName
) ) {
339 $this->mainLoginForm( wfMsg( 'externaldberror' ) );
343 return $this->initUser( $u, false );
347 * Actually add a user to the database.
348 * Give it a User object that has been initialised with a name.
350 * @param $u User object.
351 * @param $autocreate boolean -- true if this is an autocreation via auth plugin
352 * @return User object.
355 function initUser( $u, $autocreate ) {
360 if ( $wgAuth->allowPasswordChange() ) {
361 $u->setPassword( $this->mPassword
);
364 $u->setEmail( $this->mEmail
);
365 $u->setRealName( $this->mRealName
);
368 $wgAuth->initUser( $u, $autocreate );
370 if ( $this->mExtUser
) {
371 $this->mExtUser
->linkToLocal( $u->getId() );
372 $email = $this->mExtUser
->getPref( 'emailaddress' );
373 if ( $email && !$this->mEmail
) {
374 $u->setEmail( $email );
378 $u->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
382 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
383 $ssUpdate->doUpdate();
389 * Internally authenticate the login request.
391 * This may create a local account as a side effect if the
392 * authentication plugin allows transparent local account
395 public function authenticateUserData() {
396 global $wgUser, $wgAuth;
397 if ( $this->mName
== '' ) {
398 return self
::NO_NAME
;
401 global $wgPasswordAttemptThrottle;
404 if ( is_array( $wgPasswordAttemptThrottle ) ) {
405 $throttleKey = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName
) );
406 $count = $wgPasswordAttemptThrottle['count'];
407 $period = $wgPasswordAttemptThrottle['seconds'];
410 $throttleCount = $wgMemc->get( $throttleKey );
411 if ( !$throttleCount ) {
412 $wgMemc->add( $throttleKey, 1, $period ); // start counter
413 } else if ( $throttleCount < $count ) {
414 $wgMemc->incr($throttleKey);
415 } else if ( $throttleCount >= $count ) {
416 return self
::THROTTLED
;
420 // Load $wgUser now, and check to see if we're logging in as the same
421 // name. This is necessary because loading $wgUser (say by calling
422 // getName()) calls the UserLoadFromSession hook, which potentially
423 // creates the user in the database. Until we load $wgUser, checking
424 // for user existence using User::newFromName($name)->getId() below
425 // will effectively be using stale data.
426 if ( $wgUser->getName() === $this->mName
) {
427 wfDebug( __METHOD__
.": already logged in as {$this->mName}\n" );
428 return self
::SUCCESS
;
431 $this->mExtUser
= ExternalUser
::newFromName( $this->mName
);
433 # TODO: Allow some magic here for invalid external names, e.g., let the
434 # user choose a different wiki name.
435 $u = User
::newFromName( $this->mName
);
436 if( is_null( $u ) ||
!User
::isUsableName( $u->getName() ) ) {
437 return self
::ILLEGAL
;
440 $isAutoCreated = false;
441 if ( 0 == $u->getID() ) {
442 $status = $this->attemptAutoCreate( $u );
443 if ( $status !== self
::SUCCESS
) {
446 $isAutoCreated = true;
449 global $wgExternalAuthType, $wgAutocreatePolicy;
450 if ( $wgExternalAuthType && $wgAutocreatePolicy != 'never'
451 && is_object( $this->mExtUser
)
452 && $this->mExtUser
->authenticate( $this->mPassword
) ) {
453 # The external user and local user have the same name and
454 # password, so we assume they're the same.
455 $this->mExtUser
->linkToLocal( $u->getID() );
461 // Give general extensions, such as a captcha, a chance to abort logins
462 $abort = self
::ABORTED
;
463 if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword
, &$abort ) ) ) {
467 if (!$u->checkPassword( $this->mPassword
)) {
468 if( $u->checkTemporaryPassword( $this->mPassword
) ) {
469 // The e-mailed temporary password should not be used for actu-
470 // al logins; that's a very sloppy habit, and insecure if an
471 // attacker has a few seconds to click "search" on someone's o-
474 // Allow it to be used only to reset the password a single time
475 // to a new value, which won't be in the user's e-mail ar-
478 // For backwards compatibility, we'll still recognize it at the
479 // login form to minimize surprises for people who have been
480 // logging in with a temporary password for some time.
482 // As a side-effect, we can authenticate the user's e-mail ad-
483 // dress if it's not already done, since the temporary password
484 // was sent via e-mail.
485 if( !$u->isEmailConfirmed() ) {
490 // At this point we just return an appropriate code/ indicating
491 // that the UI should show a password reset form; bot inter-
492 // faces etc will probably just fail cleanly here.
493 $retval = self
::RESET_PASS
;
495 $retval = ($this->mPassword
== '') ? self
::EMPTY_PASS
: self
::WRONG_PASS
;
498 $wgAuth->updateUser( $u );
501 // Please reset throttle for successful logins, thanks!
503 $wgMemc->delete($throttleKey);
506 if ( $isAutoCreated ) {
507 // Must be run after $wgUser is set, for correct new user log
508 wfRunHooks( 'AuthPluginAutoCreate', array( $wgUser ) );
511 $retval = self
::SUCCESS
;
513 wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword
, $retval ) );
518 * Attempt to automatically create a user on login. Only succeeds if there
519 * is an external authentication method which allows it.
520 * @return integer Status code
522 function attemptAutoCreate( $user ) {
523 global $wgAuth, $wgUser, $wgAutocreatePolicy;
525 if ( $wgUser->isBlockedFromCreateAccount() ) {
526 wfDebug( __METHOD__
.": user is blocked from account creation\n" );
527 return self
::CREATE_BLOCKED
;
531 * If the external authentication plugin allows it, automatically cre-
532 * ate a new account for users that are externally defined but have not
535 if ( $this->mExtUser
) {
536 # mExtUser is neither null nor false, so use the new ExternalAuth
538 if ( $wgAutocreatePolicy == 'never' ) {
539 return self
::NOT_EXISTS
;
541 if ( !$this->mExtUser
->authenticate( $this->mPassword
) ) {
542 return self
::WRONG_PLUGIN_PASS
;
546 if ( !$wgAuth->autoCreate() ) {
547 return self
::NOT_EXISTS
;
549 if ( !$wgAuth->userExists( $user->getName() ) ) {
550 wfDebug( __METHOD__
.": user does not exist\n" );
551 return self
::NOT_EXISTS
;
553 if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword
) ) {
554 wfDebug( __METHOD__
.": \$wgAuth->authenticate() returned false, aborting\n" );
555 return self
::WRONG_PLUGIN_PASS
;
559 wfDebug( __METHOD__
.": creating account\n" );
560 $user = $this->initUser( $user, true );
561 return self
::SUCCESS
;
564 function processLogin() {
565 global $wgUser, $wgAuth;
567 switch ( $this->authenticateUserData() ) {
569 # We've verified now, update the real record
570 if( (bool)$this->mRemember
!= (bool)$wgUser->getOption( 'rememberpassword' ) ) {
571 $wgUser->setOption( 'rememberpassword', $this->mRemember ?
1 : 0 );
572 $wgUser->saveSettings();
574 $wgUser->invalidateCache();
576 $wgUser->setCookies();
578 // Reset the throttle
579 $key = wfMemcKey( 'password-throttle', wfGetIP(), md5( $this->mName
) );
581 $wgMemc->delete( $key );
583 if( $this->hasSessionCookie() ||
$this->mSkipCookieCheck
) {
584 /* Replace the language object to provide user interface in
585 * correct language immediately on this first page load.
587 global $wgLang, $wgRequest;
588 $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
589 $wgLang = Language
::factory( $code );
590 return $this->successfulLogin();
592 return $this->cookieRedirectCheck( 'login' );
598 $this->mainLoginForm( wfMsg( 'noname' ) );
600 case self
::WRONG_PLUGIN_PASS
:
601 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
603 case self
::NOT_EXISTS
:
604 if( $wgUser->isAllowed( 'createaccount' ) ){
605 $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $this->mName
) ) );
607 $this->mainLoginForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->mName
) ) );
610 case self
::WRONG_PASS
:
611 $this->mainLoginForm( wfMsg( 'wrongpassword' ) );
613 case self
::EMPTY_PASS
:
614 $this->mainLoginForm( wfMsg( 'wrongpasswordempty' ) );
616 case self
::RESET_PASS
:
617 $this->resetLoginForm( wfMsg( 'resetpass_announce' ) );
619 case self
::CREATE_BLOCKED
:
620 $this->userBlockedMessage();
622 case self
::THROTTLED
:
623 $this->mainLoginForm( wfMsg( 'login-throttled' ) );
626 throw new MWException( "Unhandled case value" );
630 function resetLoginForm( $error ) {
632 $wgOut->addHTML( Xml
::element('p', array( 'class' => 'error' ), $error ) );
633 $reset = new SpecialResetpass();
634 $reset->execute( null );
640 function mailPassword() {
641 global $wgUser, $wgOut, $wgAuth;
643 if ( wfReadOnly() ) {
644 $wgOut->readOnlyPage();
648 if( !$wgAuth->allowPasswordChange() ) {
649 $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) );
653 # Check against blocked IPs
654 # fixme -- should we not?
655 if( $wgUser->isBlocked() ) {
656 $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) );
662 if ( ! wfRunHooks( 'UserLoginMailPassword', array( $this->mName
, &$error ) ) ) {
663 $this->mainLoginForm( $error );
667 # Check against the rate limiter
668 if( $wgUser->pingLimiter( 'mailpassword' ) ) {
669 $wgOut->rateLimited();
673 if ( $this->mName
== '' ) {
674 $this->mainLoginForm( wfMsg( 'noname' ) );
677 $u = User
::newFromName( $this->mName
);
678 if( is_null( $u ) ) {
679 $this->mainLoginForm( wfMsg( 'noname' ) );
682 if ( 0 == $u->getID() ) {
683 $this->mainLoginForm( wfMsgWikiHtml( 'nosuchuser', htmlspecialchars( $u->getName() ) ) );
687 # Check against password throttle
688 if ( $u->isPasswordReminderThrottled() ) {
689 global $wgPasswordReminderResendTime;
690 # Round the time in hours to 3 d.p., in case someone is specifying
691 # minutes or seconds.
692 $this->mainLoginForm( wfMsgExt( 'throttled-mailpassword', array( 'parsemag' ),
693 round( $wgPasswordReminderResendTime, 3 ) ) );
697 $result = $this->mailPasswordInternal( $u, true, 'passwordremindertitle', 'passwordremindertext' );
698 if( WikiError
::isError( $result ) ) {
699 $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) );
701 $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' );
708 * @param bool throttle
709 * @param string message name of email title
710 * @param string message name of email text
711 * @return mixed true on success, WikiError on failure
714 function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
715 global $wgServer, $wgScript, $wgUser, $wgNewPasswordExpiry;
717 if ( $u->getEmail() == '' ) {
718 return new WikiError( wfMsg( 'noemail', $u->getName() ) );
722 return new WikiError( wfMsg( 'badipaddress' ) );
725 wfRunHooks( 'User::mailPasswordInternal', array(&$wgUser, &$ip, &$u) );
727 $np = $u->randomPassword();
728 $u->setNewpassword( $np, $throttle );
730 $userLanguage = $u->getOption( 'language' );
731 $m = wfMsgExt( $emailText, array( 'parsemag', 'language' => $userLanguage ), $ip, $u->getName(), $np,
732 $wgServer . $wgScript, round( $wgNewPasswordExpiry / 86400 ) );
733 $result = $u->sendMail( wfMsgExt( $emailTitle, array( 'parsemag', 'language' => $userLanguage ) ), $m );
740 * Run any hooks registered for logins, then HTTP redirect to
741 * $this->mReturnTo (or Main Page if that's undefined). Formerly we had a
742 * nice message here, but that's really not as useful as just being sent to
743 * wherever you logged in from. It should be clear that the action was
744 * successful, given the lack of error messages plus the appearance of your
745 * name in the upper right.
749 function successfulLogin() {
750 global $wgUser, $wgOut;
752 # Run any hooks; display injected HTML if any, else redirect
754 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
756 if( $injected_html !== '' ) {
757 $this->displaySuccessfulLogin( 'loginsuccess', $injected_html );
759 $titleObj = Title
::newFromText( $this->mReturnTo
);
760 if ( !$titleObj instanceof Title
) {
761 $titleObj = Title
::newMainPage();
763 $wgOut->redirect( $titleObj->getFullURL( $this->mReturnToQuery
) );
768 * Run any hooks registered for logins, then display a message welcoming
773 function successfulCreation() {
774 global $wgUser, $wgOut;
776 # Run any hooks; display injected HTML
778 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
780 $this->displaySuccessfulLogin( 'welcomecreation', $injected_html );
784 * Display a "login successful" page.
786 private function displaySuccessfulLogin( $msgname, $injected_html ) {
787 global $wgOut, $wgUser;
789 $wgOut->setPageTitle( wfMsg( 'loginsuccesstitle' ) );
790 $wgOut->setRobotPolicy( 'noindex,nofollow' );
791 $wgOut->setArticleRelated( false );
792 $wgOut->addWikiMsg( $msgname, $wgUser->getName() );
793 $wgOut->addHTML( $injected_html );
795 if ( !empty( $this->mReturnTo
) ) {
796 $wgOut->returnToMain( null, $this->mReturnTo
, $this->mReturnToQuery
);
798 $wgOut->returnToMain( null );
803 function userNotPrivilegedMessage($errors) {
806 $wgOut->setPageTitle( wfMsg( 'permissionserrors' ) );
807 $wgOut->setRobotPolicy( 'noindex,nofollow' );
808 $wgOut->setArticleRelated( false );
810 $wgOut->addWikitext( $wgOut->formatPermissionsErrorMessage( $errors, 'createaccount' ) );
811 // Stuff that might want to be added at the end. For example, instruc-
813 $wgOut->addWikiMsg( 'cantcreateaccount-nonblock-text' );
815 $wgOut->returnToMain( false );
819 function userBlockedMessage() {
820 global $wgOut, $wgUser;
822 # Let's be nice about this, it's likely that this feature will be used
823 # for blocking large numbers of innocent people, e.g. range blocks on
824 # schools. Don't blame it on the user. There's a small chance that it
825 # really is the user's fault, i.e. the username is blocked and they
826 # haven't bothered to log out before trying to create an account to
827 # evade it, but we'll leave that to their guilty conscience to figure
830 $wgOut->setPageTitle( wfMsg( 'cantcreateaccounttitle' ) );
831 $wgOut->setRobotPolicy( 'noindex,nofollow' );
832 $wgOut->setArticleRelated( false );
835 $blocker = User
::whoIs( $wgUser->mBlock
->mBy
);
836 $block_reason = $wgUser->mBlock
->mReason
;
838 if ( strval( $block_reason ) === '' ) {
839 $block_reason = wfMsg( 'blockednoreason' );
841 $wgOut->addWikiMsg( 'cantcreateaccount-text', $ip, $block_reason, $blocker );
842 $wgOut->returnToMain( false );
848 function mainLoginForm( $msg, $msgtype = 'error' ) {
849 global $wgUser, $wgOut, $wgHiddenPrefs, $wgEnableEmail;
850 global $wgCookiePrefix, $wgLoginLanguageSelector;
851 global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
853 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
855 if ( $this->mType
== 'signup' ) {
856 // Block signup here if in readonly. Keeps user from
857 // going through the process (filling out data, etc)
858 // and being informed later.
859 if ( wfReadOnly() ) {
860 $wgOut->readOnlyPage();
862 } elseif ( $wgUser->isBlockedFromCreateAccount() ) {
863 $this->userBlockedMessage();
865 } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $wgUser, true ) )>0 ) {
866 $wgOut->showPermissionsErrorPage( $permErrors, 'createaccount' );
871 if ( $this->mName
== '' ) {
872 if ( $wgUser->isLoggedIn() ) {
873 $this->mName
= $wgUser->getName();
875 $this->mName
= isset( $_COOKIE[$wgCookiePrefix.'UserName'] ) ?
$_COOKIE[$wgCookiePrefix.'UserName'] : null;
879 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
881 if ( $this->mType
== 'signup' ) {
882 $template = new UsercreateTemplate();
883 $q = 'action=submitlogin&type=signup';
884 $linkq = 'type=login';
885 $linkmsg = 'gotaccount';
887 $template = new UserloginTemplate();
888 $q = 'action=submitlogin&type=login';
889 $linkq = 'type=signup';
890 $linkmsg = 'nologin';
893 if ( !empty( $this->mReturnTo
) ) {
894 $returnto = '&returnto=' . wfUrlencode( $this->mReturnTo
);
895 if ( !empty( $this->mReturnToQuery
) )
896 $returnto .= '&returntoquery=' .
897 wfUrlencode( $this->mReturnToQuery
);
902 # Pass any language selection on to the mode switch link
903 if( $wgLoginLanguageSelector && $this->mLanguage
)
904 $linkq .= '&uselang=' . $this->mLanguage
;
906 $link = '<a href="' . htmlspecialchars ( $titleObj->getLocalUrl( $linkq ) ) . '">';
907 $link .= wfMsgHtml( $linkmsg . 'link' ); # Calling either 'gotaccountlink' or 'nologinlink'
910 # Don't show a "create account" link if the user can't
911 if( $this->showCreateOrLoginLink( $wgUser ) )
912 $template->set( 'link', wfMsgWikiHtml( $linkmsg, $link ) );
914 $template->set( 'link', '' );
916 $template->set( 'header', '' );
917 $template->set( 'name', $this->mName
);
918 $template->set( 'password', $this->mPassword
);
919 $template->set( 'retype', $this->mRetype
);
920 $template->set( 'email', $this->mEmail
);
921 $template->set( 'realname', $this->mRealName
);
922 $template->set( 'domain', $this->mDomain
);
924 $template->set( 'action', $titleObj->getLocalUrl( $q ) );
925 $template->set( 'message', $msg );
926 $template->set( 'messagetype', $msgtype );
927 $template->set( 'createemail', $wgEnableEmail && $wgUser->isLoggedIn() );
928 $template->set( 'userealname', !in_array( 'realname', $wgHiddenPrefs ) );
929 $template->set( 'useemail', $wgEnableEmail );
930 $template->set( 'emailrequired', $wgEmailConfirmToEdit );
931 $template->set( 'canreset', $wgAuth->allowPasswordChange() );
932 $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
933 $template->set( 'remember', $wgUser->getOption( 'rememberpassword' ) or $this->mRemember
);
935 # Prepare language selection links as needed
936 if( $wgLoginLanguageSelector ) {
937 $template->set( 'languages', $this->makeLanguageSelector() );
938 if( $this->mLanguage
)
939 $template->set( 'uselang', $this->mLanguage
);
942 // Give authentication and captcha plugins a chance to modify the form
943 $wgAuth->modifyUITemplate( $template, $this->mType
);
944 if ( $this->mType
== 'signup' ) {
945 wfRunHooks( 'UserCreateForm', array( &$template ) );
947 wfRunHooks( 'UserLoginForm', array( &$template ) );
950 //Changes the title depending on permissions for creating account
951 if ( $wgUser->isAllowed( 'createaccount' ) ) {
952 $wgOut->setPageTitle( wfMsg( 'userlogin' ) );
954 $wgOut->setPageTitle( wfMsg( 'userloginnocreate' ) );
957 $wgOut->setRobotPolicy( 'noindex,nofollow' );
958 $wgOut->setArticleRelated( false );
959 $wgOut->disallowUserJs(); // just in case...
960 $wgOut->addTemplate( $template );
966 function showCreateOrLoginLink( &$user ) {
967 if( $this->mType
== 'signup' ) {
969 } elseif( $user->isAllowed( 'createaccount' ) ) {
977 * Check if a session cookie is present.
979 * This will not pick up a cookie set during _this_ request, but is meant
980 * to ensure that the client is returning the cookie which was set on a
981 * previous pass through the system.
985 function hasSessionCookie() {
986 global $wgDisableCookieCheck, $wgRequest;
987 return $wgDisableCookieCheck ?
true : $wgRequest->checkSessionCookie();
993 function cookieRedirectCheck( $type ) {
996 $titleObj = SpecialPage
::getTitleFor( 'Userlogin' );
997 $query = array( 'wpCookieCheck' => $type );
998 if ( $this->mReturnTo
) $query['returnto'] = $this->mReturnTo
;
999 $check = $titleObj->getFullURL( $query );
1001 return $wgOut->redirect( $check );
1007 function onCookieRedirectCheck( $type ) {
1008 if ( !$this->hasSessionCookie() ) {
1009 if ( $type == 'new' ) {
1010 return $this->mainLoginForm( wfMsgExt( 'nocookiesnew', array( 'parseinline' ) ) );
1011 } else if ( $type == 'login' ) {
1012 return $this->mainLoginForm( wfMsgExt( 'nocookieslogin', array( 'parseinline' ) ) );
1015 return $this->mainLoginForm( wfMsg( 'error' ) );
1018 return $this->successfulLogin();
1025 function throttleHit( $limit ) {
1026 $this->mainLoginForm( wfMsgExt( 'acct_creation_throttle_hit', array( 'parseinline' ), $limit ) );
1030 * Produce a bar of links which allow the user to select another language
1031 * during login/registration but retain "returnto"
1035 function makeLanguageSelector() {
1038 $msg = wfMsgForContent( 'loginlanguagelinks' );
1039 if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
1040 $langs = explode( "\n", $msg );
1042 foreach( $langs as $lang ) {
1043 $lang = trim( $lang, '* ' );
1044 $parts = explode( '|', $lang );
1045 if (count($parts) >= 2) {
1046 $links[] = $this->makeLanguageSelectorLink( $parts[0], $parts[1] );
1049 return count( $links ) > 0 ?
wfMsgHtml( 'loginlanguagelabel', $wgLang->pipeList( $links ) ) : '';
1056 * Create a language selector link for a particular language
1057 * Links back to this page preserving type and returnto
1059 * @param $text Link text
1060 * @param $lang Language code
1062 function makeLanguageSelectorLink( $text, $lang ) {
1064 $self = SpecialPage
::getTitleFor( 'Userlogin' );
1065 $attr = array( 'uselang' => $lang );
1066 if( $this->mType
== 'signup' )
1067 $attr['type'] = 'signup';
1068 if( $this->mReturnTo
)
1069 $attr['returnto'] = $this->mReturnTo
;
1070 $skin = $wgUser->getSkin();
1071 return $skin->linkKnown(
1073 htmlspecialchars( $text ),