From 74ef36fdd635a09a4d8dfb09e15907af657e5756 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Wed, 7 Aug 2013 02:22:21 +0300 Subject: [PATCH] Further work on session --- ajax/genesis.php | 3 --- ajax/session.php | 17 +++++++++++++++++ lib/session.php | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 ajax/session.php diff --git a/ajax/genesis.php b/ajax/genesis.php index 67690bf8..c2d33bee 100644 --- a/ajax/genesis.php +++ b/ajax/genesis.php @@ -8,9 +8,6 @@ // // * GET requests have to support ranges // curl --user admin:admin -r 500-1000 -i http://whatever/owncloud/index.php/apps/office/ajax/genesis.php/1234 -// -// hardcoding the served file with /welcome.odt for now is enough to unblock development -// (that saves all db work for now) namespace OCA\Office; diff --git a/ajax/session.php b/ajax/session.php new file mode 100644 index 00000000..4c55acbd --- /dev/null +++ b/ajax/session.php @@ -0,0 +1,17 @@ +fetchRow(); } - public function setMockSession(){ + public static function getSessionByUrl($url){ + $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ?'); + $result = $query->execute(array($url)); + return $result->fetchRow(); + } + + public static function addSession($genesis){ $query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_session` (`es_id`, `genesis_url`, `genesis_hash`, `owner`) VALUES (?, ?, ?, ?) '); - $result = $query->execute(array( - 'dev0', - '/welcome.odt', - '0xdeadbeef', + + $data = array( + self::getSessionId(), + $genesis, + self::getHash($genesis), \OCP\User::getUser() - )); + ); + $result = $query->execute($data); + + if ($result){ + return $data; + } + return false; + } + + public static function setMockSession(){ + self::addSession('/welcome.odt'); + } + protected static function getSessionId(){ + return substr(md5(time()), 1, 10); + } + + protected static function getHash($genesis){ + return '0xdeadbeef'; } }