File: D:/HostingSpaces/NVonken/mijneigenlied.com/wwwroot/Core/Domain/User.php
<?php
class User extends BaseClass
{
public static $_IsChecked = false;
private static $_userId = 0;
private static $_user = null;
////////////////
// Properties //
////////////////
public $Id;
public $Name;
public $Email;
public $Password;
public $ActivationHash;
public $Active;
public $IsAdmin;
public static $_primaryKey = array("Id");
////////////////////
// Public Methods //
////////////////////
public function __construct()
{
//set the primary key(s)
//$this->_primaryKey[] = "Id";
parent::__construct();
}
public static function Select($id)
{
return parent::Select($id);
}
/**
* @return User[]
*/
public static function SelectAll()
{
return parent::SelectAll();
}
public static function SelectByEmail($email)
{
return reset(parent::SelectObjects("SELECT *
FROM User
WHERE Email = '".(parent::_db()->escape($email))."'"));
}
public static function CheckLogin()
{
Session::CleanSessions();
if(User::$_IsChecked == true)
return User::$_userId > 0;
//check session
if(isset($_SESSION['sessionhash']))
{
//create session object
$session = Session::SelectByHash($_SESSION['sessionhash']);
if($session == null)
{
//reset session
$_SESSION['sessionhash'] = '';
User::$_IsChecked = true;
return false;
}
else
{
//refresh session
$_SESSION['sessionhash'] = $session->Hash;
$session->Refresh();
User::$_userId = $session->UserId;
User::$_user = User::Select(User::$_userId);
User::$_IsChecked = true;
return true;
}
}
}
/**
* Get the user info of the loggedin user
* @static
* @return User
* @throws Exception when not checked if there is a user logged in with CheckLogin()
*/
public static function GetUserInfo()
{
if (!User::$_IsChecked || User::$_user == null)
throw new Exception("Fatal Error: Unvalidated user info request");
return User::$_user;
}
public static function GetSessionHash()
{
if(User::$_IsChecked)
return $_SESSION["sessionhash"];
return null;
}
public function Insert()
{
return parent::Insert($this);
}
public function Update()
{
parent::Update($this);
}
public function Delete()
{
parent::Delete();
}
public function Login()
{
$sessionHash = sha1(microtime().SALT);
//create database session
$session = new Session();
$session->Hash = $sessionHash;
$session->UserId = $this->Id;
$session->IP = $_SERVER["REMOTE_ADDR"];
$session->Time = time();
$session->Insert();
//create session with ID
$_SESSION["sessionhash"] = $sessionHash;
}
}
?>