2020-04-26 11:36:41 +02:00
|
|
|
<?php
|
|
|
|
namespace OCA\BigBlueButton\Controller;
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
use OCA\BigBlueButton\BigBlueButton\API;
|
|
|
|
use OCA\BigBlueButton\BigBlueButton\Presentation;
|
2020-06-04 09:52:49 +02:00
|
|
|
use OCA\BigBlueButton\NotFoundException;
|
2020-04-26 11:36:41 +02:00
|
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\ISession;
|
|
|
|
use OCP\IUserSession;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCA\BigBlueButton\Service\RoomService;
|
2020-06-04 09:52:49 +02:00
|
|
|
use OCP\AppFramework\Controller;
|
2020-04-26 11:36:41 +02:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
|
2020-06-04 09:52:49 +02:00
|
|
|
class JoinController extends Controller
|
2020-04-26 11:36:41 +02:00
|
|
|
{
|
2020-06-04 09:52:49 +02:00
|
|
|
/** @var string */
|
|
|
|
protected $token;
|
|
|
|
|
2020-04-26 12:14:06 +02:00
|
|
|
/** @var RoomService */
|
|
|
|
private $service;
|
|
|
|
|
|
|
|
/** @var IUserSession */
|
|
|
|
private $userSession;
|
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
/** @var API */
|
|
|
|
private $api;
|
2020-04-26 12:14:06 +02:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
string $appName,
|
|
|
|
IRequest $request,
|
|
|
|
ISession $session,
|
|
|
|
RoomService $service,
|
|
|
|
IUserSession $userSession,
|
|
|
|
IConfig $config,
|
2020-05-16 17:14:17 +02:00
|
|
|
API $api
|
2020-04-26 12:14:06 +02:00
|
|
|
) {
|
|
|
|
parent::__construct($appName, $request, $session);
|
|
|
|
|
|
|
|
$this->service = $service;
|
|
|
|
$this->userSession = $userSession;
|
|
|
|
$this->config = $config;
|
2020-05-16 17:14:17 +02:00
|
|
|
$this->api = $api;
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
2020-06-04 09:52:49 +02:00
|
|
|
public function setToken(string $token)
|
2020-04-26 12:14:06 +02:00
|
|
|
{
|
2020-06-04 09:52:49 +02:00
|
|
|
$this->token = $token;
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isValidToken(): bool
|
|
|
|
{
|
2020-06-04 09:52:49 +02:00
|
|
|
$room = $this->service->findByUid($this->token);
|
2020-04-26 12:14:06 +02:00
|
|
|
|
|
|
|
return $room !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
2020-05-16 17:14:17 +02:00
|
|
|
public function index($displayname, $u = '', $filename = '')
|
2020-04-26 12:14:06 +02:00
|
|
|
{
|
2020-06-04 09:52:49 +02:00
|
|
|
$room = $this->service->findByUid($this->token);
|
2020-04-26 12:14:06 +02:00
|
|
|
|
|
|
|
if ($room === null) {
|
2020-05-16 17:14:17 +02:00
|
|
|
throw new NotFoundException();
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
$userId = null;
|
|
|
|
$presentation = null;
|
2020-04-26 12:14:06 +02:00
|
|
|
|
|
|
|
if ($this->userSession->isLoggedIn()) {
|
|
|
|
$user = $this->userSession->getUser();
|
|
|
|
$displayname = $user->getDisplayName();
|
2020-05-16 17:14:17 +02:00
|
|
|
$userId = $user->getUID();
|
|
|
|
|
|
|
|
if ($userId === $room->userId) {
|
|
|
|
$presentation = new Presentation($u, $filename);
|
|
|
|
}
|
2020-04-26 12:14:06 +02:00
|
|
|
} elseif (empty($displayname) || strlen($displayname) < 3) {
|
|
|
|
$response = new TemplateResponse($this->appName, 'publicdisplayname', [
|
2020-04-28 14:34:30 +02:00
|
|
|
'room' => $room->name,
|
2020-04-26 12:14:06 +02:00
|
|
|
'wrongdisplayname' => !empty($displayname) && strlen($displayname) < 3
|
|
|
|
], 'guest');
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
$this->addFormActionDomain($response);
|
2020-04-26 12:14:06 +02:00
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
$creationDate = $this->api->createMeeting($room, $presentation);
|
|
|
|
$joinUrl = $this->api->createJoinUrl($room, $creationDate, $displayname, $userId);
|
|
|
|
|
|
|
|
return new RedirectResponse($joinUrl);
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
private function addFormActionDomain($response)
|
2020-04-26 12:14:06 +02:00
|
|
|
{
|
|
|
|
$apiUrl = $this->config->getAppValue($this->appName, 'api.url');
|
2020-05-16 17:14:17 +02:00
|
|
|
$parsedApiUrl = parse_url($apiUrl);
|
2020-04-26 12:14:06 +02:00
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
if ($parsedApiUrl === false) {
|
|
|
|
throw new \Exception('No valid api url provided');
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 17:14:17 +02:00
|
|
|
$response->getContentSecurityPolicy()->addAllowedFormActionDomain(($parsedApiUrl['scheme'] ?: 'https') . '://' . $parsedApiUrl['host']);
|
2020-04-26 12:14:06 +02:00
|
|
|
}
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|