fix: remove dependency on shares

fix #20
pull/63/head
sualko 2020-06-04 09:52:49 +02:00
parent 49bd4ca673
commit d744699f6b
4 changed files with 84 additions and 19 deletions

View File

@ -2,6 +2,21 @@
namespace OCA\BigBlueButton\AppInfo; namespace OCA\BigBlueButton\AppInfo;
use \OCP\AppFramework\App;
use \OCA\BigBlueButton\Middleware\JoinMiddleware;
if ((@include_once __DIR__ . '/../../vendor/autoload.php') === false) { if ((@include_once __DIR__ . '/../../vendor/autoload.php') === false) {
throw new \Exception('Cannot include autoload. Did you run install dependencies using composer?'); throw new \Exception('Cannot include autoload. Did you run install dependencies using composer?');
} }
class Application extends App
{
public function __construct(array $urlParams = [])
{
parent::__construct('bbb', $urlParams);
$container = $this->getContainer();
$container->registerMiddleWare(JoinMiddleware::class);
}
}

View File

@ -3,18 +3,21 @@ namespace OCA\BigBlueButton\Controller;
use OCA\BigBlueButton\BigBlueButton\API; use OCA\BigBlueButton\BigBlueButton\API;
use OCA\BigBlueButton\BigBlueButton\Presentation; use OCA\BigBlueButton\BigBlueButton\Presentation;
use OCA\BigBlueButton\NotFoundException;
use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\PublicShareController;
use OCP\IRequest; use OCP\IRequest;
use OCP\ISession; use OCP\ISession;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\IConfig; use OCP\IConfig;
use OCP\Files\NotFoundException;
use OCA\BigBlueButton\Service\RoomService; use OCA\BigBlueButton\Service\RoomService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
class JoinController extends PublicShareController class JoinController extends Controller
{ {
/** @var string */
protected $token;
/** @var RoomService */ /** @var RoomService */
private $service; private $service;
@ -44,37 +47,25 @@ class JoinController extends PublicShareController
$this->api = $api; $this->api = $api;
} }
protected function getPasswordHash(): string public function setToken(string $token)
{ {
return ''; $this->token = $token;
} }
/**
* Validate the token of this share. If the token is invalid this controller
* will return a 404.
*/
public function isValidToken(): bool public function isValidToken(): bool
{ {
$room = $this->service->findByUid($this->getToken()); $room = $this->service->findByUid($this->token);
return $room !== null; return $room !== null;
} }
/**
* Allows you to specify if this share is password protected
*/
protected function isPasswordProtected(): bool
{
return false;
}
/** /**
* @PublicPage * @PublicPage
* @NoCSRFRequired * @NoCSRFRequired
*/ */
public function index($displayname, $u = '', $filename = '') public function index($displayname, $u = '', $filename = '')
{ {
$room = $this->service->findByUid($this->getToken()); $room = $this->service->findByUid($this->token);
if ($room === null) { if ($room === null) {
throw new NotFoundException(); throw new NotFoundException();

View File

@ -0,0 +1,52 @@
<?php
namespace OCA\BigBlueButton\Middleware;
use OCA\BigBlueButton\Controller\JoinController;
use OCA\BigBlueButton\NotFoundException;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Http\NotFoundResponse;
use OCP\IRequest;
class JoinMiddleware extends Middleware
{
/** @var IRequest */
private $request;
public function __construct(IRequest $request)
{
$this->request = $request;
}
public function beforeController($controller, $methodName)
{
if (!($controller instanceof JoinController)) {
return;
}
$token = $this->request->getParam('token');
if ($token === null) {
throw new NotFoundException();
}
$controller->setToken($token);
if ($controller->isValidToken()) {
return;
}
throw new NotFoundException();
}
public function afterException($controller, $methodName, \Exception $exception)
{
if (!($controller instanceof JoinController)) {
throw $exception;
}
if ($exception instanceof NotFoundException) {
return new NotFoundResponse();
}
throw $exception;
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace OCA\BigBlueButton;
class NotFoundException extends \Exception
{
}