diff options
author | Simon Rettberg | 2013-10-17 19:45:55 +0200 |
---|---|---|
committer | Simon Rettberg | 2013-10-17 19:45:55 +0200 |
commit | 0869034ed71e3d3a6bc03551e48657bd83be9b96 (patch) | |
tree | d14a007fb1f198d7320ad0983c6f737422760495 /inc/user.inc.php | |
parent | New stuff (diff) | |
download | slx-admin-0869034ed71e3d3a6bc03551e48657bd83be9b96.tar.gz slx-admin-0869034ed71e3d3a6bc03551e48657bd83be9b96.tar.xz slx-admin-0869034ed71e3d3a6bc03551e48657bd83be9b96.zip |
Day 3
Diffstat (limited to 'inc/user.inc.php')
-rw-r--r-- | inc/user.inc.php | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/inc/user.inc.php b/inc/user.inc.php index de615932..f10a4f65 100644 --- a/inc/user.inc.php +++ b/inc/user.inc.php @@ -5,7 +5,6 @@ require_once('inc/session.inc.php'); class User { private static $user = false; - private static $session = false; public static function isLoggedIn() { @@ -20,14 +19,8 @@ class User 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'; + if (Session::loadSession()) { + self::$user['name'] = 'Hans'; return true; } return false; @@ -36,10 +29,10 @@ class User 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(); + Session::createSession();; + Session::set('uid', 1); + Session::set('token', md5(rand() . time() . rand() . $_SERVER['REMOTE_ADDR'] . rand() . $_SERVER['REMOTE_PORT'] . rand() . $_SERVER['HTTP_USER_AGENT'])); + Session::save(); return true; } return false; @@ -47,11 +40,8 @@ class User public static function logout() { - session_unset(); - session_destroy(); - if (setcookie('PHPSESSID', '', time() - 86400)) { - Header('Location: ?do=main&fromlogout'); - } + Session::delete(); + Header('Location: ?do=main&fromlogout'); exit(0); } |