mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add /me endpoint
This commit is contained in:
@@ -2,19 +2,25 @@ api_platform:
|
|||||||
title: Domain Watchdog API
|
title: Domain Watchdog API
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
formats:
|
formats:
|
||||||
jsonld: ['application/ld+json']
|
jsonld: [ 'application/ld+json' ]
|
||||||
json: ['application/json']
|
json: [ 'application/json' ]
|
||||||
docs_formats:
|
docs_formats:
|
||||||
jsonld: ['application/ld+json']
|
jsonld: [ 'application/ld+json' ]
|
||||||
jsonopenapi: ['application/vnd.openapi+json']
|
jsonopenapi: [ 'application/vnd.openapi+json' ]
|
||||||
html: ['text/html']
|
html: [ 'text/html' ]
|
||||||
defaults:
|
defaults:
|
||||||
stateless: true
|
stateless: true
|
||||||
cache_headers:
|
cache_headers:
|
||||||
vary: ['Content-Type', 'Authorization', 'Origin']
|
vary: [ 'Content-Type', 'Authorization', 'Origin' ]
|
||||||
extra_properties:
|
extra_properties:
|
||||||
standard_put: true
|
standard_put: true
|
||||||
rfc_7807_compliant_errors: true
|
rfc_7807_compliant_errors: true
|
||||||
keep_legacy_inflector: false
|
keep_legacy_inflector: false
|
||||||
use_symfony_listeners: true
|
use_symfony_listeners: true
|
||||||
show_webby: false
|
show_webby: false
|
||||||
|
swagger:
|
||||||
|
api_keys:
|
||||||
|
JWT:
|
||||||
|
name: Authorization
|
||||||
|
type: header
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ security:
|
|||||||
pattern: ^/api/login
|
pattern: ^/api/login
|
||||||
stateless: true
|
stateless: true
|
||||||
json_login:
|
json_login:
|
||||||
check_path: /api/login
|
check_path: api_login
|
||||||
success_handler: lexik_jwt_authentication.handler.authentication_success
|
success_handler: lexik_jwt_authentication.handler.authentication_success
|
||||||
failure_handler: lexik_jwt_authentication.handler.authentication_failure
|
failure_handler: lexik_jwt_authentication.handler.authentication_failure
|
||||||
|
|
||||||
|
|||||||
23
src/Controller/MeController.php
Normal file
23
src/Controller/MeController.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
|
||||||
|
class MeController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly Security $security
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(): UserInterface
|
||||||
|
{
|
||||||
|
return $this->security->getUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use ApiPlatform\Metadata\ApiProperty;
|
||||||
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
|
use ApiPlatform\Metadata\Get;
|
||||||
|
use App\Controller\MeController;
|
||||||
use App\Repository\UserRepository;
|
use App\Repository\UserRepository;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
@@ -9,10 +13,22 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||||
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
|
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
|
||||||
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
|
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
|
||||||
|
#[ApiResource(
|
||||||
|
operations: [
|
||||||
|
new Get(
|
||||||
|
uriTemplate: '/me',
|
||||||
|
controller: MeController::class,
|
||||||
|
paginationEnabled: false,
|
||||||
|
normalizationContext: ["groups" => "user:list"],
|
||||||
|
read: false
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)]
|
||||||
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||||
{
|
{
|
||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
@@ -21,12 +37,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 180)]
|
#[ORM\Column(length: 180)]
|
||||||
|
#[Groups(['user:list'])]
|
||||||
private ?string $email = null;
|
private ?string $email = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array The user roles
|
* @var array The user roles
|
||||||
*/
|
*/
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
|
#[Groups(['user:list'])]
|
||||||
private array $roles = [];
|
private array $roles = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user