summaryrefslogtreecommitdiffstats
path: root/inc/user.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-10-09 16:01:11 +0200
committerSimon Rettberg2014-10-09 16:01:11 +0200
commite1dc0d3c99217504de2ac8467156274786efc0bd (patch)
tree130d7fed1fff8aaaffe5942cf2a3d6bb1dad03c8 /inc/user.inc.php
parentMinor fixes and improvements (diff)
downloadslx-admin-e1dc0d3c99217504de2ac8467156274786efc0bd.tar.gz
slx-admin-e1dc0d3c99217504de2ac8467156274786efc0bd.tar.xz
slx-admin-e1dc0d3c99217504de2ac8467156274786efc0bd.zip
Big load of changes
- Added callback functionality for taskmanager tasks. You can launch a task and define a callback function to be run when the task finished. This requires activating the cronjob - Added cron functionality: Add cronjob that calls the cron api every 5 minutes to use it. (See cron.inc.php) - Added eventlog - Added missing translations - Merged main-menu-login and main-menu-logout
Diffstat (limited to 'inc/user.inc.php')
-rw-r--r--inc/user.inc.php41
1 files changed, 32 insertions, 9 deletions
diff --git a/inc/user.inc.php b/inc/user.inc.php
index 19d17753..111849fe 100644
--- a/inc/user.inc.php
+++ b/inc/user.inc.php
@@ -4,6 +4,7 @@ require_once('inc/session.inc.php');
class User
{
+
private static $user = false;
public static function isLoggedIn()
@@ -13,26 +14,29 @@ class User
public static function getName()
{
- if (self::$user === false) return false;
+ if (!self::isLoggedIn())
+ return false;
return self::$user['fullname'];
}
public static function hasPermission($permission)
{
- if (self::$user === false) return false;
+ if (!self::isLoggedIn())
+ return false;
return (self::$user['permissions'] & Permission::get($permission)) != 0;
}
public static function load()
{
- if (self::isLoggedIn()) {
+ if (self::isLoggedIn())
return true;
- }
if (Session::load()) {
$uid = Session::get('uid');
- if ($uid === false || $uid < 1) self::logout();
+ if ($uid === false || $uid < 1)
+ self::logout();
self::$user = Database::queryFirst('SELECT * FROM user WHERE userid = :uid LIMIT 1', array(':uid' => $uid));
- if (self::$user === false) self::logout();
+ if (self::$user === false)
+ self::logout();
return true;
}
return false;
@@ -41,8 +45,10 @@ class User
public static function login($user, $pass)
{
$ret = Database::queryFirst('SELECT userid, passwd FROM user WHERE login = :user LIMIT 1', array(':user' => $user));
- if ($ret === false) return false;
- if (!Crypto::verify($pass, $ret['passwd'])) return false;
+ if ($ret === false)
+ return false;
+ if (!Crypto::verify($pass, $ret['passwd']))
+ return false;
Session::create();
Session::set('uid', $ret['userid']);
Session::set('token', md5(rand() . time() . rand() . $_SERVER['REMOTE_ADDR'] . rand() . $_SERVER['REMOTE_PORT'] . rand() . $_SERVER['HTTP_USER_AGENT']));
@@ -57,5 +63,22 @@ class User
exit(0);
}
-}
+ public static function setLastSeenEvent($eventid)
+ {
+ if (!self::isLoggedIn())
+ return;
+ Database::exec("UPDATE user SET lasteventid = :eventid WHERE userid = :userid LIMIT 1", array(
+ 'eventid' => $eventid,
+ 'userid' => self::$user['userid']
+ ));
+ self::$user['lasteventid'] = $eventid;
+ }
+ public static function getLastSeenEvent()
+ {
+ if (!self::isLoggedIn())
+ return false;
+ return self::$user['lasteventid'];
+ }
+
+}