Customizer: Gravefully handle cookie expipration. Prompt for log in in the preview. Props ocean90, koopersmith, nacin. fixes #20876

git-svn-id: https://develop.svn.wordpress.org/trunk@21031 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2012-06-08 19:22:11 +00:00
parent b6a0bae669
commit ab8deebae3
6 changed files with 187 additions and 18 deletions
+21
View File
@@ -514,3 +514,24 @@ body {
-webkit-overflow-scrolling: touch;
}
/**
* Handle cheaters.
*/
body.cheatin {
min-width: 0;
background: #f9f9f9;
padding: 50px;
}
body.cheatin p {
max-width: 700px;
margin: 0 auto;
padding: 2em;
font-size: 14px;
background: #fff;
border: 1px solid #dfdfdf;
-webkit-border-radius: 3px;
border-radius: 3px;
}
+6
View File
@@ -148,6 +148,11 @@ do_action( 'customize_controls_print_scripts' );
'TB_iframe' => 'true'
), home_url( '/' ) );
$login_url = add_query_arg( array(
'interim-login' => 1,
'customize-login' => 1
), wp_login_url() );
$settings = array(
'theme' => array(
'stylesheet' => $wp_customize->get_stylesheet(),
@@ -162,6 +167,7 @@ do_action( 'customize_controls_print_scripts' );
'isCrossDomain' => $cross_domain,
'fallback' => $fallback_url,
'home' => esc_url( home_url( '/' ) ),
'login' => $login_url,
),
'browser' => array(
'mobile' => wp_is_mobile(),
+76 -2
View File
@@ -334,6 +334,18 @@
return;
}
// Check if the user is not logged in.
if ( '0' === response ) {
deferred.rejectWith( self, [ 'logged out' ] );
return;
}
// Check for cheaters.
if ( '-1' === response ) {
deferred.rejectWith( self, [ 'cheatin' ] );
return;
}
// Check for a signature in the request.
index = response.lastIndexOf( signature );
if ( -1 === index || index < response.lastIndexOf('</html>') ) {
@@ -548,7 +560,52 @@
this.loading.fail( function( reason, location ) {
if ( 'redirect' === reason && location )
self.url( location );
if ( 'logged out' === reason ) {
if ( self.iframe ) {
self.iframe.destroy();
delete self.iframe;
}
self.login().done( self.refresh );
}
if ( 'cheatin' === reason )
self.cheatin();
});
},
login: function() {
var previewer = this,
deferred, messenger, iframe;
if ( this._login )
return this._login;
deferred = $.Deferred();
this._login = deferred.promise();
messenger = new api.Messenger({
channel: 'login',
url: api.settings.url.login
});
iframe = $('<iframe src="' + api.settings.url.login + '" />').appendTo( this.container );
messenger.targetWindow( iframe[0].contentWindow );
messenger.bind( 'login', function() {
iframe.remove();
messenger.destroy();
delete previewer._login;
deferred.resolve();
});
return this._login;
},
cheatin: function() {
$( document.body ).empty().addClass('cheatin').append( '<p>' + api.l10n.cheatin + '</p>' );
}
});
@@ -605,7 +662,8 @@
nonce: $('#_wpnonce').val(),
save: function() {
var query = $.extend( this.query(), {
var self = this,
query = $.extend( this.query(), {
action: 'customize_save',
nonce: this.nonce
}),
@@ -619,7 +677,23 @@
body.removeClass('saving');
});
request.done( function() {
request.done( function( response ) {
// Check if the user is logged out.
if ( '0' === response ) {
self.iframe.iframe.hide();
self.login().done( function() {
self.save();
self.iframe.iframe.show();
});
return;
}
// Check for cheaters.
if ( '-1' === response ) {
self.cheatin();
return;
}
api.trigger( 'saved' );
});
}