perfected automated logins
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s
This commit is contained in:
@ -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, "/");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user