Project

General

Profile

Bug #20038 » 10467_loginrefresh_refactored.diff

Administrator Admin, 2009-10-04 17:29

View differences:

typo3/backend.php (working copy)
$pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
$pageRenderer->loadScriptaculous('builder,effects,controls,dragdrop');
$pageRenderer->loadExtJS();
// remove duplicate entries
$this->jsFiles = array_unique($this->jsFiles);
......
'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') ,
'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'),
'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'),
'refresh_login_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'),
'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])),
'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'),
'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'),
'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'),
'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'),
'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'),
'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'),
'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'),
typo3/classes/class.ajaxlogin.php (working copy)
*/
public function login($params = array(), TYPO3AJAX &$ajaxObj = null) {
if ($GLOBALS['BE_USER']->user['uid']) {
$json = '{success: true}';
$json = array('success' => true);
} else {
$json = '{success: false}';
$json = array('success' => false);
}
$ajaxObj->addContent('login', $json);
$ajaxObj->setContentFormat('json');
}
/**
......
public function logout($params = array(), TYPO3AJAX &$ajaxObj = null) {
$GLOBALS['BE_USER']->logoff();
if($GLOBALS['BE_USER']->user['uid']) {
$ajaxObj->addContent('logout', '{sucess: false}');
$ajaxObj->addContent('logout', array('success' => false));
} else {
$ajaxObj->addContent('logout', '{sucess: true}');
$ajaxObj->addContent('logout', array('success' => true));
}
$ajaxObj->setContentFormat('json');
}
/**
......
*/
public function refreshLogin($params = array(), TYPO3AJAX &$ajaxObj = null) {
$GLOBALS['BE_USER']->checkAuthentication();
$ajaxObj->addContent('refresh', '{sucess: true}');
$ajaxObj->addContent('refresh', array('success' => true));
$ajaxObj->setContentFormat('json');
}
......
*/
function isTimedOut($params = array(), TYPO3AJAX &$ajaxObj = null) {
if(is_object($GLOBALS['BE_USER'])) {
$ajaxObj->setContentFormat('json');
if (@is_file(PATH_typo3conf.'LOCK_BACKEND')) {
$ajaxObj->addContent('login', '{timed_out: false,locked:true}');
$ajaxObj->addContent('login', array('timed_out' => false, 'locked' => true));
$ajaxObj->setContentFormat('json');
} else {
$GLOBALS['BE_USER']->fetchUserSession(true);
......
// if 120 seconds from now is later than the session timeout, we need to show the refresh dialog.
// 120 is somewhat arbitrary to allow for a little room during the countdown and load times, etc.
if($GLOBALS['EXEC_TIME'] >= $ses_tstamp+$timeout-120) {
$ajaxObj->addContent('login', '{timed_out: true}');
$ajaxObj->setContentFormat('json');
$ajaxObj->addContent('login', array('timed_out' => true));
} else {
$ajaxObj->addContent('login', '{timed_out: false}');
$ajaxObj->setContentFormat('json');
$ajaxObj->addContent('login', array('timed_out' => false));
}
}
} else {
$ajaxObj->addContent('login', '{success: false, error: "No BE_USER object"}');
$ajaxObj->addContent('login', array('success' => false, 'error' => 'No BE_USER object'));
}
}
}
typo3/js/loginrefresh.js (working copy)
/**
* AJAX login refresh box
*/
Ext.namespace('Ext.ux.TYPO3');
/**
* Functions for session-expiry detection:
*/
function busy() { //
this.loginRefreshed = busy_loginRefreshed;
this.openRefreshWindow = busy_OpenRefreshWindow;
this.openLockedWaitWindow = busy_openLockedWaitWindow;
this.busyloadTime=0;
this.openRefreshW=0;
this.reloginCancelled=0;
this.earlyRelogin=0;
this.locked=0;
Ext.ux.TYPO3.loginRefresh = Ext.extend(Ext.util.Observable, {
locked: 0,
interval: 60,
constructor: function(config) {
config = config || {};
Ext.apply(this, config);
this.initComponents();
this.loadingTask = {
run: function(){
// interval run
Ext.Ajax.request({
url: "ajax.php",
params: {
"ajaxID": "BackendLogin::isTimedOut",
"skipSessionUpdate": 1
},
method: "GET",
success: function(response, options) {
var result = Ext.util.JSON.decode(response.responseText);
if(result.login.locked) {
this.locked = 1;
Ext.MessageBox.show({
title: TYPO3.LLL.core.please_wait,
msg: TYPO3.LLL.core.be_locked,
width: 500,
icon: Ext.MessageBox.INFO,
closable: false
});
} else {
if (this.locked === 1) {
this.locked = 0;
Ext.MessageBox.hide();
}
}
if (result.login.timed_out) {
Ext.getCmp("login_username").value = TYPO3.configuration.username;
this.stopTimer();
this.progressWindow.show();
}
},
failure: function() {
// starts the timer and resets the earlyRelogin variable so that
// the countdown works properly.
this.startTimer = function() {
this.earlyRelogin = 0;
this.timer.start();
}
},
scope: this
});
},
interval: this.interval * 1000,
scope: this
};
this.startTimer();
Ext.ux.TYPO3.loginRefresh.superclass.constructor.call(this, config);
},
initComponents: function() {
var loginPanel = new Ext.FormPanel({
url: "ajax.php",
id: "loginform",
title: TYPO3.LLL.core.refresh_login_title,
defaultType: 'textfield',
scope: this,
width: "100%",
bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
this.stopTimer = function() {
this.timer.stop();
}
items: [{
xtype: "panel",
bodyStyle: "margin-bottom: 7px; border: none;",
html: TYPO3.LLL.core.login_expired
},{
fieldLabel: TYPO3.LLL.core.refresh_login_password,
name: "p_field",
width: 250,
id: "password",
inputType: "password"
},{
inputType: "hidden",
name: "username",
id: "login_username",
value: ""
},{
inputType: "hidden",
name: "userident",
id: "userident",
value: ""
}, {
inputType: "hidden",
name: "challenge",
id: "challenge",
value: TYPO3.configuration.challenge
}
],
keys:({
key: Ext.EventObject.ENTER,
fn: this.submitForm,
scope: this
}),
buttons: [{
text: TYPO3.LLL.core.refresh_login_button,
formBind: true,
handler: this.submitForm
}, {
text: TYPO3.LLL.core.refresh_logout_button,
formBind: true,
handler: function() {
top.location.href = TYPO3.configuration.siteUrl + TYPO3.configuration.TYPO3_mainDir;
}
}]
});
this.loginRefreshWindow = new Ext.Window({
id: "loginformWindow",
width: 450,
autoHeight: true,
closable: false,
resizable: false,
plain: true,
border: false,
modal: true,
draggable: false,
items: [loginPanel]
});
var progressControl = new Ext.ProgressBar({
autoWidth: true,
autoHeight: true,
value: 30,
});
this.progressWindow = new Ext.Window({
closable: false,
resizable: false,
draggable: false,
modal: true,
id: "loginRefreshWindow",
items: [{
xtype: "panel",
bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
bodyBorder: false,
autoHeight: true,
autoWidth: true,
html: TYPO3.LLL.core.login_about_to_expire
},
progressControl
],
title: TYPO3.LLL.core.login_about_to_expire_title,
width: 450,
// simple timer that polls the server to determine imminent timeout.
this.timer = new Ajax.PeriodicalUpdater("","ajax.php", {
method: "get",
frequency: 60,
decay: 1,
parameters: "ajaxID=BackendLogin::isTimedOut&skipSessionUpdate=1",
onSuccess: function(e) {
var login = e.responseJSON.login.evalJSON();
if(login.locked) {
busy.locked = 1;
busy.openLockedWaitWindow();
} else if(login.timed_out) {
busy.openRefreshWindow();
}
if (busy.locked && !login.locked && !login.timed_out) {
busy.locked = 0;
Ext.MessageBox.hide();
}
}
});
buttons: [{
text: TYPO3.LLL.core.refresh_login_refresh_button,
handler: function() {
refresh = Ext.Ajax.request({
url: "ajax.php",
params: {
"ajaxID": "BackendLogin::isTimedOut"
},
method: "GET",
scope: this
});
this.hide();
}
}, {
text: TYPO3.LLL.core.refresh_direct_logout_button,
handler: function() {
top.location.href = TYPO3.configuration.siteUrl + TYPO3.configuration.TYPO3_mainDir + "logout.php";
}
}]
});
this.progressWindow.on('show', function(){
progressControl.wait({
interval: 1000,
duration: 30000,
increment: 32,
text: String.format(TYPO3.LLL.core.refresh_login_countdown, '30'),
fn: function(win){
Ext.getCmp("loginRefreshWindow").hide();
Ext.getCmp("loginformWindow").show();
}
});
// this function runs the countdown and opens the login window
// as soon as the countdown expires.
this.countDown = function(progressControl, progressTextFormatPlural, progressTextFormatSingular, secondsRemaining, totalSeconds) {
if(busy.earlyRelogin == 0) {
if(secondsRemaining > 1) {
progressControl.updateText(String.format(progressTextFormatPlural, secondsRemaining));
progressControl.updateProgress(secondsRemaining/(1.0*totalSeconds));
setTimeout(function () {
busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular,secondsRemaining - 1, totalSeconds);
}, 1000);
} else if(secondsRemaining > 0) {
progressControl.updateText(String.format(progressTextFormatSingular, secondsRemaining));
progressControl.updateProgress(secondsRemaining/(1.0*totalSeconds));
setTimeout(function () {
busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular,secondsRemaining - 1, totalSeconds);
}, 1000);
});
progressControl.on('update', function(control, value, text) {
var rest = 30-(parseInt(value*30));
if (rest === 1) {
control.updateText(String.format(TYPO3.LLL.core.refresh_login_countdown_singular, rest));
} else {
busy.openRefreshW = 1;
busy.openLogin();
control.updateText(String.format(TYPO3.LLL.core.refresh_login_countdown, rest));
}
}
};
// Closes the countdown window and opens a new one with a login form.
this.openLogin = function() {
var login;
doChallengeResponse = function(superchallenged) {
password = $$("#loginform form")[0].p_field.value;
if (password) {
if (superchallenged) {
password = MD5(password); // this makes it superchallenged!!
}
str = $("login_username").value+":"+password+":"+$("challenge").value;
$("userident").value = MD5(str);
$("password").value = "";
return true;
}
}
submitForm = function() {
if(TS.securityLevel == "superchallenged") {
doChallengeResponse(1);
} else if (TS.securityLevel == "challenged") {
doChallengeResponse(0);
});
},
startTimer: function() {
Ext.TaskMgr.start(this.loadingTask);
},
stopTimer: function() {
Ext.TaskMgr.stop(this.loadingTask);
},
submitForm: function() {
var form = Ext.getCmp("loginform").getForm();
var fields = form.getValues();
if (fields.p_field === "") {
Ext.Msg.alert(TYPO3.LLL.core.refresh_login_failed, TYPO3.LLL.core.refresh_login_emptyPassword);
} else {
if (TS.securityLevel == "superchallenged") {
fields.p_field = MD5(fields.p_field);
}
if (TS.securityLevel == "superchallenged" || TS.securityLevel == "challenged") {
fields.userident = MD5(fields.username + ":" + fields.p_field + ":" + fields.challenge);
} else {
$("userident").value = $$("#loginform form")[0].p_field.value;
$("password").value= "";
fields.userident = fields.p_field;
}
fields.p_field = "";
form.setValues(fields);
login.getForm().submit({
method: "post",
form.submit({
method: "POST",
waitTitle: TYPO3.LLL.core.waitTitle,
waitMsg: " ",
params: "ajaxID=BackendLogin::login&login_status=login",
success: function() {
win.close();
setTimeout("busy.startTimer()", 2000);
params: {
"ajaxID": "BackendLogin::login",
"login_status": "login"
},
failure: function() {
// TODO: add failure to notification system instead of alert
// Ext.tip.msg("Login failed", "Username or Password incorrect!");
Ext.Msg.alert(TYPO3.LLL.core.refresh_login_failed, TYPO3.LLL.core.refresh_login_failed_message);
success: function(form, action) {
// response object is "login" so real result will be available in failure handler
Ext.getCmp("loginformWindow").hide();
TYPO3.loginRefresh.startTimer();
},
failure: function(form, action) {
var result = Ext.util.JSON.decode(action.response.responseText).login;
if (result.success) {
// User is logged in
Ext.getCmp("loginformWindow").hide();
TYPO3.loginRefresh.startTimer();
} else {
// TODO: add failure to notification system instead of alert
Ext.Msg.alert(TYPO3.LLL.core.refresh_login_failed, TYPO3.LLL.core.refresh_login_failed_message);
}
}
});
}
logout = new Ajax.Request("ajax.php", {
method: "get",
parameters: "ajaxID=BackendLogin::logout"
});
Ext.onReady(function(){
login = new Ext.FormPanel({
url: "ajax.php",
id: "loginform",
title: TYPO3.LLL.core.refresh_login_title,
defaultType: "textfield",
width: "100%",
bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
items: [{
xtype: "panel",
bodyStyle: "margin-bottom: 7px; border: none;",
html: TYPO3.LLL.core.login_expired
},{
fieldLabel: TYPO3.LLL.core.refresh_login_username,
name: "username",
id: "login_username",
allowBlank: false,
width: 250
},{
fieldLabel: TYPO3.LLL.core.refresh_login_password,
name: "p_field",
width: 250,
id: "password",
inputType: "password"
},{
xtype: "hidden",
name: "userident",
id: "userident",
value: ""
}, {
xtype: "hidden",
name: "challenge",
id: "challenge",
value: TYPO3.configuration.challenge
}
],
keys:({
key: Ext.EventObject.ENTER,
fn: submitForm,
scope: this
}),
buttons: [{
text: TYPO3.LLL.core.refresh_login_button,
formBind: true,
handler: submitForm
}, {
text: TYPO3.LLL.core.refresh_logout_button,
formBind: true,
handler: function() {
top.location.href = TYPO3.configuration.siteUrl + TYPO3.configuration.TYPO3_mainDir;
}
}]
});
win.close();
win = new Ext.Window({
width: 450,
autoHeight: true,
closable: false,
resizable: false,
plain: true,
border: false,
modal: true,
draggable: false,
items: [login]
});
win.show();
});
}
}
});
function busy_loginRefreshed() { //
this.openRefreshW=0;
this.earlyRelogin=0;
}
function busy_openLockedWaitWindow() {
Ext.MessageBox.show({
title: TYPO3.LLL.core.please_wait,
msg: TYPO3.LLL.core.be_locked,
width: 500,
icon: Ext.MessageBox.INFO,
closable: false
});
}
function busy_OpenRefreshWindow() {
this.openRefreshW = 1;
busy.stopTimer();
var seconds = 30;
var progressTextFormatSingular = TYPO3.LLL.core.refresh_login_countdown_singular;
var progressTextFormatPlural = TYPO3.LLL.core.refresh_login_countdown;
var progressText = String.format(progressTextFormatPlural, seconds);
var progressControl = new Ext.ProgressBar({
autoWidth: true,
autoHeight: true,
value: 1,
text: progressText
});
win = new Ext.Window({
closable: false,
resizable: false,
draggable: false,
modal: true,
items: [{
xtype: "panel",
bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
bodyBorder: false,
autoHeight: true,
autoWidth: true,
html: TYPO3.LLL.core.login_about_to_expire
},
progressControl
],
title: TYPO3.LLL.core.login_about_to_expire_title,
width: 450,
buttons: [{
text: TYPO3.LLL.core.refresh_login_refresh_button,
handler: function() {
refresh = new Ajax.Request("ajax.php", {
method: "get",
parameters: "ajaxID=BackendLogin::refreshLogin"
});
win.close();
busy.earlyRelogin = 1;
setTimeout("busy.startTimer()", 2000);
}
}, {
text: TYPO3.LLL.core.refresh_direct_logout_button,
handler: function() {
top.location.href = TYPO3.configuration.siteUrl + TYPO3.configuration.TYPO3_mainDir + "logout.php";
}
}]
});
win.show();
busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular, seconds, seconds);
}
/**
* Initialize login expiration warning object
*/
var busy = new busy();
busy.loginRefreshed();
Ext.onReady(function() {
TYPO3.loginRefresh = new Ext.ux.TYPO3.loginRefresh();
});
typo3/sysext/lang/locallang_core.xml (working copy)
<label index="mess.refresh_login_countdown_singular">{0} second</label>
<label index="mess.refresh_login_logging_in">Logging in...</label>
<label index="mess.refresh_login_failed">Login failed</label>
<label index="mess.refresh_login_failed_message">Username or password not correct.</label>
<label index="mess.refresh_login_title">Login to TYPO3</label>
<label index="mess.refresh_login_failed_message">Password not correct.</label>
<label index="mess.refresh_login_title">Refresh Login to TYPO3 (User: %s)</label>
<label index="mess.refresh_login_username">Username</label>
<label index="mess.refresh_login_password">Password</label>
<label index="mess.refresh_login_button">Login</label>
<label index="mess.refresh_login_emptyPassword">Empty password is not allowed!</label>
<label index="mess.please_wait">Please wait ...</label>
<label index="mess.be_locked">The TYPO3 backend is currently locked for maintenance. Leave this browser window open and the backend will automatically become available again once maintenance is complete.</label>
<label index="mess.login_about_to_expire">Your TYPO3 login is about to expire. Please confirm that you want to stay logged in.</label>
(1-1/2)