From 04c5aefbea81ea53d8c73537cd5d7b1262ced19d Mon Sep 17 00:00:00 2001
From: Andrew Ozz
Date: Wed, 27 Mar 2013 08:43:11 +0000
Subject: [PATCH] Logged out warnings: add fallback text dialog for: - The
login page has "X-Frame-Options: DENY" header. - Cross-domain when displaying
on the front-end on multisite with domain mapping. - The site forces ssl
login but not ssl admin.
Add onbeforeunload prompt to counter (frame-busting) JS redirects. Move the JS and CSS into separate files. See #23295.
git-svn-id: http://core.svn.wordpress.org/trunk@23805 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
wp-admin/css/wp-admin.css | 6 +-
wp-includes/css/wp-auth-check.css | 76 +++++++++++++
wp-includes/css/wp-auth-check.min.css | 0
wp-includes/default-filters.php | 2 +-
wp-includes/functions.php | 158 +++++++++-----------------
wp-includes/js/wp-auth-check.js | 87 ++++++++++++++
wp-includes/js/wp-auth-check.min.js | 0
wp-includes/script-loader.php | 6 +
wp-login.php | 58 ++++++----
9 files changed, 267 insertions(+), 126 deletions(-)
create mode 100644 wp-includes/css/wp-auth-check.css
create mode 100644 wp-includes/css/wp-auth-check.min.css
create mode 100644 wp-includes/js/wp-auth-check.js
create mode 100644 wp-includes/js/wp-auth-check.min.js
diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css
index b831e61436..99d444def7 100644
--- a/wp-admin/css/wp-admin.css
+++ b/wp-admin/css/wp-admin.css
@@ -7291,9 +7291,13 @@ a.rsswidget {
width: auto;
}
+body.interim-login {
+ height: auto;
+}
+
.interim-login #login {
padding: 0;
- width: 300px;
+ margin: 25px auto 20px;
}
.interim-login.login h1 a {
diff --git a/wp-includes/css/wp-auth-check.css b/wp-includes/css/wp-auth-check.css
new file mode 100644
index 0000000000..6a4c56f597
--- /dev/null
+++ b/wp-includes/css/wp-auth-check.css
@@ -0,0 +1,76 @@
+/*------------------------------------------------------------------------------
+ Interim login dialog
+------------------------------------------------------------------------------*/
+
+#wp-auth-check-wrap.hidden {
+ display: none;
+}
+
+#wp-auth-check-wrap #wp-auth-check-bg {
+ position: fixed;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ background: #000;
+ opacity: 0.5;
+ filter: alpha(opacity=50);
+ z-index: 1000000;
+}
+
+#wp-auth-check-wrap #wp-auth-check {
+ position: fixed;
+ left: 50%;
+ overflow: hidden;
+ top: 40px;
+ bottom: 20px;
+ max-height: 435px;
+ width: 380px;
+ margin: 0 0 0 -190px;
+ padding: 0;
+ background-color: #fbfbfb;
+ -webkit-border-radius: 3px;
+ border-radius: 3px;
+ z-index: 1000001;
+}
+
+#wp-auth-check-wrap.fallback #wp-auth-check {
+ max-height: 180px;
+ overflow: auto;
+}
+
+#wp-auth-check-wrap #wp-auth-check-form {
+ background: url('../images/wpspin-2x.gif') no-repeat center center;
+ background-size: 16px 16px;
+ height: 100%;
+}
+
+#wp-auth-check-wrap #wp-auth-check-form iframe {
+ height: 100%;
+ width: 100%;
+ overflow: auto;
+}
+
+#wp-auth-check-wrap .wp-auth-check-close {
+ bottom: 10px;
+ display: none;
+ position: absolute;
+ right: 30px;
+}
+
+#wp-auth-check-wrap .wp-auth-fallback-expired {
+ outline: 0;
+}
+
+#wp-auth-check-wrap .wp-auth-fallback {
+ font-size: 14px;
+ line-height: 21px;
+ padding: 10px 25px;
+ display: none;
+}
+
+#wp-auth-check-wrap.fallback .wp-auth-fallback,
+#wp-auth-check-wrap.fallback .wp-auth-check-close {
+ display: block;
+}
+
diff --git a/wp-includes/css/wp-auth-check.min.css b/wp-includes/css/wp-auth-check.min.css
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php
index c24e68d7f2..1827dc94bd 100644
--- a/wp-includes/default-filters.php
+++ b/wp-includes/default-filters.php
@@ -295,6 +295,6 @@ add_filter( 'default_option_embed_autourls', '__return_true' );
add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' );
// Check if the user is logged out
-add_action( 'admin_init', 'wp_auth_check_load' );
+add_action( 'init', 'wp_auth_check_load' );
unset($filter, $action);
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index b55bca12f7..30a7f1715b 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -3887,43 +3887,69 @@ function wp_checkdate( $month, $day, $year, $source_date ) {
}
/**
- * Load the auth check, for monitoring whether the user is still logged in
+ * Load the auth check for monitoring whether the user is still logged in.
+ * Can be disabled with remove_action( 'init', 'wp_auth_check_load' );
*
* @since 3.6.0
*
* @return void
*/
function wp_auth_check_load() {
- wp_enqueue_script( 'heartbeat' );
- add_filter( 'heartbeat_received', 'wp_auth_check', 10, 2 );
- add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 );
+ global $pagenow;
- if ( is_admin() )
- add_action( 'admin_print_footer_scripts', 'wp_auth_check_js' );
- elseif ( is_user_logged_in() )
- add_action( 'wp_print_footer_scripts', 'wp_auth_check_js' );
+ // Don't load for these types of requests
+ if ( defined('XMLRPC_REQUEST') || defined('IFRAME_REQUEST') || 'wp-login.php' == $pagenow )
+ return;
+
+ if ( is_admin() || is_user_logged_in() ) {
+ if ( defined('DOING_AJAX') ) {
+ add_filter( 'heartbeat_received', 'wp_auth_check', 10, 2 );
+ add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 );
+ } else {
+ wp_enqueue_style( 'wp-auth-check' );
+ wp_enqueue_script( 'wp-auth-check' );
+
+ if ( is_admin() )
+ add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 );
+ else
+ add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );
+ }
+ }
}
/**
- * Output the JS that shows the wp-login iframe when the user is no longer logged in
+ * Output the HTML that shows the wp-login dialog when the user is no longer logged in
*/
-function wp_auth_check_js() {
- ?>
-
+ ?>
+
'' ) );
+ return array_merge( $response, array( 'wp-auth-check' => '1' ) );
}
/**
@@ -4039,4 +3987,4 @@ function get_tag_regex( $tag ) {
return;
return sprintf( '(<%1$s[^>]*(?:/?>$|>[\s\S]*?%1$s>))', tag_escape( $tag ) );
-}
\ No newline at end of file
+}
diff --git a/wp-includes/js/wp-auth-check.js b/wp-includes/js/wp-auth-check.js
new file mode 100644
index 0000000000..12144076b2
--- /dev/null
+++ b/wp-includes/js/wp-auth-check.js
@@ -0,0 +1,87 @@
+// Interim login dialog
+(function($){
+ var wrap;
+
+ function show() {
+ var parent = $('#wp-auth-check'), form = $('#wp-auth-check-form'), noframe = wrap.find('.wp-auth-fallback-expired'), frame, loaded = false;
+
+ if ( form.length ) {
+ // Add unload confirmation to counter (frame-busting) JS redirects
+ $(window).on( 'beforeunload.wp-auth-check', function(e) {
+ e.originalEvent.returnValue = window.authcheckL10n.beforeunload;
+ });
+
+ // Add 'sandbox' for browsers that support it, only restrict access to the top window.
+ frame = $('
';
+ $interim_login = 'success';
login_header( '', $message ); ?>
@@ -648,29 +655,42 @@ default:
}
$errors = $user;
- // Clear errors if loggedout or interim_login is set.
- if ( !empty($_GET['loggedout']) || $reauth || $interim_login )
+ // Clear errors if loggedout is set.
+ if ( !empty($_GET['loggedout']) || $reauth )
$errors = new WP_Error();
// If cookies are disabled we can't log in even with a valid user+pass
if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) )
$errors->add('test_cookie', __("ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress."));
- // Some parts of this script use the main login form to display a message
- if ( isset($_GET['loggedout']) && true == $_GET['loggedout'] )
- $errors->add('loggedout', __('You are now logged out.'), 'message');
- elseif ( isset($_GET['registration']) && 'disabled' == $_GET['registration'] )
- $errors->add('registerdisabled', __('User registration is currently not allowed.'));
- elseif ( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] )
- $errors->add('confirm', __('Check your e-mail for the confirmation link.'), 'message');
- elseif ( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] )
- $errors->add('newpass', __('Check your e-mail for your new password.'), 'message');
- elseif ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] )
- $errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
- elseif ( $interim_login )
- $errors->add('expired', __('Please log in again. You will not move away from this page.'), 'message');
- elseif ( strpos( $redirect_to, 'about.php?updated' ) )
- $errors->add('updated', __( 'You have successfully updated WordPress! Please log back in to experience the awesomeness.' ), 'message' );
+ // Clear most errors if interim login
+ if ( $interim_login ) {
+ $error_code = $errors->get_error_code();
+ $errors = new WP_Error();
+
+ if ( $error_code ) {
+ if ( in_array( $error_code, array( 'empty_password', 'empty_username', 'invalid_username', 'incorrect_password' ) ) )
+ $errors->add('interim_login_error', __('ERROR: Invalid username or password.'));
+ else
+ $errors->add('interim_login_error_other', sprintf( __( 'ERROR: Please contact the site administrator or try to log in from a new window.' ), wp_login_url() ) );
+ } else {
+ $errors->add('expired', __('Session expired. Please log in again. You will not move away from this page.'), 'message');
+ }
+ } else {
+ // Some parts of this script use the main login form to display a message
+ if ( isset($_GET['loggedout']) && true == $_GET['loggedout'] )
+ $errors->add('loggedout', __('You are now logged out.'), 'message');
+ elseif ( isset($_GET['registration']) && 'disabled' == $_GET['registration'] )
+ $errors->add('registerdisabled', __('User registration is currently not allowed.'));
+ elseif ( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] )
+ $errors->add('confirm', __('Check your e-mail for the confirmation link.'), 'message');
+ elseif ( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] )
+ $errors->add('newpass', __('Check your e-mail for your new password.'), 'message');
+ elseif ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] )
+ $errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
+ elseif ( strpos( $redirect_to, 'about.php?updated' ) )
+ $errors->add('updated', __( 'You have successfully updated WordPress! Please log back in to experience the awesomeness.' ), 'message' );
+ }
// Clear any stale cookies.
if ( $reauth )