Ajout page d'authentification

This commit is contained in:
2020-02-19 12:21:04 +01:00
parent 72e328ea1c
commit 3aa8ab987b
9 changed files with 203 additions and 14 deletions

View File

@ -2,6 +2,7 @@
namespace App\Controller;
use App\Http\DataResponse;
use App\Http\ErrorResponse;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
@ -12,10 +13,19 @@ class SecurityController extends Controller
/**
* @Route("/api/v1/login", name="api_v1_login", methods={"POST"})
*/
public function login(Request $request)
public function login()
{
$user = $this->getUser();
if ($user == null) {
return new ErrorResponse(
0,
"Identifiants invalides",
null,
401,
);
}
return new DataResponse([
'username' => $user->getUsername(),
'roles' => $user->getRoles(),