- Fixed a bug where click at "logout" shows error notification instead of redirecting the user to /login page, closed #894

This commit is contained in:
Mark Friedrich
2020-03-06 19:47:32 +01:00
parent c9b2215a19
commit 8f5acb2656
15 changed files with 88 additions and 60 deletions

View File

@@ -197,7 +197,10 @@ class User extends Controller\Controller{
* @throws \Exception
*/
public function logout(\Base $f3){
$this->logoutCharacter($f3, false, true, true, true);
$data = $f3->get('POST');
$deleteCookie = (bool)$data['deleteCookie'];
$this->logoutCharacter($f3, false, true, true, $deleteCookie, 200);
}
/**
@@ -373,7 +376,7 @@ class User extends Controller\Controller{
sprintf(self::LOG_DELETE_ACCOUNT, $user->id, $user->name)
);
$this->logoutCharacter($f3, true, true, true, true);
$this->logoutCharacter($f3, true, true, true, true, 200);
$user->erase();
}
}else{

View File

@@ -24,6 +24,12 @@ use Exodus4D\Pathfinder\Exception\PathfinderException;
class Controller {
/**
* default HTTP response status for users that logged out
* -> if it is a "graceful" logout (e.g. user clicks "logout" button, we use 200)
*/
const DEFAULT_STATUS_LOGOUT = 403;
// cookie specific keys (names)
const COOKIE_NAME_STATE = 'cookie';
const COOKIE_PREFIX_CHARACTER = 'char';
@@ -481,9 +487,17 @@ class Controller {
* @param bool $deleteSession
* @param bool $deleteLog
* @param bool $deleteCookie
* @param int $status
* @throws \Exception
*/
protected function logoutCharacter(\Base $f3, bool $all = false, bool $deleteSession = true, bool $deleteLog = true, bool $deleteCookie = false){
protected function logoutCharacter(
\Base $f3,
bool $all = false,
bool $deleteSession = true,
bool $deleteLog = true,
bool $deleteCookie = false,
int $status = self::DEFAULT_STATUS_LOGOUT
){
$sessionCharacterData = (array)$f3->get(Api\User::SESSION_KEY_CHARACTERS);
if($sessionCharacterData){
@@ -512,7 +526,6 @@ class Controller {
}
if($f3->get('AJAX')){
$status = 403;
$f3->status($status);
$return = (object) [];

View File

@@ -767,26 +767,36 @@ define([
Util.showVersionInfo();
// show log off message
let isLogOut = location.search.split('logout')[1];
if(isLogOut !== undefined){
let searchParams = new URLSearchParams(location.search); // jshint ignore:line
if(
searchParams.has('logout') ||
searchParams.has('logoutGraceful')
){
let cls = 'txt-color-warning';
let text = [
'For security reasons, you were logged out automatically',
'Please log in again'
];
if(searchParams.has('logoutGraceful')){
cls = 'txt-color-success';
text = ['You have successfully logged out'];
}
// show logout dialog
let options = {
buttons: {
close: {
label: 'close',
className: ['btn-default'].join(' ')
className: 'btn-default'
}
},
content: {
icon: 'fa-sign-out-alt',
class: 'txt-color-warning',
class: cls,
title: 'Logout',
headline: 'Logout',
text: [
'For security reasons, you were logged out automatically',
'Please log in again'
]
text: text
}
};

View File

@@ -572,7 +572,7 @@ define([
initData(),
getMapAccessData()
])
.then(([mapModule, accessData]) => Promise.all([
.then(([mapModule, initData, accessData]) => Promise.all([
initMapModule(mapModule),
initMapWorker(mapModule,accessData),
initUnload(mapModule)

View File

@@ -302,7 +302,7 @@ define([
icon: 'fa-sign-in-alt',
btnType: 'warning',
action: 'Logout',
data: {clearCookies: 1}
data: {graceful: 1, deleteCookie: 1}
}
]));
@@ -725,7 +725,8 @@ define([
case 'Logout':
Util.logout({
ajaxData: {
clearCookies: Util.getObjVal(data, 'clearCookies') || false
graceful: parseInt(Util.getObjVal(data, 'graceful')) || 0,
deleteCookie: parseInt(Util.getObjVal(data, 'deleteCookie')) || 0
}
});
break;

View File

@@ -27,7 +27,7 @@ define([
headlineElement.delay(300).velocity('transition.shrinkIn', {
duration: 500
}).delay(800);
}).delay(500);
headlineElement.velocity({
scale: 1.05

View File

@@ -3506,10 +3506,7 @@ define([
let currentUrl = document.URL;
if(url !== currentUrl){
if(
params &&
params.length > 0
){
if(params && params.length > 0){
url += '?' + params.join('&');
}
window.location = url;
@@ -3520,23 +3517,18 @@ define([
* send logout request
* @param params
*/
let logout = (params) => {
let data = {};
if(
params &&
params.ajaxData
){
data = params.ajaxData;
}
let logout = params => {
let data = getObjVal(params, 'ajaxData') || {};
$.ajax({
type: 'POST',
url: Init.path.logout,
data: data,
dataType: 'json'
}).done(function(data){
if(data.reroute){
redirect(data.reroute, ['logout']);
}).done(function(responseData){
if(responseData.reroute){
let params = data.graceful ? 'logoutGraceful' : 'logout';
redirect(responseData.reroute, [params]);
}
}).fail(function(jqXHR, status, error){
let reason = status + ' ' + error;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -767,26 +767,36 @@ define([
Util.showVersionInfo();
// show log off message
let isLogOut = location.search.split('logout')[1];
if(isLogOut !== undefined){
let searchParams = new URLSearchParams(location.search); // jshint ignore:line
if(
searchParams.has('logout') ||
searchParams.has('logoutGraceful')
){
let cls = 'txt-color-warning';
let text = [
'For security reasons, you were logged out automatically',
'Please log in again'
];
if(searchParams.has('logoutGraceful')){
cls = 'txt-color-success';
text = ['You have successfully logged out'];
}
// show logout dialog
let options = {
buttons: {
close: {
label: 'close',
className: ['btn-default'].join(' ')
className: 'btn-default'
}
},
content: {
icon: 'fa-sign-out-alt',
class: 'txt-color-warning',
class: cls,
title: 'Logout',
headline: 'Logout',
text: [
'For security reasons, you were logged out automatically',
'Please log in again'
]
text: text
}
};

View File

@@ -572,7 +572,7 @@ define([
initData(),
getMapAccessData()
])
.then(([mapModule, accessData]) => Promise.all([
.then(([mapModule, initData, accessData]) => Promise.all([
initMapModule(mapModule),
initMapWorker(mapModule,accessData),
initUnload(mapModule)

View File

@@ -302,7 +302,7 @@ define([
icon: 'fa-sign-in-alt',
btnType: 'warning',
action: 'Logout',
data: {clearCookies: 1}
data: {graceful: 1, deleteCookie: 1}
}
]));
@@ -725,7 +725,8 @@ define([
case 'Logout':
Util.logout({
ajaxData: {
clearCookies: Util.getObjVal(data, 'clearCookies') || false
graceful: parseInt(Util.getObjVal(data, 'graceful')) || 0,
deleteCookie: parseInt(Util.getObjVal(data, 'deleteCookie')) || 0
}
});
break;

View File

@@ -27,7 +27,7 @@ define([
headlineElement.delay(300).velocity('transition.shrinkIn', {
duration: 500
}).delay(800);
}).delay(500);
headlineElement.velocity({
scale: 1.05

View File

@@ -3506,10 +3506,7 @@ define([
let currentUrl = document.URL;
if(url !== currentUrl){
if(
params &&
params.length > 0
){
if(params && params.length > 0){
url += '?' + params.join('&');
}
window.location = url;
@@ -3520,23 +3517,18 @@ define([
* send logout request
* @param params
*/
let logout = (params) => {
let data = {};
if(
params &&
params.ajaxData
){
data = params.ajaxData;
}
let logout = params => {
let data = getObjVal(params, 'ajaxData') || {};
$.ajax({
type: 'POST',
url: Init.path.logout,
data: data,
dataType: 'json'
}).done(function(data){
if(data.reroute){
redirect(data.reroute, ['logout']);
}).done(function(responseData){
if(responseData.reroute){
let params = data.graceful ? 'logoutGraceful' : 'logout';
redirect(responseData.reroute, [params]);
}
}).fail(function(jqXHR, status, error){
let reason = status + ' ' + error;

View File

@@ -152,6 +152,12 @@
}
}
}
// notification dialog ========================================================
#pf-notification-dialog{
h1{
will-change: transform;
}
}
// settings dialog ============================================================
#pf-settings-dialog{