summaryrefslogtreecommitdiffstats
path: root/inc
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
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')
-rw-r--r--inc/menu.inc.php21
-rw-r--r--inc/render.inc.php22
-rw-r--r--inc/user.inc.php59
-rw-r--r--inc/util.inc.php7
4 files changed, 107 insertions, 2 deletions
diff --git a/inc/menu.inc.php b/inc/menu.inc.php
new file mode 100644
index 00000000..7b2502b9
--- /dev/null
+++ b/inc/menu.inc.php
@@ -0,0 +1,21 @@
+<?php
+
+require_once('inc/render.inc.php');
+require_once('inc/user.inc.php');
+
+class Menu
+{
+
+ public function loginPanel()
+ {
+ if (User::getName() === false) return Render::parse('menu-login');
+ return Render::parse('menu-logout', array('user' => User::getName()));
+ }
+
+ public function token()
+ {
+ return 123;
+ }
+
+}
+
diff --git a/inc/render.inc.php b/inc/render.inc.php
index 455fd87d..41b8e2b8 100644
--- a/inc/render.inc.php
+++ b/inc/render.inc.php
@@ -46,10 +46,12 @@ class Render
,
' </head>
<body>
+ <div class="container">
',
self::$body
,
- ' <script src="script/jquery.js"></script>
+ ' </div>
+ <script src="script/jquery.js"></script>
<script src="script/bootstrap.min.js"></script></body>
</html>'
;
@@ -74,12 +76,28 @@ class Render
/**
* Add the given template to the output, using the given params for placeholders in the template
*/
- public static function parse($template, $params)
+ public static function addTemplate($template, $params = false)
{
self::$body .= self::$mustache->render(self::getTemplate($template), $params);
}
/**
+ * Add error message to page
+ */
+ public static function addError($message)
+ {
+ self::addTemplate('messagebox-error', array('message' => $message));
+ }
+
+ /**
+ * Parse template with given params and return; do not add to body
+ */
+ public static function parse($template, $params = false)
+ {
+ return self::$mustache->render(self::getTemplate($template), $params);
+ }
+
+ /**
* Open the given html tag, optionally adding the passed assoc array of params
*/
public static function openTag($tag, $params = false)
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);
+ }
+
+}
+
diff --git a/inc/util.inc.php b/inc/util.inc.php
index 75cd914e..793902ec 100644
--- a/inc/util.inc.php
+++ b/inc/util.inc.php
@@ -17,5 +17,12 @@ class Util
}
exit(0);
}
+
+ public static function redirect($location)
+ {
+ session_write_close();
+ Header('Location: ' . $location);
+ exit(0);
+ }
}