[TASK] Limit request to get logout information 85/49685/2
authorNicole Cordes <typo3@cordes.co>
Mon, 29 Aug 2016 10:22:31 +0000 (12:22 +0200)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Wed, 31 Aug 2016 15:38:46 +0000 (17:38 +0200)
Currently a request to get information about the login state is
triggered every minute. To prevent traffic the request can be triggered
only when the session is about to expire. This patch adds a function
to be able to pass the interval time to the LoginRefresh refresh and
sets it properly after initialization.

Resolves: #76364
Releases: master, 7.6
Change-Id: I9bfeb578973f1a5bc3a0f662ac1f6dcce82e7d37
Reviewed-on: https://review.typo3.org/49685
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
typo3/sysext/backend/Classes/Controller/BackendController.php
typo3/sysext/backend/Resources/Public/JavaScript/LoginRefresh.js

index 043ca72..532a0f8 100644 (file)
@@ -136,8 +136,10 @@ class BackendController
             'viewportConfiguration' => $backendRelPath . 'Resources/Public/JavaScript/extjs/viewportConfiguration.js',
         ];
         $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LoginRefresh', 'function(LoginRefresh) {
+                       LoginRefresh.setIntervalTime(' . MathUtility::forceIntegerInRange((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'] - 60, 60) . ');
                        LoginRefresh.setLoginFramesetUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('login_frameset')) . ');
                        LoginRefresh.setLogoutUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('logout')) . ');
+                       LoginRefresh.initialize();
                }');
 
         // load Utility class
index 2bcd2cd..c9097b6 100644 (file)
  * displays a proper dialog to the user.
  */
 define(['jquery', 'TYPO3/CMS/Backend/Notification', 'TYPO3/CMS/Rsaauth/RsaEncryptionModule', 'bootstrap'], function($, Typo3Notification, RsaEncryption) {
+       'use strict';
+
        /**
         *
-        * @type {{identifier: {loginrefresh: string, lockedModal: string, loginFormModal: string}, options: {modalConfig: {backdrop: string}}, webNotification: null, intervalId: null, backendIsLocked: boolean, isTimingOut: boolean, $timeoutModal: string, $backendLockedModal: string, $loginForm: string, loginFramesetUrl: string, logoutUrl: string}}
+        * @type {{identifier: {loginrefresh: string, lockedModal: string, loginFormModal: string}, options: {modalConfig: {backdrop: string}}, webNotification: null, intervalTime: integer, intervalId: null, backendIsLocked: boolean, isTimingOut: boolean, $timeoutModal: string, $backendLockedModal: string, $loginForm: string, loginFramesetUrl: string, logoutUrl: string}}
         * @exports TYPO3/CMS/Backend/LoginRefresh
         */
        var LoginRefresh = {
@@ -34,6 +36,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Notification', 'TYPO3/CMS/Rsaauth/RsaEncryp
                        }
                },
                webNotification: null,
+               intervalTime: 60,
                intervalId: null,
                backendIsLocked: false,
                isTimingOut: false,
@@ -53,7 +56,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Notification', 'TYPO3/CMS/Rsaauth/RsaEncryp
                }
 
                // set interval to 60 seconds
-               var interval = 1000 * 60;
+               var interval = 1000 * LoginRefresh.intervalTime;
                LoginRefresh.intervalId = setInterval(LoginRefresh.checkActiveSession, interval);
        };
 
@@ -86,6 +89,15 @@ define(['jquery', 'TYPO3/CMS/Backend/Notification', 'TYPO3/CMS/Rsaauth/RsaEncryp
        };
 
        /**
+        * Set interval time
+        *
+        * @param {integer} intervalTime
+        */
+       LoginRefresh.setIntervalTime = function(intervalTime) {
+               LoginRefresh.intervalTime = intervalTime;
+       };
+
+       /**
         * Set logout url
         *
         * @param {String} logoutUrl
@@ -452,8 +464,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Notification', 'TYPO3/CMS/Rsaauth/RsaEncryp
                });
        };
 
-       // initialize and return the LoginRefresh object
-       $(function() {
+       LoginRefresh.initialize = function() {
                LoginRefresh.initializeTimeoutModal();
                LoginRefresh.initializeBackendLockedModal();
                LoginRefresh.initializeLoginForm();
@@ -463,7 +474,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Notification', 'TYPO3/CMS/Rsaauth/RsaEncryp
                if (typeof Notification !== 'undefined' && Notification.permission !== 'granted') {
                        Notification.requestPermission();
                }
-       });
+       };
 
        // expose to global
        TYPO3.LoginRefresh = LoginRefresh;