fix some spacing
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index d9c4244..ddd57c3 100644 (file)
@@ -314,8 +314,10 @@ class LoginForm extends SpecialPage {
                if( 'local' != $this->mDomain && $this->mDomain != '' ) {
                        if(
                                !$wgAuth->canCreateAccounts() &&
-                               ( !$wgAuth->userExists( $this->mUsername ||
-                                 !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) )
+                               (
+                                       !$wgAuth->userExists( $this->mUsername ) ||
+                                       !$wgAuth->authenticate( $this->mUsername, $this->mPassword )
+                               )
                        ) {
                                return Status::newFatal( 'wrongpassword' );
                        }
@@ -371,32 +373,34 @@ class LoginForm extends SpecialPage {
                        return Status::newFatal( 'noname' );
                } elseif ( 0 != $u->idForName() ) {
                        return Status::newFatal( 'userexists' );
-               } elseif ( 0 != strcmp( $this->mPassword, $this->mRetype ) ) {
-                       return Status::newFatal( 'badretype' );
                }
 
-               # check for minimal password length
-               $valid = $u->getPasswordValidity( $this->mPassword );
-               if ( $valid !== true ) {
-                       if ( !$this->mCreateaccountMail ) {
+               if ( $this->mCreateaccountMail ) {
+                       # do not force a password for account creation by email
+                       # set invalid password, it will be replaced later by a random generated password
+                       $this->mPassword = null;
+               } else {
+                       if ( $this->mPassword !== $this->mRetype ) {
+                               return Status::newFatal( 'badretype' );
+                       }
+
+                       # check for minimal password length
+                       $valid = $u->getPasswordValidity( $this->mPassword );
+                       if ( $valid !== true ) {
                                if ( !is_array( $valid ) ) {
                                        $valid = array( $valid, $wgMinimalPasswordLength );
                                }
                                return call_user_func_array( 'Status::newFatal', $valid );
-                       } else {
-                               # do not force a password for account creation by email
-                               # set invalid password, it will be replaced later by a random generated password
-                               $this->mPassword = null;
                        }
                }
 
                # if you need a confirmed email address to edit, then obviously you
                # need an email address.
-               if ( $wgEmailConfirmToEdit && empty( $this->mEmail ) ) {
+               if ( $wgEmailConfirmToEdit && strval( $this->mEmail ) === '' ) {
                        return Status::newFatal( 'noemailtitle' );
                }
 
-               if( !empty( $this->mEmail ) && !Sanitizer::validateEmail( $this->mEmail ) ) {
+               if ( strval( $this->mEmail ) !== '' && !Sanitizer::validateEmail( $this->mEmail ) ) {
                        return Status::newFatal( 'invalidemailaddress' );
                }
 
@@ -600,7 +604,7 @@ class LoginForm extends SpecialPage {
                                // faces etc will probably just fail cleanly here.
                                $retval = self::RESET_PASS;
                        } else {
-                               $retval = ( $this->mPassword  == '' ) ? self::EMPTY_PASS : self::WRONG_PASS;
+                               $retval = ( $this->mPassword == '' ) ? self::EMPTY_PASS : self::WRONG_PASS;
                        }
                } elseif ( $wgBlockDisablesLogin && $u->isBlocked() ) {
                        // If we've enabled it, make it so that a blocked user cannot login
@@ -743,7 +747,7 @@ class LoginForm extends SpecialPage {
                        case self::SUCCESS:
                                # We've verified now, update the real record
                                $user = $this->getUser();
-                               if( (bool)$this->mRemember != (bool)$user->getOption( 'rememberpassword' ) ) {
+                               if( (bool)$this->mRemember != $user->getBoolOption( 'rememberpassword' ) ) {
                                        $user->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
                                        $user->saveSettings();
                                } else {
@@ -828,7 +832,7 @@ class LoginForm extends SpecialPage {
        }
 
        function resetLoginForm( $error ) {
-               $this->getOutput()->addHTML( Xml::element('p', array( 'class' => 'error' ), $error ) );
+               $this->getOutput()->addHTML( Xml::element( 'p', array( 'class' => 'error' ), $error ) );
                $reset = new SpecialChangePassword();
                $reset->setContext( $this->getContext() );
                $reset->execute( null );
@@ -866,7 +870,6 @@ class LoginForm extends SpecialPage {
                return $result;
        }
 
-
        /**
         * Run any hooks registered for logins, then HTTP redirect to
         * $this->mReturnTo (or Main Page if that's undefined).  Formerly we had a
@@ -1011,7 +1014,7 @@ class LoginForm extends SpecialPage {
                global $wgEnableEmail, $wgEnableUserEmail;
                global $wgHiddenPrefs, $wgLoginLanguageSelector;
                global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
-               global $wgSecureLogin, $wgPasswordResetRoutes;
+               global $wgSecureLogin, $wgSecureLoginDefaultHTTPS, $wgPasswordResetRoutes;
 
                $titleObj = $this->getTitle();
                $user = $this->getUser();
@@ -1031,7 +1034,8 @@ class LoginForm extends SpecialPage {
                        }
                }
 
-               if ( $this->mUsername == '' ) {
+               // Pre-fill username (if not creating an account, bug 44775).
+               if ( $this->mUsername == '' && $this->mType != 'signup' ) {
                        if ( $user->isLoggedIn() ) {
                                $this->mUsername = $user->getName();
                        } else {
@@ -1076,6 +1080,11 @@ class LoginForm extends SpecialPage {
                        $template->set( 'link', '' );
                }
 
+               // Decide if we default stickHTTPS on
+               if ( $wgSecureLoginDefaultHTTPS && $this->mAction != 'submitlogin' && !$this->mLoginattempt ) {
+                       $this->mStickHTTPS = true;
+               }
+
                $resetLink = $this->mType == 'signup'
                        ? null
                        : is_array( $wgPasswordResetRoutes ) && in_array( true, array_values( $wgPasswordResetRoutes ) );