73152b928b6e9f46ecc737f71a039ad33d50e03a
[Packages/TYPO3.CMS.git] / typo3 / js / loginrefresh.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2009 Steffen Kamper <info@sk-typo3.de>
5 * All rights reserved
6 *
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.
12 *
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.
17 *
18 *
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.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * AJAX login refresh box
29 */
30 Ext.namespace('Ext.ux.TYPO3');
31
32 Ext.ux.TYPO3.loginRefresh = Ext.extend(Ext.util.Observable, {
33 locked: 0,
34 interval: 60,
35
36 constructor: function(config) {
37 config = config || {};
38 Ext.apply(this, config);
39 this.initComponents();
40 this.loadingTask = {
41 run: function(){
42 // interval run
43 Ext.Ajax.request({
44 url: "ajax.php",
45 params: {
46 "ajaxID": "BackendLogin::isTimedOut",
47 "skipSessionUpdate": 1
48 },
49 method: "GET",
50 success: function(response, options) {
51 var result = Ext.util.JSON.decode(response.responseText);
52 if(result.login.locked) {
53 this.locked = 1;
54 Ext.MessageBox.show({
55 title: TYPO3.LLL.core.please_wait,
56 msg: TYPO3.LLL.core.be_locked,
57 width: 500,
58 icon: Ext.MessageBox.INFO,
59 closable: false
60 });
61 } else {
62 if (this.locked === 1) {
63 this.locked = 0;
64 Ext.MessageBox.hide();
65 }
66 }
67 if (result.login.timed_out && Ext.getCmp("loginformWindow")) {
68 Ext.getCmp("login_username").value = TYPO3.configuration.username;
69 this.stopTimer();
70 this.progressWindow.show();
71 }
72 },
73 failure: function() {
74
75 },
76 scope: this
77 });
78 },
79 interval: this.interval * 1000,
80 scope: this
81 };
82 this.startTimer();
83 Ext.ux.TYPO3.loginRefresh.superclass.constructor.call(this, config);
84 },
85
86
87 initComponents: function() {
88 var loginPanel = new Ext.FormPanel({
89 url: "ajax.php",
90 id: "loginform",
91 title: TYPO3.LLL.core.refresh_login_title,
92 defaultType: 'textfield',
93 scope: this,
94 width: "100%",
95 bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
96
97 items: [{
98 xtype: "panel",
99 bodyStyle: "margin-bottom: 7px; border: none;",
100 html: TYPO3.LLL.core.login_expired
101 },{
102 fieldLabel: TYPO3.LLL.core.refresh_login_password,
103 name: "p_field",
104 width: 250,
105 id: "password",
106 inputType: "password"
107 },{
108 inputType: "hidden",
109 name: "username",
110 id: "login_username",
111 value: ""
112 },{
113 inputType: "hidden",
114 name: "userident",
115 id: "userident",
116 value: ""
117 }, {
118 inputType: "hidden",
119 name: "challenge",
120 id: "challenge",
121 value: TYPO3.configuration.challenge
122 }
123 ],
124 keys:({
125 key: Ext.EventObject.ENTER,
126 fn: this.submitForm,
127 scope: this
128 }),
129 buttons: [{
130 text: TYPO3.LLL.core.refresh_login_button,
131 formBind: true,
132 handler: this.submitForm
133 }, {
134 text: TYPO3.LLL.core.refresh_logout_button,
135 formBind: true,
136 handler: function() {
137 top.location.href = TYPO3.configuration.siteUrl + TYPO3.configuration.TYPO3_mainDir + "logout.php";
138 }
139 }]
140 });
141 this.loginRefreshWindow = new Ext.Window({
142 id: "loginformWindow",
143 width: 450,
144 autoHeight: true,
145 closable: true,
146 resizable: false,
147 plain: true,
148 border: false,
149 modal: true,
150 draggable: false,
151 items: [loginPanel]
152 });
153
154 var progressControl = new Ext.ProgressBar({
155 autoWidth: true,
156 autoHeight: true,
157 value: 30
158 });
159
160 this.progressWindow = new Ext.Window({
161 closable: false,
162 resizable: false,
163 draggable: false,
164 modal: true,
165 id: "loginRefreshWindow",
166 items: [{
167 xtype: "panel",
168 bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
169 bodyBorder: false,
170 autoHeight: true,
171 autoWidth: true,
172 html: TYPO3.LLL.core.login_about_to_expire
173 },
174 progressControl
175 ],
176 title: TYPO3.LLL.core.login_about_to_expire_title,
177 width: 450,
178
179 buttons: [{
180 text: TYPO3.LLL.core.refresh_login_refresh_button,
181 handler: function() {
182 refresh = Ext.Ajax.request({
183 url: "ajax.php",
184 params: {
185 "ajaxID": "BackendLogin::isTimedOut"
186 },
187 method: "GET",
188 scope: this
189 });
190 TYPO3.loginRefresh.progressWindow.hide();
191 progressControl.reset();
192 TYPO3.loginRefresh.startTimer();
193 }
194 }, {
195 text: TYPO3.LLL.core.refresh_direct_logout_button,
196 handler: function() {
197 top.location.href = TYPO3.configuration.siteUrl + TYPO3.configuration.TYPO3_mainDir + "logout.php";
198 }
199 }]
200 });
201 this.progressWindow.on('show', function(){
202 progressControl.wait({
203 interval: 1000,
204 duration: 30000,
205 increment: 32,
206 text: String.format(TYPO3.LLL.core.refresh_login_countdown, '30'),
207 fn: function(win){
208 if (TYPO3.configuration.showRefreshLoginPopup) {
209 //log off for sure
210 Ext.Ajax.request({
211 url: "ajax.php",
212 params: {
213 "ajaxID": "BackendLogin::logout"
214 },
215 method: "GET",
216 scope: this,
217 success: function(response, opts) {
218 TYPO3.loginRefresh.showLoginPopup();
219 },
220 failure: function(response, opts) {
221 alert("something went wrong");
222 }
223 });
224 } else {
225 Ext.getCmp("loginRefreshWindow").hide();
226 Ext.getCmp("loginformWindow").show();
227 }
228 }
229 });
230
231 });
232 progressControl.on('update', function(control, value, text) {
233 var rest = 30-(parseInt(value*30));
234 if (rest === 1) {
235 control.updateText(String.format(TYPO3.LLL.core.refresh_login_countdown_singular, rest));
236 } else {
237 control.updateText(String.format(TYPO3.LLL.core.refresh_login_countdown, rest));
238 }
239 });
240
241 this.loginRefreshWindow.on('close', function(){
242 TYPO3.loginRefresh.startTimer();
243 });
244 },
245
246 showLoginPopup: function() {
247 Ext.getCmp("loginRefreshWindow").hide();
248 vHWin=window.open("login_frameset.php","relogin_"+TS.uniqueID,"height=450,width=700,status=0,menubar=0,location=1");
249 vHWin.focus();
250 },
251
252 startTimer: function() {
253 Ext.TaskMgr.start(this.loadingTask);
254 },
255
256 stopTimer: function() {
257 Ext.TaskMgr.stop(this.loadingTask);
258 },
259
260 submitForm: function() {
261 var form = Ext.getCmp("loginform").getForm();
262 var fields = form.getValues();
263 if (fields.p_field === "") {
264 Ext.Msg.alert(TYPO3.LLL.core.refresh_login_failed, TYPO3.LLL.core.refresh_login_emptyPassword);
265 } else {
266 if (TS.securityLevel == "superchallenged") {
267 fields.p_field = MD5(fields.p_field);
268 }
269 if (TS.securityLevel == "superchallenged" || TS.securityLevel == "challenged") {
270 fields.userident = MD5(fields.username + ":" + fields.p_field + ":" + fields.challenge);
271 } else {
272 fields.userident = fields.p_field;
273 }
274 fields.p_field = "";
275 form.setValues(fields);
276
277 form.submit({
278 method: "POST",
279 waitTitle: TYPO3.LLL.core.waitTitle,
280 waitMsg: " ",
281 params: {
282 "ajaxID": "BackendLogin::login",
283 "login_status": "login"
284 },
285 success: function(form, action) {
286 // response object is "login" so real result will be available in failure handler
287 Ext.getCmp("loginformWindow").hide();
288 TYPO3.loginRefresh.startTimer();
289 },
290 failure: function(form, action) {
291 var result = Ext.util.JSON.decode(action.response.responseText).login;
292 if (result.success) {
293 // User is logged in
294 Ext.getCmp("loginformWindow").hide();
295 TYPO3.loginRefresh.startTimer();
296 } else {
297 // TODO: add failure to notification system instead of alert
298 Ext.Msg.alert(TYPO3.LLL.core.refresh_login_failed, TYPO3.LLL.core.refresh_login_failed_message);
299 }
300 }
301 });
302 }
303 }
304
305 });
306
307
308
309 /**
310 * Initialize login expiration warning object
311 */
312 Ext.onReady(function() {
313 TYPO3.loginRefresh = new Ext.ux.TYPO3.loginRefresh();
314 });