diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index 9118bb24..8a0ae19e 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -124,15 +124,24 @@ var odfViewer = { $('#app-content #controls').addClass('hidden'); $('#app-content').append($iframe); - $.ajax({type: 'GET', url: OC.filePath('richdocuments', 'ajax', 'generate.php'), data: {id: context.$file.attr('data-id')}, async: false, success: function(result) { - if(result.status=="success"){ - var $chatroom = $(''); - $('#app-content').append($chatroom); + $.ajax({type: 'GET', + url: OC.filePath('richdocuments', 'ajax', 'generate.php'), + data: {id: context.$file.attr('data-id')}, + async: false, success: function(result) { + if(result.status=="success"){ + var $chatroom = $('
'); + $chatroom.attr('id','chatroom'); + $chatroom.data('chatroom-password',result.password); + $chatroom.data('chatroom-name',result.name); + $chatroom.data('chatroom-title',fileName); + $('#app-content').append($chatroom); + } else { + console.log(result.message); + } + }, error: function(xhr, textStatus, errorThrown){ + console.log(errorThrown); } - - }, error: function(xhr, textStatus, errorThrown){ - password=errorThrown; - }}); + }); }, diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index 3b4589a7..01df7a0d 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -256,35 +256,33 @@ class DocumentController extends Controller { * @NoAdminRequired */ public function generate($id) { - if((!empty($id))) { - $view = \OC\Files\Filesystem::getView(); - try { - $path = $view->getPath($id); - if ($view->is_file($path) && $view->isReadable($path)) { - $secret = \OC::$server->getConfig()->getSystemValue("secret"); - $instanceID = \OC::$server->getConfig()->getSystemValue("instanceid"); - $chatRoomPassword = hash('sha512', "chatroom-password".$instanceID.$secret.$id); - $chatRoomName = hash('sha512', "chatroom-name".$instanceID.$secret.$id); - return array( - 'status' => 'success','password' => $chatRoomPassword,'name' => $chatRoomName - ); - } else { - return array( - 'status' => 'unauthorised' - ); - } - } catch (\Exception $e) { + if (empty($id)) { + return array( + 'status' => 'error', + 'message' => 'no id received'); + } + $view = \OC\Files\Filesystem::getView(); + try { + $path = $view->getPath($id); + if ($view->is_file($path) && $view->isReadable($path)) { + $secret = \OC::$server->getConfig()->getSystemValue('secret'); + $instanceID = \OC::$server->getConfig()->getSystemValue('instanceid'); + $chatRoomPassword = hash('sha512', 'chatroom-password'.$instanceID.$secret.$id); + $chatRoomName = hash('sha512','chatroom-name'.$instanceID.$secret.$id); + return array( + 'status' => 'success', + 'password' => $chatRoomPassword, + 'name' => $chatRoomName); + } else { return array( - 'status' => 'unauthorised' - ); + 'status' => 'error', + 'message' => 'user unauthorised to view file'); } - + } catch (\Exception $e) { + return array( + 'status' => 'error', + 'message' => 'user unauthorised to view file'); } - return array( - 'status' => 'no id received' - ); - } - }