From 0869034ed71e3d3a6bc03551e48657bd83be9b96 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 17 Oct 2013 19:45:55 +0200 Subject: Day 3 --- inc/user.inc.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'inc/user.inc.php') 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); } -- cgit v1.2.3-55-g7522