|
|
|
@ -8,10 +8,10 @@ use App\Http\HttpResponse;
|
|
|
|
|
use App\Http\ViewHttpResponse;
|
|
|
|
|
use App\Model\AuthModel;
|
|
|
|
|
use App\Validation\FieldValidationFail;
|
|
|
|
|
use App\Validation\ValidationFail;
|
|
|
|
|
use App\Validation\Validators;
|
|
|
|
|
use Twig\Environment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AuthController {
|
|
|
|
|
private AuthModel $model;
|
|
|
|
|
|
|
|
|
@ -26,6 +26,11 @@ class AuthController {
|
|
|
|
|
return ViewHttpResponse::twig("display_register.html.twig", []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $viewName
|
|
|
|
|
* @param ValidationFail[] $fails
|
|
|
|
|
* @return HttpResponse
|
|
|
|
|
*/
|
|
|
|
|
private function displayBadFields(string $viewName, array $fails): HttpResponse {
|
|
|
|
|
$bad_fields = [];
|
|
|
|
|
foreach ($fails as $err) {
|
|
|
|
@ -36,14 +41,17 @@ class AuthController {
|
|
|
|
|
return ViewHttpResponse::twig($viewName, ['bad_fields' => $bad_fields]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param mixed[] $request
|
|
|
|
|
* @return HttpResponse
|
|
|
|
|
*/
|
|
|
|
|
public function confirmRegister(array $request): HttpResponse {
|
|
|
|
|
$fails = [];
|
|
|
|
|
$request = HttpRequest::from($request, $fails, [
|
|
|
|
|
"username" => [Validators::name(), Validators::lenBetween(2, 32)],
|
|
|
|
|
"password" => [Validators::lenBetween(6, 256)],
|
|
|
|
|
"confirmpassword" => [Validators::lenBetween(6, 256)],
|
|
|
|
|
"email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"),Validators::lenBetween(5, 256)]
|
|
|
|
|
"email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"),Validators::lenBetween(5, 256)],
|
|
|
|
|
]);
|
|
|
|
|
if (!empty($fails)) {
|
|
|
|
|
return $this->displayBadFields("display_register.html.twig", $fails);
|
|
|
|
@ -61,12 +69,15 @@ class AuthController {
|
|
|
|
|
return ViewHttpResponse::twig("display_login.html.twig", []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param mixed[] $request
|
|
|
|
|
* @return HttpResponse
|
|
|
|
|
*/
|
|
|
|
|
public function confirmLogin(array $request): HttpResponse {
|
|
|
|
|
$fails = [];
|
|
|
|
|
$request = HttpRequest::from($request, $fails, [
|
|
|
|
|
"password" => [Validators::lenBetween(6, 256)],
|
|
|
|
|
"email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"),Validators::lenBetween(5, 256)]
|
|
|
|
|
"email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"),Validators::lenBetween(5, 256)],
|
|
|
|
|
]);
|
|
|
|
|
if (!empty($fails)) {
|
|
|
|
|
return $this->displayBadFields("display_login.html.twig", $fails);
|
|
|
|
|