remove session when logging out

This commit is contained in:
Uwe Steinmann 2023-12-19 09:31:18 +01:00
parent 6a558a4d26
commit 9050f8b374

View File

@ -258,7 +258,24 @@ class RestapiController { /* {{{ */
$userobj = $this->container->userobj;
$settings = $this->container->config;
setcookie("mydms_session", '', time()-3600, $settings->_httpRoot);
if(isset($_COOKIE['mydms_session'])) {
$dms_session = $_COOKIE["mydms_session"];
$db = $dms->getDb();
$session = new SeedDMS_Session($db);
$session->load($dms_session);
// If setting the user id to 0 worked, it would be a way to logout a
// user. It doesn't work because of a foreign constraint in the database
// won't allow it. So we keep on deleting the session and the cookie on
// logout
// $session->setUser(0); does not work because of foreign user constraint
if(!$session->delete($dms_session)) {
UI::exitError(getMLText("logout"),$db->getErrorMsg());
}
setcookie("mydms_session", '', time()-3600, $settings->_httpRoot);
}
return $response->withJson(array('success'=>true, 'message'=>'', 'data'=>''), 200);
} /* }}} */