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'])) {
|
||||
redirect('/login');
|
||||
}
|
||||
} else {
|
||||
} elseif($auth->good()) {
|
||||
// Block user if he/she has been banned.
|
||||
if (user()->authlevel === 2) {
|
||||
exit("Your account has been banned.");
|
||||
|
@ -56,5 +56,7 @@ if (!file_exists('../.installed') && $uri[0] !== 'install') {
|
|||
if (user()->authlevel !== 1 && $uri[0] === 'admin') {
|
||||
redirect('/');
|
||||
}
|
||||
|
||||
user()->update_online_time();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@ function db(): Database
|
|||
function redirect(string $location): void
|
||||
{
|
||||
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");
|
||||
} else {
|
||||
header("Location: $location");
|
||||
|
|
|
@ -38,6 +38,14 @@ class User extends Model
|
|||
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
|
||||
* 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