Permet l'inscription d'utilisateurs

This commit is contained in:
2022-11-30 11:21:48 +01:00
parent 1bce756470
commit d6a3a7938a
7 changed files with 81 additions and 5 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]);
}
}