diff --git a/src/Component/Nginx/Stats.php b/src/Component/Nginx/Stats.php index f7f9aaa..583936b 100644 --- a/src/Component/Nginx/Stats.php +++ b/src/Component/Nginx/Stats.php @@ -42,4 +42,4 @@ class Stats return []; } -} \ No newline at end of file +} diff --git a/src/Controller/Events.php b/src/Controller/Events.php index 45c7221..752c72d 100644 --- a/src/Controller/Events.php +++ b/src/Controller/Events.php @@ -8,6 +8,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * Class Events @@ -53,7 +54,7 @@ class Events extends Controller $manager->persist($stream); $manager->flush(); - return new Response(); + return new RedirectResponse('live'); } return new Response('', 401); @@ -108,4 +109,4 @@ class Events extends Controller return $stream; } -} \ No newline at end of file +} diff --git a/src/Controller/Register.php b/src/Controller/Register.php index b1b7cba..d28c7e8 100644 --- a/src/Controller/Register.php +++ b/src/Controller/Register.php @@ -55,6 +55,10 @@ class Register extends Controller $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']])) { return new JsonResponse(['message' => 'Username is already taken'], 500); } @@ -89,4 +93,14 @@ class Register extends Controller { return XmlUtils::phpize($this->container->getParameter('registrationEnabled')); } -} \ No newline at end of file + + /** + * @param null|string $string + * @return false|int + * @author Soner Sayakci + */ + private function isValidString(?string $string) + { + return preg_match('/^[A-Z|a-z|0-9|.|\-|_]+$/m', $string); + } +} diff --git a/src/Controller/Streams.php b/src/Controller/Streams.php index 3a4ea47..6a3e197 100644 --- a/src/Controller/Streams.php +++ b/src/Controller/Streams.php @@ -97,7 +97,7 @@ class Streams extends Controller } 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()); @@ -317,6 +317,6 @@ class Streams extends Controller */ 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); } -} \ No newline at end of file +}