Redirect to https for signup
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index df1b16e..a68efc4 100644 (file)
@@ -105,7 +105,8 @@ class LoginForm extends SpecialPage {
                $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
                $this->mAction = $request->getVal( 'action' );
                $this->mRemember = $request->getCheck( 'wpRemember' );
-               $this->mStickHTTPS = $request->getCheck( 'wpStickHTTPS' );
+               $this->mFromHTTP = $request->getBool( 'fromhttp', false );
+               $this->mStickHTTPS = ( !$this->mFromHTTP && $request->detectProtocol() === 'https' ) || $request->getBool( 'wpForceHttps', false );
                $this->mLanguage = $request->getText( 'uselang' );
                $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
                $this->mToken = ( $this->mType == 'signup' ) ? $request->getVal( 'wpCreateaccountToken' ) : $request->getVal( 'wpLoginToken' );
@@ -167,18 +168,15 @@ class LoginForm extends SpecialPage {
 
                // If logging in and not on HTTPS, either redirect to it or offer a link.
                global $wgSecureLogin;
-               if (
-                       $this->mType !== 'signup' &&
-                       WebRequest::detectProtocol() !== 'https'
-               ) {
+               if ( WebRequest::detectProtocol() !== 'https' ) {
                        $title = $this->getFullTitle();
                        $query = array(
                                'returnto' => $this->mReturnTo,
                                'returntoquery' => $this->mReturnToQuery,
-                               'wpStickHTTPS' => $this->mStickHTTPS
                        );
                        $url = $title->getFullURL( $query, false, PROTO_HTTPS );
-                       if ( $wgSecureLogin ) {
+                       if ( $wgSecureLogin && wfCanIPUseHTTPS( $this->getRequest()->getIP() ) ) {
+                               $url = wfAppendQuery( $url, 'fromhttp=1' );
                                $this->getOutput()->redirect( $url );
                                return;
                        } else {
@@ -734,7 +732,7 @@ class LoginForm extends SpecialPage {
        }
 
        function processLogin() {
-               global $wgMemc, $wgLang, $wgSecureLogin;
+               global $wgMemc, $wgLang, $wgSecureLogin, $wgPasswordAttemptThrottle;
 
                switch ( $this->authenticateUserData() ) {
                        case self::SUCCESS:
@@ -747,6 +745,10 @@ class LoginForm extends SpecialPage {
                                        $user->invalidateCache();
                                }
 
+                               if ( $user->requiresHTTPS() ) {
+                                       $this->mStickHTTPS = true;
+                               }
+
                                if ( $wgSecureLogin && !$this->mStickHTTPS ) {
                                        $user->setCookies( null, false );
                                } else {
@@ -810,7 +812,10 @@ class LoginForm extends SpecialPage {
                                $this->userBlockedMessage( $this->getUser()->isBlockedFromCreateAccount() );
                                break;
                        case self::THROTTLED:
-                               $this->mainLoginForm( $this->msg( 'login-throttled' )->text() );
+                               $this->mainLoginForm( $this->msg( 'login-throttled' )
+                               ->params ( $this->getLanguage()->formatDuration( $wgPasswordAttemptThrottle['seconds'] ) )
+                               ->text()
+                               );
                                break;
                        case self::USER_BLOCKED:
                                $this->mainLoginForm( $this->msg( 'login-userblocked',
@@ -1034,7 +1039,7 @@ class LoginForm extends SpecialPage {
                global $wgEnableEmail, $wgEnableUserEmail;
                global $wgHiddenPrefs, $wgLoginLanguageSelector;
                global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
-               global $wgSecureLogin, $wgSecureLoginDefaultHTTPS, $wgPasswordResetRoutes;
+               global $wgSecureLogin, $wgPasswordResetRoutes;
 
                $titleObj = $this->getTitle();
                $user = $this->getUser();
@@ -1117,11 +1122,6 @@ 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 ) );
@@ -1151,7 +1151,7 @@ class LoginForm extends SpecialPage {
                $template->set( 'usereason', $user->isLoggedIn() );
                $template->set( 'remember', $user->getOption( 'rememberpassword' ) || $this->mRemember );
                $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );
-               $template->set( 'stickHTTPS', $this->mStickHTTPS );
+               $template->set( 'stickhttps', (int)$this->mStickHTTPS );
 
                if ( $this->mType === 'signup' && $user->isLoggedIn() ) {
                        $template->set( 'createAnother', true );