Make WordPress Core

Changeset 48337


Ignore:
Timestamp:
07/06/2020 04:12:24 PM (3 years ago)
Author:
azaozz
Message:

Heartbeat: Do not disable the login prompts when the user needs to log in again but has closed the log in modal. Add a 5 minutes timeout before asking them to log in again.

Props dsixinetu, adamsilverstein, azaozz.
Fixes #49573.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/auth-check.js

    r48285 r48337  
    66
    77/* global adminpage */
    8 (function($){
    9     var wrap;
     8( function( $ ) {
     9    var wrap,
     10        tempHidden,
     11        tempHiddenTimeout;
    1012
    1113    /**
     
    1618     */
    1719    function show() {
    18         var parent = $('#wp-auth-check'),
    19             form = $('#wp-auth-check-form'),
    20             noframe = wrap.find('.wp-auth-fallback-expired'),
     20        var parent = $( '#wp-auth-check' ),
     21            form = $( '#wp-auth-check-form' ),
     22            noframe = wrap.find( '.wp-auth-fallback-expired' ),
    2123            frame, loaded = false;
    2224
    2325        if ( form.length ) {
    2426            // Add unload confirmation to counter (frame-busting) JS redirects.
    25             $(window).on( 'beforeunload.wp-auth-check', function(e) {
    26                 e.originalEvent.returnValue = wp.i18n.__( 'Your session has expired. You can log in again from this page or go to the login page.' );
     27            $( window ).on( 'beforeunload.wp-auth-check', function( event ) {
     28                event.originalEvent.returnValue = window.wp.i18n.__( 'Your session has expired. You can log in again from this page or go to the login page.' );
    2729            });
    2830
    29             frame = $('<iframe id="wp-auth-check-frame" frameborder="0">').attr( 'title', noframe.text() );
     31            frame = $( '<iframe id="wp-auth-check-frame" frameborder="0">' ).attr( 'title', noframe.text() );
    3032            frame.on( 'load', function() {
    3133                var height, body;
     
    3638
    3739                try {
    38                     body = $(this).contents().find('body');
     40                    body = $( this ).contents().find( 'body' );
    3941                    height = body.height();
    40                 } catch(e) {
    41                     wrap.addClass('fallback');
     42                } catch( er ) {
     43                    wrap.addClass( 'fallback' );
    4244                    parent.css( 'max-height', '' );
    4345                    form.remove();
     
    4749
    4850                if ( height ) {
    49                     if ( body && body.hasClass('interim-login-success') )
     51                    if ( body && body.hasClass( 'interim-login-success' ) ) {
    5052                        hide();
    51                     else
     53                    } else {
    5254                        parent.css( 'max-height', height + 40 + 'px' );
     55                    }
    5356                } else if ( ! body || ! body.length ) {
    5457                    // Catch "silent" iframe origin exceptions in WebKit
    5558                    // after another page is loaded in the iframe.
    56                     wrap.addClass('fallback');
     59                    wrap.addClass( 'fallback' );
    5760                    parent.css( 'max-height', '' );
    5861                    form.remove();
    5962                    noframe.focus();
    6063                }
    61             }).attr( 'src', form.data('src') );
     64            }).attr( 'src', form.data( 'src' ) );
    6265
    6366            form.append( frame );
     
    6568
    6669        $( 'body' ).addClass( 'modal-open' );
    67         wrap.removeClass('hidden');
     70        wrap.removeClass( 'hidden' );
    6871
    6972        if ( frame ) {
     
    7679            setTimeout( function() {
    7780                if ( ! loaded ) {
    78                     wrap.addClass('fallback');
     81                    wrap.addClass( 'fallback' );
    7982                    form.remove();
    8083                    noframe.focus();
     
    9396     */
    9497    function hide() {
    95         $(window).off( 'beforeunload.wp-auth-check' );
     98        var adminpage = window.adminpage,
     99            wp        = window.wp;
     100
     101        $( window ).off( 'beforeunload.wp-auth-check' );
    96102
    97103        // When on the Edit Post screen, speed up heartbeat
    98104        // after the user logs in to quickly refresh nonces.
    99         if ( typeof adminpage !== 'undefined' && ( adminpage === 'post-php' || adminpage === 'post-new-php' ) &&
    100             typeof wp !== 'undefined' && wp.heartbeat ) {
    101 
    102             $(document).off( 'heartbeat-tick.wp-auth-check' );
     105        if ( ( adminpage === 'post-php' || adminpage === 'post-new-php' ) && wp && wp.heartbeat ) {
    103106            wp.heartbeat.connectNow();
    104107        }
    105108
    106109        wrap.fadeOut( 200, function() {
    107             wrap.addClass('hidden').css('display', '');
    108             $('#wp-auth-check-frame').remove();
     110            wrap.addClass( 'hidden' ).css( 'display', '' );
     111            $( '#wp-auth-check-frame' ).remove();
    109112            $( 'body' ).removeClass( 'modal-open' );
    110113        });
     114    }
     115
     116    /**
     117     * Set or reset the tempHidden variable used to pause showing of the modal
     118     * after a user closes it without logging in.
     119     *
     120     * @since 5.5.0
     121     * @private
     122     */
     123    function setShowTimeout() {
     124        tempHidden = true;
     125        window.clearTimeout( tempHiddenTimeout );
     126        tempHiddenTimeout = window.setTimeout(
     127            function() {
     128                tempHidden = false;
     129            },
     130            300000 // 5 min.
     131        );
    111132    }
    112133
     
    127148    $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
    128149        if ( 'wp-auth-check' in data ) {
    129             if ( ! data['wp-auth-check'] && wrap.hasClass('hidden') ) {
     150            if ( ! data['wp-auth-check'] && wrap.hasClass( 'hidden' ) && ! tempHidden ) {
    130151                show();
    131             } else if ( data['wp-auth-check'] && ! wrap.hasClass('hidden') ) {
     152            } else if ( data['wp-auth-check'] && ! wrap.hasClass( 'hidden' ) ) {
    132153                hide();
    133154            }
     
    142163         * @since 3.6.0
    143164         */
    144         wrap = $('#wp-auth-check-wrap');
    145         wrap.find('.wp-auth-check-close').on( 'click', function() {
     165        wrap = $( '#wp-auth-check-wrap' );
     166        wrap.find( '.wp-auth-check-close' ).on( 'click', function() {
    146167            hide();
     168            setShowTimeout();
    147169        });
    148170    });
Note: See TracChangeset for help on using the changeset viewer.