This commit is contained in:
Colin FRIZOT
2022-11-30 11:43:29 +01:00
14 changed files with 145 additions and 34 deletions

View File

@@ -6,6 +6,7 @@ namespace Silex\Controller;
use Silex\DI\DI;
use Silex\Http\HttpResponse;
use Silex\Model\User;
class SecurityController
{
@@ -19,9 +20,23 @@ class SecurityController
header('Location: ' . $di->getRouter()->url(''));
exit();
}
var_dump($success);
$fail = !$success;
}
return HttpResponse::found('login', ['fail' => $fail]);
}
}
public function register(DI $di): HttpResponse
{
$fail = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$user = $di->getSecurity()->register(User::fromRawPassword($_POST['login'], $_POST['password']));
if ($user !== null) {
http_response_code(303);
header('Location: ' . $di->getRouter()->url(''));
exit();
}
$fail = $user === null;
}
return HttpResponse::found('register', ['fail' => $fail]);
}
}

View File

@@ -28,7 +28,7 @@ class UserController
} else {
$nbCommentsByUser = 0;
}
return new HttpResponse(200, 'home', ['news' => $news, 'page' => $page, 'nbPages' => $nbPages, 'router' => $di->getRouter(), 'nbComments' => $nbComments, 'nbCommentsByUser' => $nbCommentsByUser]);
return new HttpResponse(200, 'home', ['news' => $news, 'page' => $page, 'nbPages' => $nbPages, 'nbComments' => $nbComments, 'nbCommentsByUser' => $nbCommentsByUser]);
}
public function viewPost(DI $di, array $params): HttpResponse