summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2021-06-28 15:03:09 +0200
committerSimon Rettberg2021-06-28 15:03:09 +0200
commit0a53c4a6da057d7679347a14ae73a378a432ba48 (patch)
treef8b714cd1c00d5c855bdfdd46cd2138355a77240 /inc
parent[eventlog] Add event filtering and notification system (diff)
downloadslx-admin-0a53c4a6da057d7679347a14ae73a378a432ba48.tar.gz
slx-admin-0a53c4a6da057d7679347a14ae73a378a432ba48.tar.xz
slx-admin-0a53c4a6da057d7679347a14ae73a378a432ba48.zip
[inc/User] Make sure user has a token
Diffstat (limited to 'inc')
-rw-r--r--inc/user.inc.php28
1 files changed, 18 insertions, 10 deletions
diff --git a/inc/user.inc.php b/inc/user.inc.php
index e89a4355..cf9c38c0 100644
--- a/inc/user.inc.php
+++ b/inc/user.inc.php
@@ -7,7 +7,7 @@ class User
private static $user = false;
- public static function isLoggedIn()
+ public static function isLoggedIn(): bool
{
return self::$user !== false;
}
@@ -113,6 +113,9 @@ class User
if (self::isLoggedIn())
return true;
if (Session::load()) {
+ if (empty(Session::get('token'))) {
+ self::generateToken();
+ }
$uid = Session::getUserId();
if ($uid < 1)
self::logout();
@@ -150,15 +153,7 @@ class User
if (!Crypto::verify($pass, $ret['passwd']))
return false;
Session::create($ret['passwd'], $ret['userid'], $fixedIp);
- Session::set('token', md5($ret['passwd'] . ','
- . rand() . ','
- . time() . ','
- . rand() . ','
- . $_SERVER['REMOTE_ADDR'] . ','
- . rand() . ','
- . $_SERVER['REMOTE_PORT'] . ','
- . rand() . ','
- . $_SERVER['HTTP_USER_AGENT']), false);
+ self::generateToken($ret['passwd']);
return true;
}
@@ -187,4 +182,17 @@ class User
return self::$user['lasteventid'];
}
+ private static function generateToken($salt = '')
+ {
+ Session::set('token', md5($salt . ','
+ . rand() . ','
+ . time() . ','
+ . rand() . ','
+ . $_SERVER['REMOTE_ADDR'] . ','
+ . rand() . ','
+ . $_SERVER['REMOTE_PORT'] . ','
+ . rand() . ','
+ . $_SERVER['HTTP_USER_AGENT']), false);
+ }
+
}