From eed75032e46dca52f68f62295755888fc05f7110 Mon Sep 17 00:00:00 2001 From: sundowndev Date: Thu, 12 Jul 2018 18:05:44 +0200 Subject: [PATCH] Session service --- server/src/Service/Session.php | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 server/src/Service/Session.php diff --git a/server/src/Service/Session.php b/server/src/Service/Session.php new file mode 100644 index 0000000..a3dceb8 --- /dev/null +++ b/server/src/Service/Session.php @@ -0,0 +1,51 @@ +db = new Database(); + } + + /** + * @param $user_id + * @param $csrf + * @param $cookie + */ + public function create($user_id, $csrf, $cookie) + { + $stmt = $this->db->getConnection()->prepare('INSERT INTO Session (user_id, csrf, cookie) VALUES(:user_id, :csrf, :cookie)'); + $stmt->bindParam(':user_id', $user_id, \PDO::PARAM_INT); + $stmt->bindParam(':title', $csrf, \PDO::PARAM_STR); + $stmt->bindParam(':description', $cookie, \PDO::PARAM_STR); + $stmt->execute(); + } + + /** + * @param $cookie + * @return mixed|null + */ + public function getSession($cookie) + { + $stmt = $this->db->getConnection()->prepare('SELECT * FROM Session WHERE cookie = :cookie'); + $stmt->bindParam(':cookie', $cookie); + $stmt->execute(); + + $session = $stmt->fetch(\PDO::FETCH_ASSOC); + + if (!$session) { + return null; + } else { + return $session; + } + } +} \ No newline at end of file