Further work on session

pull/1/head
Victor Dubiniuk 11 years ago committed by Tobias Hintze
parent 173dae0381
commit 74ef36fdd6

@ -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;

@ -0,0 +1,17 @@
<?php
namespace OCA\Office;
// Check if we are a user
\OCP\User::checkLoggedIn();
$genesis = @$_POST['genesis'];
if ($genesis){
$session = Session::getSessionByUrl($genesis);
if (!$session){
$session = Session::addSession($genesis);
}
\OCP\JSON::success($session);
exit();
}
\OCP\JSON::error();

@ -9,13 +9,37 @@ class Session {
return $result->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';
}
}

Loading…
Cancel
Save