From: csteipp Date: Thu, 22 Aug 2013 03:42:32 +0000 (-0700) Subject: Setup cookies security based on user preference X-Git-Tag: 1.31.0-rc.0~18887 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=c99b0dcaa69982b27d7df3f86361cf460ac10d89;p=lhc%2Fweb%2Fwiklou.git Setup cookies security based on user preference Use the user pref instead of the login form checkbox for setting up cookie security on login. The preferences menu is still broken (always shows checked, even if preference has been turned off), but this will log the user in (over https), and then redirect them back to http if they have selected to not use https. Likewise, if they have the default preference to use https, they get the forceHTTPS cookie and other cookies secure. Change-Id: I08f67b35f355ef193ae86cb9cca3799e247ead4e --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index c04402e092..92cbab353a 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3999,13 +3999,6 @@ $wgUserrightsInterwikiDelimiter = '@'; */ $wgSecureLogin = false; -/** - * By default, keep users logged in via HTTPS when $wgSecureLogin is also - * true. Users opt-out of HTTPS when they login by de-selecting the checkbox. - * @since 1.21 - */ -$wgSecureLoginDefaultHTTPS = true; - /** @} */ # end user accounts } /************************************************************************//** diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index bb31bdfbf2..2739df311d 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -618,10 +618,6 @@ class SkinTemplate extends Skin { } } - if ( $wgSecureLogin && $request->detectProtocol() === 'https' ) { - $a['wpStickHTTPS'] = true; - } - $returnto = wfArrayToCgi( $a ); if ( $this->loggedin ) { $personal_urls['userpage'] = array( diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index d4784a5322..db8ddcd56b 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -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->getBool( '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' ); @@ -175,10 +176,10 @@ class LoginForm extends SpecialPage { $query = array( 'returnto' => $this->mReturnTo, 'returntoquery' => $this->mReturnToQuery, - 'wpStickHTTPS' => $this->mStickHTTPS ); $url = $title->getFullURL( $query, false, PROTO_HTTPS ); if ( $wgSecureLogin && wfCanIPUseHTTPS( $this->getRequest()->getIP() ) ) { + $url = wfAppendQuery( $url, 'fromhttp=1' ); $this->getOutput()->redirect( $url ); return; } else { @@ -1041,7 +1042,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(); @@ -1124,15 +1125,6 @@ class LoginForm extends SpecialPage { $template->set( 'link', '' ); } - // Decide if we default stickHTTPS on - if ( $wgSecureLoginDefaultHTTPS - && $this->mAction != 'submitlogin' - && !$this->mLoginattempt - && wfCanIPUseHTTPS( $this->getRequest()->getIP() ) ) - { - $this->mStickHTTPS = true; - } - $resetLink = $this->mType == 'signup' ? null : is_array( $wgPasswordResetRoutes ) && in_array( true, array_values( $wgPasswordResetRoutes ) ); @@ -1162,7 +1154,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', (int)$this->mStickHTTPS ); + $template->set( 'stickhttps', (int) $this->mStickHTTPS ); if ( $this->mType === 'signup' && $user->isLoggedIn() ) { $template->set( 'createAnother', true ); diff --git a/includes/templates/Userlogin.php b/includes/templates/Userlogin.php index 46a0235db0..030b4799d3 100644 --- a/includes/templates/Userlogin.php +++ b/includes/templates/Userlogin.php @@ -170,7 +170,7 @@ class UserloginTemplate extends BaseTemplate { haveData( 'uselang' ) ) { ?> haveData( 'token' ) ) { ?> -data['cansecurelogin'] ) {?> +data['cansecurelogin'] ) {?>