Permalink
Browse files

Implements User class - closes #100

- Updated design (Javascripts)
- Added login and register page
  • Loading branch information...
1 parent af24e7c commit f3d7514e1f5ba456776fd06fa488ead6f750a67d @NoxNebula NoxNebula committed Mar 2, 2012
View
@@ -3,7 +3,7 @@
-- http://www.phpmyadmin.net
--
-- Host: localhost
--- Erstellungszeit: 29. Feb 2012 um 18:56
+-- Erstellungszeit: 02. Mrz 2012 um 17:22
-- Server Version: 5.5.18
-- PHP-Version: 5.3.8
@@ -394,14 +394,6 @@ CREATE TABLE IF NOT EXISTS `session` (
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
---
--- Daten für Tabelle `session`
---
-
-INSERT INTO `session` (`ID`, `SessionValue`, `UserID`, `Username`, `IPAddress`, `UserAgent`, `LastActivityTime`, `Token`) VALUES
-('qrlp3vc2f4s02uicu6sqbmnn7aap87ok', 'Test|s:2:\\"Hi\\";', 0, '', '', '', 1326208529, ''),
-('u8k49vvkt6d208fdbphtkl27dr1bjp8j', 'Test|s:2:\\"Hi\\";', 0, '', '127.0.0.1', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.26 Safari/535.11', 1326208549, '');
-
-- --------------------------------------------------------
--
View
@@ -0,0 +1,11 @@
+<?php
+/**
+ * @author SilexBB
+ * @copyright 2011 - 2012 Silex Bulletin Board
+ * @license GPL version 3 or higher <http://www.gnu.org/licenses/gpl-3.0.html>
+ */
+
+class Group {
+ // Usergroup
+}
+?>
View
@@ -7,16 +7,25 @@
class SBB {
// Objects
- private static $Database = null, $Config = null, $Template = null, $Style = null, $Menu = null, $Page = null;
+ private static $Database = null,
+ $Config = null,
+ $Template = null,
+ $Style = null,
+ $Menu = null,
+ $Page = null,
+ $User = null;
/**
* Initial
* @return void
*/
public static final function Initial() {
// Initialize classes and objects
- self::$Style = Style::GetInstance();
Language::Initialize(isset($_GET['lang']) ? $_GET['lang'] : null);
+ self::$Style = Style::GetInstance();
+ self::$Template = new Template(DIR_ROOT.DIR_TPL, DIR_ROOT.self::Style()->Info('TPL'), SBB::Config('config.system.cache.dir'));
+ self::$User = new User();
+ PostListener::Check();
self::$Menu = Menu::GetInstance();
// Template assignment
@@ -38,6 +47,14 @@ class SBB {
// Display the template
self::Template()->Display('case.tpl');
}
+
+ /**
+ * Returns the user object
+ * @return User
+ */
+ public static final function User() {
+ return self::$User;
+ }
/**
* Returns the config value
@@ -65,8 +82,6 @@ class SBB {
* @return Template
*/
public static final function Template() {
- if(!self::$Template)
- self::$Template = new Template(DIR_ROOT.DIR_TPL, DIR_ROOT.self::Style()->Info('TPL'), SBB::Config('config.system.cache.dir'));
return self::$Template;
}
View
@@ -0,0 +1,116 @@
+<?php
+/**
+ * @author SilexBB
+ * @copyright 2011 - 2012 Silex Bulletin Board
+ * @license GPL version 3 or higher <http://www.gnu.org/licenses/gpl-3.0.html>
+ */
+
+class User {
+ protected $Name, $ID, $LoggedIn;
+ protected $Info = array();
+ protected $Permission = array();
+
+ public function __construct() {
+ if(Session::Get('UserID')) { // User seems to be logged in
+ $Result = SBB::DB()->Table('users')->Select('*')->Where('`ID` = '.Session::Get('UserID'))->Execute();
+ if(!$Result) {
+ // Do Logout
+ Session::Remove('UserID');
+ Session::Destroy();
+ $this->__construct();
+ } else { // User is logged in
+ $UserInfo = SBB::DB()->FetchObjects();
+ $this->Name = $UserInfo->Username;
+ $this->ID = $UserInfo->ID;
+ $this->LoggedIn = true;
+ }
+ } else { // Not logged in
+ $this->Name = Language::Get('com.sbb.user.guest');
+ $this->ID = 0;
+ $this->LoggedIn = false;
+ }
+ SBB::Template()->Set(array('User' => array('ID' => $this->ID, 'Name' => $this->Name)));
+ }
+
+ /* User info */
+
+ /**
+ * Return the user name or set it
+ */
+ public function Name($Name = '') {
+ if(empty($Name))
+ return $this->Name;
+ // TODO: Set the name
+ }
+
+ /**
+ * Returns the user id of the current user
+ * @return int
+ */
+ public function ID() {
+ return $this->ID;
+ }
+
+ /**
+ * Get the user permission
+ * @param string $Node
+ * @return mixed
+ */
+ public function Permission($Node) {
+ return isset($this->Permission[$Node]) ? $this->Permission[$Node] : null;
+ }
+
+ /**
+ * Return if the user is logged in
+ * @return bool
+ */
+ public function LoggedIn() {
+ return $this->LoggedIn;
+ }
+
+ /**
+ * Return additional info
+ * @param string $Info
+ * @return mixed
+ */
+ public function Info($Info) {
+ return isset($this->Info[$Info]) ? $this->Info[$Info] : null;
+ }
+
+ /* User actions */
+
+ /**
+ * Login the current user
+ * @param string $Username
+ * @param string $Password
+ * @param bool $Stay
+ */
+ public function Login($Username, $Password, $Stay) {
+ $Username = EscapeString($Username);
+ $Password = EscapeString($Password);
+ if(SBB::DB()->Table('users')->Exists()->Where('`Username` = \''.$Username.'\'')->Execute()) {
+ echo 'Existiert';
+ } else {
+ Session::Set('LoginError', Language::Get('com.sbb.login.no_user')); // BUG: Sessionvalue is NULL?
+ header('location: ?page=Login');
+ }
+ }
+
+ public function Logout() {
+ // Logout the user
+ }
+
+ public function Register() {
+ // Register a new user
+ }
+
+ /* All user info */
+ public static function GetName($ID) {
+ // Get the user name
+ }
+
+ public static function GetID($Name) {
+ // Get the user ID
+ }
+}
+?>
@@ -170,7 +170,12 @@ public function Execute($GetResult = false) {
$this->Database->multi_query($Query);
$this->Result = 'MULTIQUERY';
} else { // Singlequery
- $Query = SQL::Make($this->QueryList[0], $this, false); // Do not use prepared statements
+ $Query = '';
+ if(isset($this->QueryList[0]))
+ $Query = SQL::Make($this->QueryList[0], $this, false); // Do not use prepared statements
+ else
+ throw new DatabaseException('Error while parsing the query');
+
// Send
$this->Result = $this->Database->query($Query);
@@ -31,7 +31,7 @@ public static function Destroy() {
* Reads the content of a session, if the key is empty, false will return
* Alias for $_SESSION[$Key];
*/
- public static function Read($Key) {
+ public static function Get($Key) {
return(isset($_SESSION[$Key]) ? $_SESSION[$Key] : false);
}
@@ -41,7 +41,7 @@ public static function Read($Key) {
* It will return true if succeeded else false
*/
public static function Set($Key, $Value) {
- return (bool)($_SESSION[$Key] = $Value);
+ return $_SESSION[$Key] = $Value;
}
/**
@@ -62,7 +62,7 @@ public function write($SessionID, $Data) {
'ID' => EscapeString($SessionID),
'SessionValue' => EscapeString($Data),
'UserID' => (int)(isset($_SESSION['UserID']) ? $_SESSION['UserID'] : 0),
- 'Username' => '', // TODO: read Username from User class?
+ 'Username' => SBB::User()->Name(),
'IPAddress' => (string)$_SERVER['REMOTE_ADDR'],
'UserAgent' => EscapeString($_SERVER['HTTP_USER_AGENT']),
'LastActivityTime' => time(),
@@ -0,0 +1,27 @@
+<?php
+/**
+ * @author SilexBB
+ * @copyright 2011 - 2012 Silex Bulletin Board
+ * @license GPL version 3 or higher <http://www.gnu.org/licenses/gpl-3.0.html>
+ */
+
+class PostListener {
+ // Listen to forms and trigger actions
+ public static function Check() {
+ // Any POSTs are send?
+ if(isset($_POST)) {
+ // Login
+ if(isset($_POST['Login']) && isset($_POST['Register'])) {
+ if($_POST['Register'] == 1) {
+ // Redirect to register page
+ header('location: ?page=Register');
+ } else if($_POST['Register'] == 0 && isset($_POST['Username']) && isset($_POST['Password'])) {
+ SBB::User()->Login($_POST['Username'], $_POST['Password'], !empty($_POST['StayLoggedIn']) ? true : false);
+ } else {
+ throw new SystemException('The loginform don\'t match');
+ }
+ }
+ }
+ }
+}
+?>
View
@@ -0,0 +1,17 @@
+<?php
+/**
+ * @author SilexBB
+ * @copyright 2011 - 2012 Silex Bulletin Board
+ * @license GPL version 3 or higher <http://www.gnu.org/licenses/gpl-3.0.html>
+ */
+
+class Secure {
+ public static function EncryptPassword($Password, $Salt) {
+ return sha1($Salt.md5($Salt.sha1($Password.md5($Salt))));
+ }
+
+ public static function EncryptSalt() {
+ return sha1(md5(base64_encode(microtime())));
+ }
+}
+?>
File renamed without changes.
@@ -14,6 +14,7 @@ public function __construct() {
$this->Info['node'] = self::$Node;
$this->Info['title'] = Language::Get('com.sbb.page.forum');
Breadcrumb::Add(Language::Get('com.sbb.page.forum'), self::$Link);
+ // TODO: Subboards etc.
$this->Info['template'] = 'Board';
SBB::Template()->Set(array('Boards' => SBB::DB()->Table('board')->Select()->Execute()->FetchObjects()));
}
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @author SilexBB
+ * @copyright 2011 - 2012 Silex Bulletin Board
+ * @license GPL version 3 or higher <http://www.gnu.org/licenses/gpl-3.0.html>
+ */
+
+class LoginPage extends Page implements PageData {
+ protected static $Link = '?page=Login';
+ protected static $Node = 'page.login';
+ protected $Info = array();
+
+ public function __construct() {
+ $this->Info['node'] = self::$Node;
+ $this->Info['title'] = Language::Get('com.sbb.page.login');
+ $this->Info['template'] = 'Login';
+
+ if(Session::Get('LoginError')) {
+ // TODO: Errormessage (Messagebox)
+ // echo 'LoginError: '.Session::Get('LoginError');
+ Session::Remove('LoginError');
+ }
+ }
+
+ public function GetInfo($Info) {
+ return isset($this->Info[$Info]) ? $this->Info[$Info] : false;
+ }
+
+ protected function GetWholeInfo() {
+ return $this->Info;
+ }
+
+ public static function Link() {
+ return self::$Link;
+ }
+
+ public static function Node() {
+ return self::$Node;
+ }
+}
+?>
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @author SilexBB
+ * @copyright 2011 - 2012 Silex Bulletin Board
+ * @license GPL version 3 or higher <http://www.gnu.org/licenses/gpl-3.0.html>
+ */
+
+class RegisterPage extends Page implements PageData {
+ protected static $Link = '?page=Register';
+ protected static $Node = 'page.register';
+ protected $Info = array();
+
+ public function __construct() {
+ $this->Info['node'] = self::$Node;
+ $this->Info['title'] = Language::Get('com.sbb.page.register');
+ $this->Info['template'] = 'Register';
+ }
+
+ public function GetInfo($Info) {
+ return isset($this->Info[$Info]) ? $this->Info[$Info] : false;
+ }
+
+ protected function GetWholeInfo() {
+ return $this->Info;
+ }
+
+ public static function Link() {
+ return self::$Link;
+ }
+
+ public static function Node() {
+ return self::$Node;
+ }
+}
+?>
Oops, something went wrong.

0 comments on commit f3d7514

Please sign in to comment.