Browse Source

Check stream permission by streamName, userName and streamKey

master
Shyim 7 years ago
parent
commit
f83c344d14
  1. 12
      src/Controller/Events.php
  2. 29
      src/Repository/StreamsRepository.php

12
src/Controller/Events.php

@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\Streams; use App\Entity\Streams;
use App\Repository\StreamsRepository; use App\Repository\StreamsRepository;
use Doctrine\Common\Util\Debug;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -103,14 +104,9 @@ class Events extends Controller
*/ */
private function getStreamByRequest(array $data): ?Streams private function getStreamByRequest(array $data): ?Streams
{ {
$streamName = explode('/', $data['app'])[1]; [$username, $streamName] = explode('/', $data['app']);
$stream = $this->repository->getStreamByNameAndUsername($streamName, $username, $data['name']);
$stream = $this->repository->findOneBy(['name' => $streamName]); return $stream;
if ($stream !== null && $stream->getStreamKey() === $data['name']) {
return $stream;
}
return null;
} }
} }

29
src/Repository/StreamsRepository.php

@ -7,6 +7,7 @@ use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Bridge\Doctrine\RegistryInterface; use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Bundle\MakerBundle\Str;
/** /**
* @method Streams|null find($id, $lockMode = null, $lockVersion = null) * @method Streams|null find($id, $lockMode = null, $lockVersion = null)
@ -55,4 +56,32 @@ class StreamsRepository extends ServiceEntityRepository
return $qb->getResult(); return $qb->getResult();
} }
/**
* @param string $streamName
* @param string $userName
* @param string $streamKey
* @return Streams
* @author Soner Sayakci <shyim@posteo.de>
*/
public function getStreamByNameAndUsername(string $streamName, string $userName, string $streamKey): ?Streams
{
$qb = $this->createQueryBuilder('streams')
->addSelect('endpoints')
->addSelect('user')
->leftJoin('streams.endpoints', 'endpoints')
->innerJoin('streams.user', 'user')
->andWhere('streams.active = true')
->andWhere('endpoints.active = true')
->andWhere('streams.name = :streamName')
->andWhere('user.username = :userName')
->andWhere('streams.streamKey = :streamKey')
->setParameter('streamName', $streamName)
->setParameter('streamKey', $streamKey)
->setParameter('userName', $userName)
->getQuery();
$qb->setMaxResults(1);
return $qb->getResult()[0];
}
} }

Loading…
Cancel
Save