summaryrefslogtreecommitdiffstats
path: root/inc/user.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2023-11-14 14:47:55 +0100
committerSimon Rettberg2023-11-14 14:47:55 +0100
commit06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0 (patch)
tree7e5493b102074672d8cfd8fe1a61e49f080edbe8 /inc/user.inc.php
parentUpdate phpstorm config (diff)
downloadslx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.gz
slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.xz
slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.zip
Add function param/return types, fix a lot more phpstorm complaints
Diffstat (limited to 'inc/user.inc.php')
-rw-r--r--inc/user.inc.php22
1 files changed, 13 insertions, 9 deletions
diff --git a/inc/user.inc.php b/inc/user.inc.php
index cf9c38c0..4d278e1b 100644
--- a/inc/user.inc.php
+++ b/inc/user.inc.php
@@ -1,5 +1,7 @@
<?php
+use JetBrains\PhpStorm\NoReturn;
+
require_once('inc/session.inc.php');
class User
@@ -26,7 +28,7 @@ class User
return self::$user['fullname'];
}
- public static function hasPermission($permission, $locationid = NULL)
+ public static function hasPermission(string $permission, ?int $locationid = NULL): bool
{
if (!self::isLoggedIn())
return false;
@@ -54,11 +56,12 @@ class User
/**
* Confirm current user has the given permission, stop execution and show error message
* otherwise.
+ *
* @param string $permission Permission to check for
* @param null|int $locationid location this permission has to apply to, NULL if any location is sufficient
* @param null|string $redirect page to redirect to if permission is not given, NULL defaults to main page
*/
- public static function assertPermission($permission, $locationid = NULL, $redirect = NULL)
+ public static function assertPermission(string $permission, ?int $locationid = NULL, ?string $redirect = NULL): void
{
if (User::hasPermission($permission, $locationid))
return;
@@ -108,7 +111,7 @@ class User
return [];
}
- public static function load()
+ public static function load(): bool
{
if (self::isLoggedIn())
return true;
@@ -128,7 +131,7 @@ class User
return false;
}
- public static function testPassword($userid, $password)
+ public static function testPassword(string $userid, string $password): bool
{
$ret = Database::queryFirst('SELECT passwd FROM user WHERE userid = :userid LIMIT 1', compact('userid'));
if ($ret === false)
@@ -136,7 +139,7 @@ class User
return Crypto::verify($password, $ret['passwd']);
}
- public static function updatePassword($password)
+ public static function updatePassword(string $password): bool
{
if (!self::isLoggedIn())
return false;
@@ -145,7 +148,7 @@ class User
return Database::exec('UPDATE user SET passwd = :passwd WHERE userid = :userid LIMIT 1', compact('userid', 'passwd')) > 0;
}
- public static function login(string $user, string $pass, bool $fixedIp)
+ public static function login(string $user, string $pass, bool $fixedIp): bool
{
$ret = Database::queryFirst('SELECT userid, passwd FROM user WHERE login = :user LIMIT 1', array(':user' => $user));
if ($ret === false)
@@ -157,14 +160,15 @@ class User
return true;
}
- public static function logout()
+ #[NoReturn]
+ public static function logout(): void
{
Session::delete();
Header('Location: ?do=Main&fromlogout');
exit(0);
}
- public static function setLastSeenEvent($eventid)
+ public static function setLastSeenEvent(int $eventid): void
{
if (!self::isLoggedIn())
return;
@@ -182,7 +186,7 @@ class User
return self::$user['lasteventid'];
}
- private static function generateToken($salt = '')
+ private static function generateToken($salt = ''): void
{
Session::set('token', md5($salt . ','
. rand() . ','