Update online time, auth logic
This commit is contained in:
parent
8b3b1845dc
commit
9d28a9b380
|
@ -41,7 +41,7 @@ if (!file_exists('../.installed') && $uri[0] !== 'install') {
|
||||||
if (!in_array($uri[0], ['login', 'register', 'verify', 'lostpassword', 'help'])) {
|
if (!in_array($uri[0], ['login', 'register', 'verify', 'lostpassword', 'help'])) {
|
||||||
redirect('/login');
|
redirect('/login');
|
||||||
}
|
}
|
||||||
} else {
|
} elseif($auth->good()) {
|
||||||
// Block user if he/she has been banned.
|
// Block user if he/she has been banned.
|
||||||
if (user()->authlevel === 2) {
|
if (user()->authlevel === 2) {
|
||||||
exit("Your account has been banned.");
|
exit("Your account has been banned.");
|
||||||
|
@ -56,5 +56,7 @@ if (!file_exists('../.installed') && $uri[0] !== 'install') {
|
||||||
if (user()->authlevel !== 1 && $uri[0] === 'admin') {
|
if (user()->authlevel !== 1 && $uri[0] === 'admin') {
|
||||||
redirect('/');
|
redirect('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user()->update_online_time();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ function db(): Database
|
||||||
function redirect(string $location): void
|
function redirect(string $location): void
|
||||||
{
|
{
|
||||||
if (is_htmx()) {
|
if (is_htmx()) {
|
||||||
$json = json_encode(['path' => $location, 'target' => '#'.$_SERVER['HTTP_HX_TARGET'] ?? '#middle']);
|
$target = isset($_SERVER['HTTP_HX_TARGET']) ? '#'.$_SERVER['HTTP_HX_TARGET'] : '#middle';
|
||||||
|
$json = json_encode(['path' => $location, 'target' => $target]);
|
||||||
header("HX-Location: $json");
|
header("HX-Location: $json");
|
||||||
} else {
|
} else {
|
||||||
header("Location: $location");
|
header("Location: $location");
|
||||||
|
|
|
@ -38,6 +38,14 @@ class User extends Model
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a manual update to online time for this user.
|
||||||
|
*/
|
||||||
|
public function update_online_time(): void
|
||||||
|
{
|
||||||
|
db()->query('UPDATE users SET onlinetime=CURRENT_TIMESTAMP WHERE id=?;', [$this->id]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save works just as it does on the Model class. In our case, though, user state changing may necessitate
|
* Save works just as it does on the Model class. In our case, though, user state changing may necessitate
|
||||||
* OOB swaps for parts of the UI that have user data displayed. Left and right nav, for example. In these cases,
|
* OOB swaps for parts of the UI that have user data displayed. Left and right nav, for example. In these cases,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user