Further work on session
This commit is contained in:
parent
173dae0381
commit
74ef36fdd6
@ -8,9 +8,6 @@
|
|||||||
//
|
//
|
||||||
// * GET requests have to support ranges
|
// * 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
|
// 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;
|
namespace OCA\Office;
|
||||||
|
|
||||||
|
17
ajax/session.php
Normal file
17
ajax/session.php
Normal file
@ -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();
|
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 (?, ?, ?, ?) ');
|
$query = \OCP\DB::prepare('INSERT INTO `*PREFIX*office_session` (`es_id`, `genesis_url`, `genesis_hash`, `owner`) VALUES (?, ?, ?, ?) ');
|
||||||
$result = $query->execute(array(
|
|
||||||
'dev0',
|
$data = array(
|
||||||
'/welcome.odt',
|
self::getSessionId(),
|
||||||
'0xdeadbeef',
|
$genesis,
|
||||||
|
self::getHash($genesis),
|
||||||
\OCP\User::getUser()
|
\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…
x
Reference in New Issue
Block a user