perfected automated logins
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s

This commit is contained in:
2023-10-29 19:52:08 +01:00
parent e9a718ee96
commit 0ed8ab9137
7 changed files with 39 additions and 33 deletions

View File

@ -137,4 +137,36 @@ function getMenu()
$arr = array_values($arr);
return $arr;
}
function autoLoginCheck()
{
//check if user has a cookie and if so, logg them in and refresh the page
if(isset($_COOKIE['token']) && $_COOKIE['token'] != '' && !$_SESSION['user'])
{
$u = new User();
$allusers = $u->getAll(false);
foreach($allusers as $user)
{
if($user['token'] && $user['token'] == $_COOKIE['token'])
{
$u->id = $user['id'];
break;
}
}
if($u->id) //valid cookie, users gets logged in
{
$u->load($u->id);
$u->login();
$url = '/'.implode('/',$GLOBALS['url']);
header("HX-Redirect: ". $url);
exit('<meta http-equiv="Refresh" content="seconds; url='. $url.'"> <script>window.location.href="'. $url.'"</script> ');
}
else //invalid cookie gets deleted
{
setcookie('token', '', time() - 3600, "/");
}
}
}