2020-06-04 09:52:49 +02:00
|
|
|
<?php
|
2020-06-19 09:28:58 +02:00
|
|
|
|
2020-06-04 09:52:49 +02:00
|
|
|
namespace OCA\BigBlueButton\Middleware;
|
|
|
|
|
|
|
|
use OCA\BigBlueButton\Controller\JoinController;
|
2020-06-16 16:54:50 +02:00
|
|
|
use OCA\BigBlueButton\NoPermissionException;
|
|
|
|
use OCA\BigBlueButton\NoPermissionResponse;
|
2020-06-04 09:52:49 +02:00
|
|
|
use OCA\BigBlueButton\NotFoundException;
|
|
|
|
use OCP\AppFramework\Middleware;
|
|
|
|
use OCP\AppFramework\Http\NotFoundResponse;
|
|
|
|
use OCP\IRequest;
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
class JoinMiddleware extends Middleware {
|
2020-06-04 09:52:49 +02:00
|
|
|
/** @var IRequest */
|
|
|
|
private $request;
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function __construct(IRequest $request) {
|
2020-06-04 09:52:49 +02:00
|
|
|
$this->request = $request;
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function beforeController($controller, $methodName) {
|
2020-06-04 09:52:49 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function afterException($controller, $methodName, \Exception $exception) {
|
2020-06-04 09:52:49 +02:00
|
|
|
if (!($controller instanceof JoinController)) {
|
|
|
|
throw $exception;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($exception instanceof NotFoundException) {
|
|
|
|
return new NotFoundResponse();
|
|
|
|
}
|
|
|
|
|
2020-06-16 16:54:50 +02:00
|
|
|
if ($exception instanceof NoPermissionException) {
|
|
|
|
return new NoPermissionResponse();
|
|
|
|
}
|
|
|
|
|
2020-06-04 09:52:49 +02:00
|
|
|
throw $exception;
|
|
|
|
}
|
|
|
|
}
|