diff options
Diffstat (limited to 'bootstrap/class')
| -rw-r--r-- | bootstrap/class/cache.php | 69 | ||||
| -rw-r--r-- | bootstrap/class/user.php | 38 |
2 files changed, 87 insertions, 20 deletions
diff --git a/bootstrap/class/cache.php b/bootstrap/class/cache.php new file mode 100644 index 0000000..8005484 --- /dev/null +++ b/bootstrap/class/cache.php @@ -0,0 +1,69 @@ +<?php + +class cache { + public $token = ""; + + private $db; + + public function __construct($rconnect, $rdb){ + $this->db = new Redis(); + + try { + $this->db->connect($rconnect); + } catch (Exception $e) { + return $e->getMessage(); + } + try { + $this->db->ping(); + } catch (Exception $e) { + return $e->getMessage(); + } + try { + $this->db->select($rdb); + } catch (Exception $e) { + return $e->getMessage(); + } + } + + public function check(){ + try { + return $this->db->ping(); + } catch (Exception $e) { + return $e->getMessage(); + } + } + + public function setKey($key, $value, $ttl = null){ + $this->db->set($key, $value, $ttl); + } + + public function getValue($key){ + return $this->db->get($key); + } + + public function getToken($data, $append = ""){ + $this->token = CACHEPREFIX . $append . md5(strtolower($data)); + return $this->token; + } + + public function exists($key){ + return $this->db->exists($key); + } + + public function delete($key){ + return $this->db->delete($key); + } + + public function del($key){ + return $this->db->delete($key); + } + + public function flush($token = null){ + if ( is_null($token) ) + return $this->db->flushDB(); + else + return $this->db->delete($token); + } +} + + diff --git a/bootstrap/class/user.php b/bootstrap/class/user.php index edbcaa6..969d734 100644 --- a/bootstrap/class/user.php +++ b/bootstrap/class/user.php @@ -9,8 +9,6 @@ class jg { private $query = false; public function __construct($name = null){ - if ( is_null($name) ) - return; $this->username = $name; @@ -24,10 +22,10 @@ class jg { # get's everything from the database private function _setQuery(){ - global $vfsdb; + global $db; - $sql = $vfsdv->prepare("SELECT * FROM " . DBPREFIX . "user WHERE name=%s;", $this->username); - $db_db = $vfsdb->doQuery($sql); + $sql = $db->prepare("SELECT * FROM " . DBPREFIX . "user WHERE name=%s;", $this->username); + $db_db = $db->doQuery($sql); if ( is_bool($db_db) ) $this->query = false; else @@ -54,7 +52,10 @@ class jg { } public function getEmail(){ - return $this->query['email']; + if ( $this->query['email'] == "null" ) + return ""; + else + return $this->query['email']; } public function getRegister(){ @@ -88,9 +89,11 @@ class jg { # set login to true $this->login = true; + $this->username=$user; + # start a session if needed if ( session_status() != PHP_SESSION_ACTIVE ) { - session_name(VFS_SESSION); + session_name(SESSION); session_start(); } @@ -99,6 +102,7 @@ class jg { # assign userid to the session variable $_SESSION["userid"] = $this->getUserId(); + $_SESSION["username"] = $this->username; return true; } @@ -120,21 +124,15 @@ class jg { } public function register($name, $password, $email){ - global $vfsdb; + global $db; - $password = $password . PEPPER; - $hash = password_hash($password, PASSWORD_DEFAULT); + $hash = password_hash($password . PEPPER, PASSWORD_DEFAULT); - $sql = $vfsdb->prepare(" - INSERT INTO " . DBPREFIX . "user VALUES ( - NULL, - name = %s, - password = %s, - email = %s, - register = %d - );", $name, $hash, $email, time() ); + $sql = $db->prepare(" + INSERT INTO " . DBPREFIX . "user (id, name, password, email, register) VALUES (NULL, %s, %s, %s, %d);", $name, $hash, $email, time() + ); - if ( ! $vfsdb->doQuery($sql) ) + if ( ! $db->doQuery($sql) ) return false; # the user is successfull registered, thus already logged in @@ -144,7 +142,7 @@ class jg { $this->_setPepper(); $this->_setQuery(); - $this->login($password); + $this->login($name, $password); return true; } |
