|
|
@ -26,37 +26,37 @@ class AuthController {
|
|
|
|
return ViewHttpResponse::twig("display_register.html.twig", []);
|
|
|
|
return ViewHttpResponse::twig("display_register.html.twig", []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function displayRegisterBadFields(array $fails): HttpResponse{
|
|
|
|
private function displayBadFields(string $viewName, array $fails): HttpResponse{
|
|
|
|
$bad_fields = [];
|
|
|
|
$bad_fields = [];
|
|
|
|
foreach ($fails as $err) {
|
|
|
|
foreach ($fails as $err) {
|
|
|
|
if ($err instanceof FieldValidationFail) {
|
|
|
|
if ($err instanceof FieldValidationFail) {
|
|
|
|
$bad_fields[] = $err->getFieldName();
|
|
|
|
$bad_fields[] = $err->getFieldName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ViewHttpResponse::twig("display_register.html.twig", ['bad_fields' => $bad_fields]);
|
|
|
|
return ViewHttpResponse::twig($viewName, ['bad_fields' => $bad_fields]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function confirmRegister(array $request): HttpResponse {
|
|
|
|
public function confirmRegister(array $request): HttpResponse {
|
|
|
|
|
|
|
|
|
|
|
|
$fails = [];
|
|
|
|
$fails = [];
|
|
|
|
$request = HttpRequest::from($request, $fails, [
|
|
|
|
$request = HttpRequest::from($request, $fails, [
|
|
|
|
"username" => [Validators::name(), Validators::lenBetween(0, 32)],
|
|
|
|
"username" => [Validators::name(), Validators::lenBetween(2, 32)],
|
|
|
|
"password" => [Validators::lenBetween(6, 256)],
|
|
|
|
"password" => [Validators::lenBetween(6, 256)],
|
|
|
|
"confirmpassword" => [Validators::lenBetween(6, 256)],
|
|
|
|
"confirmpassword" => [Validators::lenBetween(6, 256)],
|
|
|
|
"email" => [Validators::regex("/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g"),Validators::lenBetween(5, 256)]
|
|
|
|
"email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"),Validators::lenBetween(5, 256)]
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($fails)) {
|
|
|
|
if (!empty($fails)) {
|
|
|
|
return $this->displayRegisterBadFields($fails);
|
|
|
|
return $this->displayBadFields("display_register.html.twig",$fails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$fails = $this->model->validationRegister($request['username'], $request["password"], $request['confirmpassword'], $request['email']);
|
|
|
|
$fails = $this->model->register($request['username'], $request["password"], $request['confirmpassword'], $request['email']);
|
|
|
|
if (empty($fails)) {
|
|
|
|
if (empty($fails)) {
|
|
|
|
$results = $this->model->getUserFields($request['email']);
|
|
|
|
$results = $this->model->getUserFields($request['email']);
|
|
|
|
return ViewHttpResponse::twig("display_auth_confirm.html.twig", ['username' => $results['username'], 'email' => $results['email']]);
|
|
|
|
return ViewHttpResponse::twig("display_auth_confirm.html.twig", ['username' => $results['username'], 'email' => $results['email']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->displayRegisterBadFields($fails);
|
|
|
|
return $this->displayBadFields("display_register.html.twig",$fails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function displayLogin():HttpResponse{
|
|
|
|
public function displayLogin():HttpResponse{
|
|
|
@ -66,18 +66,18 @@ class AuthController {
|
|
|
|
public function displayLoginPassed(array $request):HttpResponse{
|
|
|
|
public function displayLoginPassed(array $request):HttpResponse{
|
|
|
|
$fails = [];
|
|
|
|
$fails = [];
|
|
|
|
$request = HttpRequest::from($request, $fails, [
|
|
|
|
$request = HttpRequest::from($request, $fails, [
|
|
|
|
"password" => [Validators::lenBetween(0, 256)],
|
|
|
|
"password" => [Validators::lenBetween(6, 256)],
|
|
|
|
"email" => [Validators::regex("/@/")]
|
|
|
|
"email" => [Validators::regex("/^\\S+@\\S+\\.\\S+$/"),Validators::lenBetween(5, 256)]
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fails = $this->model->validationLogin($request['email'],$request['password']);
|
|
|
|
$fails = $this->model->login($request['email'],$request['password']);
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($fails)){
|
|
|
|
if (empty($fails)){
|
|
|
|
$results = $this->model->getUserFields($request['email']);
|
|
|
|
$results = $this->model->getUserFields($request['email']);
|
|
|
|
return ViewHttpResponse::twig("display_auth_confirm.html.twig",['username' => $results['username'], 'email' => $results['email']]);
|
|
|
|
return ViewHttpResponse::twig("display_auth_confirm.html.twig",['username' => $results['username'], 'email' => $results['email']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->displayRegisterBadFields($fails);
|
|
|
|
return $this->displayBadFields("display_login.html.twig",$fails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|