summaryrefslogtreecommitdiffstats
path: root/inc/user.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2013-10-16 19:34:08 +0200
committerSimon Rettberg2013-10-16 19:34:08 +0200
commite74e32a0eb4b2bb9691a079d6dc579925d7bb0ce (patch)
tree01f686385bab29fe14b13a819fdbb87ba6ea1100 /inc/user.inc.php
parentAdd simple menu bar (diff)
downloadslx-admin-e74e32a0eb4b2bb9691a079d6dc579925d7bb0ce.tar.gz
slx-admin-e74e32a0eb4b2bb9691a079d6dc579925d7bb0ce.tar.xz
slx-admin-e74e32a0eb4b2bb9691a079d6dc579925d7bb0ce.zip
New stuff
Diffstat (limited to 'inc/user.inc.php')
-rw-r--r--inc/user.inc.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/inc/user.inc.php b/inc/user.inc.php
new file mode 100644
index 00000000..de615932
--- /dev/null
+++ b/inc/user.inc.php
@@ -0,0 +1,59 @@
+<?php
+
+require_once('inc/session.inc.php');
+
+class User
+{
+ private static $user = false;
+ private static $session = false;
+
+ public static function isLoggedIn()
+ {
+ return self::$user !== false;
+ }
+
+ public static function getName()
+ {
+ if (self::$user === false) return false;
+ return self::$user['name'];
+ }
+
+ public static function load()
+ {
+ if (isset($_REQUEST['PHPSESSID']) || isset($_COOKIE['PHPSESSID'])) {
+ session_start();
+ if (!isset($_SESSION['uid']) || !is_numeric($_SESSION['uid'])) {
+ self::logout();
+ return false;
+ }
+ // TODO: Query user db for persistent data
+ $user['name'] = 'Hans';
+ return true;
+ }
+ return false;
+ }
+
+ public static function login($user, $pass)
+ {
+ if ($user == 'test' && $pass == 'test') {
+ session_start();
+ $_SESSION['uid'] = 1;
+ $_SESSION['token'] = md5(rand() . time() . rand() . $_SERVER['REMOTE_ADDR'] . rand() . $_SERVER['REMOTE_PORT'] . rand() . $_SERVER['HTTP_USER_AGENT']);
+ session_write_close();
+ return true;
+ }
+ return false;
+ }
+
+ public static function logout()
+ {
+ session_unset();
+ session_destroy();
+ if (setcookie('PHPSESSID', '', time() - 86400)) {
+ Header('Location: ?do=main&fromlogout');
+ }
+ exit(0);
+ }
+
+}
+