Browse Source

Few updates:

limit usable chars in username at register
update stream name regex
make redirect on publish to user/stream/live instead leaving it with hash (makes possible to share direct stream link)
master
R4SAS 6 years ago
parent
commit
db4483d1f3
  1. 3
      src/Controller/Events.php
  2. 14
      src/Controller/Register.php
  3. 4
      src/Controller/Streams.php

3
src/Controller/Events.php

@ -8,6 +8,7 @@ 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;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
/** /**
* Class Events * Class Events
@ -53,7 +54,7 @@ class Events extends Controller
$manager->persist($stream); $manager->persist($stream);
$manager->flush(); $manager->flush();
return new Response(); return new RedirectResponse('live');
} }
return new Response('', 401); return new Response('', 401);

14
src/Controller/Register.php

@ -55,6 +55,10 @@ class Register extends Controller
$data = $request->request->all(); $data = $request->request->all();
if (empty($data['username']) || !$this->isValidString($data['username'])) {
return new JsonResponse(['message' => 'Name is empty or contains illegal chars. Please use A-Z, a-z, 0-9, .-_'], 500);
}
if ($this->repository->findOneBy(['username' => $data['username']])) { if ($this->repository->findOneBy(['username' => $data['username']])) {
return new JsonResponse(['message' => 'Username is already taken'], 500); return new JsonResponse(['message' => 'Username is already taken'], 500);
} }
@ -89,4 +93,14 @@ class Register extends Controller
{ {
return XmlUtils::phpize($this->container->getParameter('registrationEnabled')); return XmlUtils::phpize($this->container->getParameter('registrationEnabled'));
} }
/**
* @param null|string $string
* @return false|int
* @author Soner Sayakci <shyim@posteo.de>
*/
private function isValidString(?string $string)
{
return preg_match('/^[A-Z|a-z|0-9|.|\-|_]+$/m', $string);
}
} }

4
src/Controller/Streams.php

@ -97,7 +97,7 @@ class Streams extends Controller
} }
if (empty($requestBody['name']) || !$this->isValidString($requestBody['name'])) { if (empty($requestBody['name']) || !$this->isValidString($requestBody['name'])) {
return new JsonResponse(['message' => 'Name is empty or contains illegal strings'], 500); return new JsonResponse(['message' => 'Name is empty or contains illegal chars'], 500);
} }
$stream->setUser($this->getUser()); $stream->setUser($this->getUser());
@ -317,6 +317,6 @@ class Streams extends Controller
*/ */
private function isValidString(?string $string) private function isValidString(?string $string)
{ {
return preg_match('/^[a-z|A-Z|a-z|A-Z|0-9|.|\-|_|\{|\}|\:|\/|=|&|?]+$/m', $string); return preg_match('/^[A-Z|a-z|0-9|.|\-|_|\{|\}|\:|\/|=|&|?]+$/m', $string);
} }
} }
Loading…
Cancel
Save