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 5 years ago
parent
commit
db4483d1f3
  1. 2
      src/Component/Nginx/Stats.php
  2. 5
      src/Controller/Events.php
  3. 16
      src/Controller/Register.php
  4. 6
      src/Controller/Streams.php

2
src/Component/Nginx/Stats.php

@ -42,4 +42,4 @@ class Stats @@ -42,4 +42,4 @@ class Stats
return [];
}
}
}

5
src/Controller/Events.php

@ -8,6 +8,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; @@ -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 @@ -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 @@ -108,4 +109,4 @@ class Events extends Controller
return $stream;
}
}
}

16
src/Controller/Register.php

@ -55,6 +55,10 @@ class Register extends Controller @@ -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 @@ -89,4 +93,14 @@ class Register extends Controller
{
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);
}
}

6
src/Controller/Streams.php

@ -97,7 +97,7 @@ class Streams extends Controller @@ -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 @@ -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);
}
}
}

Loading…
Cancel
Save