/* * This file is part of the TYPO3 CMS project. * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 * of the License, or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. * * The TYPO3 project - inspiring people to share! */ import $ from 'jquery'; import {AjaxResponse} from 'TYPO3/CMS/Core/Ajax/AjaxResponse'; import AjaxRequest = require('TYPO3/CMS/Core/Ajax/AjaxRequest'); import Notification = require('TYPO3/CMS/Backend/Notification'); enum MarkupIdentifiers { loginrefresh = 't3js-modal-loginrefresh', lockedModal = 't3js-modal-backendlocked', loginFormModal = 't3js-modal-backendloginform', } /** * Module: TYPO3/CMS/Backend/LoginRefresh * @exports TYPO3/CMS/Backend/LoginRefresh */ class LoginRefresh { private options: any = { modalConfig: { backdrop: 'static', }, }; private intervalTime: number = 60; private intervalId: number = null; private backendIsLocked: boolean = false; private isTimingOut: boolean = false; private $timeoutModal: JQuery = null; private $backendLockedModal: JQuery = null; private $loginForm: JQuery = null; private loginFramesetUrl: string = ''; private logoutUrl: string = ''; /** * Initialize login refresh */ public initialize(): void { this.initializeTimeoutModal(); this.initializeBackendLockedModal(); this.initializeLoginForm(); this.startTask(); } /** * Start the task */ public startTask(): void { if (this.intervalId !== null) { return; } // set interval to 60 seconds let interval: number = this.intervalTime * 1000; this.intervalId = setInterval(this.checkActiveSession, interval); } /** * Stop the task */ public stopTask(): void { clearInterval(this.intervalId); this.intervalId = null; } /** * Set interval time * * @param {number} intervalTime */ public setIntervalTime(intervalTime: number): void { // To avoid the integer overflow in setInterval, we limit the interval time to be one request per day this.intervalTime = Math.min(intervalTime, 86400); } /** * Set the logout URL * * @param {string} logoutUrl */ public setLogoutUrl(logoutUrl: string): void { this.logoutUrl = logoutUrl; } /** * Set login frameset url */ public setLoginFramesetUrl(loginFramesetUrl: string): void { this.loginFramesetUrl = loginFramesetUrl; } /** * Shows the timeout dialog. If the backend is not focused, a Web Notification * is displayed, too. */ public showTimeoutModal(): void { this.isTimingOut = true; this.$timeoutModal.modal(this.options.modalConfig); this.$timeoutModal.modal('show'); this.fillProgressbar(this.$timeoutModal); } /** * Hides the timeout dialog. If a Web Notification is displayed, close it too. */ public hideTimeoutModal(): void { this.isTimingOut = false; this.$timeoutModal.modal('hide'); } /** * Shows the "backend locked" dialog. */ public showBackendLockedModal(): void { this.$backendLockedModal.modal(this.options.modalConfig); this.$backendLockedModal.modal('show'); } /** * Hides the "backend locked" dialog. */ public hideBackendLockedModal(): void { this.$backendLockedModal.modal('hide'); } /** * Shows the login form. */ public showLoginForm(): void { // log off for sure new AjaxRequest(TYPO3.settings.ajaxUrls.logout).get().then((): void => { if (TYPO3.configuration.showRefreshLoginPopup) { this.showLoginPopup(); } else { this.$loginForm.modal(this.options.modalConfig); this.$loginForm.modal('show'); } }); } /** * Opens the login form in a new window. */ public showLoginPopup(): void { const vHWin = window.open( this.loginFramesetUrl, 'relogin_' + Math.random().toString(16).slice(2), 'height=450,width=700,status=0,menubar=0,location=1', ); if (vHWin) { vHWin.focus(); } } /** * Hides the login form. */ public hideLoginForm(): void { this.$loginForm.modal('hide'); } /** * Generates the modal displayed if the backend is locked. */ protected initializeBackendLockedModal(): void { this.$backendLockedModal = this.generateModal(MarkupIdentifiers.lockedModal); this.$backendLockedModal.find('.modal-header h4').text(TYPO3.lang['mess.please_wait']); this.$backendLockedModal.find('.modal-body').append( $('

').text(TYPO3.lang['mess.be_locked']), ); this.$backendLockedModal.find('.modal-footer').remove(); $('body').append(this.$backendLockedModal); } /** * Generates the modal displayed on near session time outs */ protected initializeTimeoutModal(): void { this.$timeoutModal = this.generateModal(MarkupIdentifiers.loginrefresh); this.$timeoutModal.addClass('modal-severity-notice'); this.$timeoutModal.find('.modal-header h4').text(TYPO3.lang['mess.login_about_to_expire_title']); this.$timeoutModal.find('.modal-body').append( $('

').text(TYPO3.lang['mess.login_about_to_expire']), $('

', {class: 'progress'}).append( $('
', { class: 'progress-bar progress-bar-warning progress-bar-striped active', role: 'progressbar', 'aria-valuemin': '0', 'aria-valuemax': '100', }).append( $('', {class: 'sr-only'}), ), ), ); this.$timeoutModal.find('.modal-footer').append( $('