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:
parent
e9a718ee96
commit
0ed8ab9137
1
.vscode/extensions.json
vendored
1
.vscode/extensions.json
vendored
@ -7,6 +7,5 @@
|
|||||||
"github.copilot-chat",
|
"github.copilot-chat",
|
||||||
"anbuselvanrocky.bootstrap5-vscode",
|
"anbuselvanrocky.bootstrap5-vscode",
|
||||||
"hansuxdev.bootstrap5-snippets",
|
"hansuxdev.bootstrap5-snippets",
|
||||||
"brapifra.phpserver"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
5
.vscode/launch.json
vendored
5
.vscode/launch.json
vendored
@ -11,10 +11,11 @@
|
|||||||
"-t",
|
"-t",
|
||||||
"web"
|
"web"
|
||||||
],
|
],
|
||||||
"hostname": "localhost",
|
|
||||||
"port": 5902,
|
"port": 5902,
|
||||||
"serverReadyAction": {
|
"serverReadyAction": {
|
||||||
"action": "openExternally"
|
"action": "openExternally",
|
||||||
|
"pattern": "listening on http://localhost:([0-9]+)",
|
||||||
|
"uriFormat": "http://localhost:%s",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -137,4 +137,36 @@ function getMenu()
|
|||||||
$arr = array_values($arr);
|
$arr = array_values($arr);
|
||||||
|
|
||||||
return $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, "/");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -29,6 +29,8 @@ if($url==[] && $_SERVER['HTTP_HX_CURRENT_URL'])
|
|||||||
$GLOBALS['url'] = $url;
|
$GLOBALS['url'] = $url;
|
||||||
//echo print_r(['url'=>$url,'server'=>$_SERVER,'request'=>$_REQUEST,'cookie'=>$_COOKIE,'session'=>$_SESSION],true);
|
//echo print_r(['url'=>$url,'server'=>$_SERVER,'request'=>$_REQUEST,'cookie'=>$_COOKIE,'session'=>$_SESSION],true);
|
||||||
|
|
||||||
|
autoLoginCheck();
|
||||||
|
|
||||||
$response = callHook($url);
|
$response = callHook($url);
|
||||||
|
|
||||||
if(is_string($response))
|
if(is_string($response))
|
||||||
|
@ -11,34 +11,6 @@ class Err extends Page {
|
|||||||
|
|
||||||
function notallowed()
|
function notallowed()
|
||||||
{
|
{
|
||||||
//check if user has a cookie and if so, logg them in and refresh the page
|
|
||||||
if(isset($_COOKIE['token']))
|
|
||||||
{
|
|
||||||
$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)
|
|
||||||
{
|
|
||||||
$u->load($u->id);
|
|
||||||
$u->login();
|
|
||||||
$url = '/'.implode('/',$GLOBALS['url']);
|
|
||||||
//var_dump($url);
|
|
||||||
$this->redirect($url);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setcookie('token', '', time() - 3600, "/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->set("loggedin",(isset($_SESSION['user']) && $_SESSION['user'] !== false));
|
$this->set("loggedin",(isset($_SESSION['user']) && $_SESSION['user'] !== false));
|
||||||
$this->set('template', "notallowed.html");
|
$this->set('template', "notallowed.html");
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<h1>Profil</h1>
|
<h1>Profil</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
<img src="<?= $user['photo']?:'https://pictshare.net/1ch3e5.png' ?>/300x170/fixedsize" class="card-img-top" alt="<?= escape($user['name']); ?>'s profile Picture">
|
<img src="<?= $user['photo']?:'https://pictshare.net/1ch3e5.png' ?>/300x170/forcesize" class="card-img-top" alt="<?= escape($user['name']); ?>'s profile Picture">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-9">
|
<div class="col-9">
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<img src="<?= $dogdata['photo']?:'https://pictshare.net/1ch3e5.png' ?>/300x170/fixedsize" class="card-img-top" alt="<?= escape($dogdata['name']); ?>'s profile Picture">
|
<img src="<?= $dogdata['photo']?:'https://pictshare.net/1ch3e5.png' ?>/300x170/forcesize" class="card-img-top" alt="<?= escape($dogdata['name']); ?>'s profile Picture">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title"><?= escape($dogdata['name']); ?></h5>
|
<h5 class="card-title"><?= escape($dogdata['name']); ?></h5>
|
||||||
<p class="card-text">
|
<p class="card-text">
|
||||||
|
Reference in New Issue
Block a user