1 /***************************************************************
4 * (c) 2009 Steffen Kamper <info@sk-typo3.de>
7 * This script is part of the TYPO3 project. The TYPO3 project is
8 * free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * The GNU General Public License can be found at
14 * http://www.gnu.org/copyleft/gpl.html.
15 * A copy is found in the textfile GPL.txt and important notices to the license
16 * from the author is found in LICENSE.txt distributed with these scripts.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
28 * AJAX login refresh box
32 * Functions for session-expiry detection:
35 this.loginRefreshed
= busy_loginRefreshed
;
36 this.openRefreshWindow
= busy_OpenRefreshWindow
;
37 this.openLockedWaitWindow
= busy_openLockedWaitWindow
;
40 this.reloginCancelled
=0;
44 // starts the timer and resets the earlyRelogin variable so that
45 // the countdown works properly.
46 this.startTimer = function() {
47 this.earlyRelogin
= 0;
51 this.stopTimer = function() {
55 // simple timer that polls the server to determine imminent timeout.
56 this.timer
= new Ajax
.PeriodicalUpdater("","ajax.php", {
60 parameters
: "ajaxID=BackendLogin::isTimedOut&skipSessionUpdate=1",
61 onSuccess: function(e
) {
62 var login
= e
.responseJSON
.login
.evalJSON();
65 busy
.openLockedWaitWindow();
66 } else if(login
.timed_out
) {
67 busy
.openRefreshWindow();
69 if (busy
.locked
&& !login
.locked
&& !login
.timed_out
) {
71 Ext
.MessageBox
.hide();
76 // this function runs the countdown and opens the login window
77 // as soon as the countdown expires.
78 this.countDown = function(progressControl
, progressTextFormatPlural
, progressTextFormatSingular
, secondsRemaining
, totalSeconds
) {
80 if(busy
.earlyRelogin
== 0) {
81 if(secondsRemaining
> 1) {
82 progressControl
.updateText(String
.format(progressTextFormatPlural
, secondsRemaining
));
83 progressControl
.updateProgress(secondsRemaining
/(1.0*totalSeconds
));
84 setTimeout(function () {
85 busy
.countDown(progressControl
, progressTextFormatPlural
, progressTextFormatSingular
,secondsRemaining
- 1, totalSeconds
);
87 } else if(secondsRemaining
> 0) {
88 progressControl
.updateText(String
.format(progressTextFormatSingular
, secondsRemaining
));
89 progressControl
.updateProgress(secondsRemaining
/(1.0*totalSeconds
));
90 setTimeout(function () {
91 busy
.countDown(progressControl
, progressTextFormatPlural
, progressTextFormatSingular
,secondsRemaining
- 1, totalSeconds
);
94 busy
.openRefreshW
= 1;
100 // Closes the countdown window and opens a new one with a login form.
101 this.openLogin = function() {
103 doChallengeResponse = function(superchallenged
) {
104 password
= $$("#loginform form")[0].p_field
.value
;
107 if (superchallenged
) {
108 password
= MD5(password
); // this makes it superchallenged!!
110 str
= $("login_username").value
+":"+password
+":"+$("challenge").value
;
111 $("userident").value
= MD5(str
);
112 $("password").value
= "";
118 submitForm = function() {
119 if(TS
.securityLevel
== "superchallenged") {
120 doChallengeResponse(1);
121 } else if (TS
.securityLevel
== "challenged") {
122 doChallengeResponse(0);
124 $("userident").value
= $$("#loginform form")[0].p_field
.value
;
125 $("password").value
= "";
128 login
.getForm().submit({
130 waitTitle
: TYPO3
.LLL
.core
.waitTitle
,
132 params
: "ajaxID=BackendLogin::login&login_status=login",
133 success: function() {
135 setTimeout("busy.startTimer()", 2000);
139 failure: function() {
140 // TODO: add failure to notification system instead of alert
141 // Ext.tip.msg("Login failed", "Username or Password incorrect!");
142 Ext
.Msg
.alert(TYPO3
.LLL
.core
.refresh_login_failed
, TYPO3
.LLL
.core
.refresh_login_failed_message
);
147 logout
= new Ajax
.Request("ajax.php", {
149 parameters
: "ajaxID=BackendLogin::logout"
152 Ext
.onReady(function(){
153 login
= new Ext
.FormPanel({
156 title
: TYPO3
.LLL
.core
.refresh_login_title
,
157 defaultType
: "textfield",
159 bodyStyle
: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
163 bodyStyle
: "margin-bottom: 7px; border: none;",
164 html
: TYPO3
.LLL
.core
.login_expired
166 fieldLabel
: TYPO3
.LLL
.core
.refresh_login_username
,
168 id
: "login_username",
172 fieldLabel
: TYPO3
.LLL
.core
.refresh_login_password
,
176 inputType
: "password"
186 value
: TYPO3
.configuration
.challenge
190 key
: Ext
.EventObject
.ENTER
,
195 text
: TYPO3
.LLL
.core
.refresh_login_button
,
199 text
: TYPO3
.LLL
.core
.refresh_logout_button
,
201 handler: function() {
202 top
.location
.href
= TYPO3
.configuration
.siteUrl
+ TYPO3
.configuration
.TYPO3_mainDir
;
207 win
= new Ext
.Window({
223 function busy_loginRefreshed() { //
228 function busy_openLockedWaitWindow() {
229 Ext
.MessageBox
.show({
230 title
: TYPO3
.LLL
.core
.please_wait
,
231 msg
: TYPO3
.LLL
.core
.be_locked
,
233 icon
: Ext
.MessageBox
.INFO
,
238 function busy_OpenRefreshWindow() {
239 this.openRefreshW
= 1;
244 var progressTextFormatSingular
= TYPO3
.LLL
.core
.refresh_login_countdown_singular
;
245 var progressTextFormatPlural
= TYPO3
.LLL
.core
.refresh_login_countdown
;
246 var progressText
= String
.format(progressTextFormatPlural
, seconds
);
247 var progressControl
= new Ext
.ProgressBar({
254 win
= new Ext
.Window({
261 bodyStyle
: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
265 html
: TYPO3
.LLL
.core
.login_about_to_expire
269 title
: TYPO3
.LLL
.core
.login_about_to_expire_title
,
273 text
: TYPO3
.LLL
.core
.refresh_login_refresh_button
,
274 handler: function() {
275 refresh
= new Ajax
.Request("ajax.php", {
277 parameters
: "ajaxID=BackendLogin::refreshLogin"
280 busy
.earlyRelogin
= 1;
281 setTimeout("busy.startTimer()", 2000);
284 text
: TYPO3
.LLL
.core
.refresh_direct_logout_button
,
285 handler: function() {
286 top
.location
.href
= TYPO3
.configuration
.siteUrl
+ TYPO3
.configuration
.TYPO3_mainDir
+ "logout.php";
291 busy
.countDown(progressControl
, progressTextFormatPlural
, progressTextFormatSingular
, seconds
, seconds
);
295 * Initialize login expiration warning object
297 var busy
= new busy();
298 busy
.loginRefreshed();