Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function api()
- {
- return new Response(sprintf('Logged in as %s', $this->getUser()->getUsername()));
- }
- security:
- encoders:
- AppEntityUser:
- algorithm: bcrypt
- # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
- providers:
- entity_provider:
- entity:
- class: AppEntityUser
- property: username
- firewalls:
- dev:
- pattern: ^/(_(profiler|wdt)|css|images|js)/
- security: false
- # main:
- # anonymous: true
- login:
- pattern: ^/login
- stateless: true
- anonymous: true
- json_login:
- check_path: /login_check
- success_handler: lexik_jwt_authentication.handler.authentication_success
- failure_handler: lexik_jwt_authentication.handler.authentication_failure
- register:
- pattern: ^/register
- stateless: true
- anonymous: true
- api:
- pattern: ^/api
- stateless: true
- anonymous: false
- provider: entity_provider
- guard:
- authenticators:
- - lexik_jwt_authentication.jwt_token_authenticator
- # activate different ways to authenticate
- # http_basic: true
- # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
- # form_login: true
- # https://symfony.com/doc/current/security/form_login_setup.html
- # Easy way to control access for large sections of your site
- # Note: Only the *first* access control that matches will be used
- access_control:
- - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
- register:
- path: /register
- controller: AppControllerAuthController::register
- methods: POST
- api:
- path: /api
- controller: AppControllerAuthController::api
- login_check:
- path: /login_check
- methods: [POST]
- <?php
- namespace AppEntity;
- use ApiPlatformCoreAnnotationApiFilter;
- use ApiPlatformCoreAnnotationApiProperty;
- use ApiPlatformCoreAnnotationApiSubresource;
- use DoctrineCommonCollectionsArrayCollection;
- use DoctrineCommonCollectionsCollection;
- use DoctrineORMMapping as ORM;
- use SymfonyComponentSecurityCoreUserUserInterface;
- use ApiPlatformCoreAnnotationApiResource;
- use SymfonyComponentSerializerAnnotationGroups;
- use ApiPlatformCoreBridgeDoctrineOrmFilterSearchFilter;
- /**
- * @ORMEntity(repositoryClass="AppRepositoryUserRepository")
- * @ApiResource(normalizationContext={"groups"={"user"}})
- * @ApiFilter(SearchFilter::class, properties={"centres.id": "exact"})
- */
- class User implements UserInterface
- {
- /**
- * @ORMId()
- * @ORMGeneratedValue()
- * @ORMColumn(type="integer")
- * @Groups({"user"})
- */
- private $id;
- /**
- * @ORMColumn(type="string", length=50, unique=true)
- * @Groups({"user"})
- */
- private $username;
- /**
- * @ORMColumn(type="string", length=64)
- * @Groups({"user"})
- */
- private $password;
- /**
- * @ORMColumn(type="string", length=50, nullable=true)
- * @Groups({"user"})
- */
- private $prenom;
- /**
- * @ORMColumn(type="string", length=50, nullable=true)
- * @Groups({"user"})
- */
- private $nom;
- /**
- * @ORMColumn(type="string", length=80, unique=true)
- * @Groups({"user"})
- */
- private $email;
- /**
- * @ORMColumn(type="array")
- * @Groups({"user"})
- */
- private $roles = [];
- /**
- * @ORMColumn(type="datetime", nullable=true)
- * @Groups({"user"})
- */
- private $dateNaissance;
- /**
- * @ORMColumn(type="datetime")
- * @Groups({"user"})
- */
- private $dateEnregistrement;
- /**
- * @ORMColumn(type="datetime", nullable=true)
- * @Groups({"user"})
- */
- private $dateDernierePartie;
- /**
- * @ORMColumn(type="boolean")
- * @Groups({"user"})
- */
- private $actif;
- /**
- * @ORMColumn(type="integer")
- * @Groups({"user"})
- */
- private $niveau;
- /**
- * @ORMColumn(type="integer")
- * @Groups({"user"})
- */
- private $experience;
- /**
- * @ORMColumn(type="integer")
- * @Groups({"user"})
- */
- private $nbVictimes;
- /**
- * @ORMColumn(type="integer")
- * @Groups({"user"})
- */
- private $nbMorts;
- /**
- * @ORMColumn(type="integer", nullable=true)
- * @Groups({"user"})
- */
- private $justesse;
- /**
- * @ORMColumn(type="integer", nullable=true)
- * @Groups({"user"})
- */
- private $nbParties;
- /**
- * @ORMOneToMany(targetEntity="AppEntityCarte", mappedBy="client")
- * @Groups({"user"})
- * @var Collection
- */
- private $cartes;
- /**
- * @ORMManyToOne(targetEntity="AppEntityEquipe", inversedBy="joueurs")
- * @ORMJoinColumn(nullable=true)
- * @Groups({"user"})
- */
- private $equipe;
- /**
- * @ORMManyToMany(targetEntity="AppEntityCentre", inversedBy="clients")
- * @ORMJoinTable(name="users_centres")
- * @var Collection
- * @Groups({"user"})
- */
- private $centres;
- public function __construct()
- {
- $this->cartes = new ArrayCollection();
- $this->centres = new ArrayCollection();
- $this->actif = true;
- $this->niveau = 1;
- $this->experience = 0;
- $this->nbVictimes = 0;
- $this->nbMorts = 0;
- $this->justesse = 0;
- $this->nbParties = 0;
- $this->dateEnregistrement = new DateTime();
- }
- /**
- * @param int|null $id
- * @param string $username
- * @param string $email
- * @param string $password
- * @param array $roles
- * @param DateTime|null $dateEnregistrement
- * @return User
- */
- static public function creer(
- ?int $id = null,
- string $username,
- string $email,
- string $password,
- array $roles,
- ?DateTime $dateEnregistrement = null
- )
- {
- $user = new self();
- $user->id = $id;
- $user->username = $username;
- $user->email = $email;
- $user->password = $password;
- $user->roles = $roles;
- $user->dateEnregistrement = $dateEnregistrement;
- return $user;
- }
- public function addCarte(Carte $carte)
- {
- if ($this->cartes->contains($carte)) {
- return;
- }
- $this->cartes->add($carte);
- $carte->setClient($this);
- }
- public function addCentre(Centre $centre)
- {
- if ($this->centres->contains($centre)) {
- return;
- }
- $this->centres->add($centre);
- //$centre->inscrireJoueur($this);
- }
- public function ajouterNbVictimes(int $nbVictimes)
- {
- $this->nbVictimes += $nbVictimes;
- }
- public function ajouterJustesse(int $justesse)
- {
- $this->justesse += $justesse;
- }
- public function diminuerJustesse(int $justesse)
- {
- $this->justesse -= $justesse;
- }
- public function ajouterNbMorts(int $nbMorts)
- {
- $this->nbMorts += $nbMorts;
- }
- public function getId(): ?int
- {
- return $this->id;
- }
- public function setUsername(string $username): self
- {
- $this->username = $username;
- return $this;
- }
- public function getPassword(): ?string
- {
- return $this->password;
- }
- public function setPassword(string $password): self
- {
- $this->password = $password;
- return $this;
- }
- public function getPrenom(): ?string
- {
- return $this->prenom;
- }
- public function setPrenom(string $prenom): self
- {
- $this->prenom = $prenom;
- return $this;
- }
- public function getNom(): ?string
- {
- return $this->nom;
- }
- public function setNom(string $nom): self
- {
- $this->nom = $nom;
- return $this;
- }
- public function getEmail(): ?string
- {
- return $this->email;
- }
- public function setEmail(string $email): self
- {
- $this->email = $email;
- return $this;
- }
- public function getRoles(): ?array
- {
- return $this->roles;
- }
- public function setRoles(array $roles): self
- {
- $this->roles = $roles;
- return $this;
- }
- public function getDateNaissance(): ?DateTimeInterface
- {
- return $this->dateNaissance;
- }
- public function setDateNaissance(DateTimeInterface $dateNaissance): self
- {
- $this->dateNaissance = $dateNaissance;
- return $this;
- }
- public function getDateEnregistrement(): ?DateTimeInterface
- {
- return $this->dateEnregistrement;
- }
- public function setDateEnregistrement(DateTimeInterface $dateEnregistrement): self
- {
- $this->dateEnregistrement = $dateEnregistrement;
- return $this;
- }
- public function getDateDernierePartie(): ?DateTimeInterface
- {
- return $this->dateDernierePartie;
- }
- public function setDateDernierePartie(?DateTimeInterface $dateDernierePartie): self
- {
- $this->dateDernierePartie = $dateDernierePartie;
- return $this;
- }
- public function getActif(): ?bool
- {
- return $this->actif;
- }
- public function setActif(bool $actif): self
- {
- $this->actif = $actif;
- return $this;
- }
- public function getNiveau(): ?int
- {
- return $this->niveau;
- }
- public function setNiveau(int $niveau): self
- {
- $this->niveau = $niveau;
- return $this;
- }
- public function getExperience(): ?int
- {
- return $this->experience;
- }
- public function setExperience(int $experience): self
- {
- $this->experience = $experience;
- return $this;
- }
- public function getNbVictimes(): ?int
- {
- return $this->nbVictimes;
- }
- public function setNbVictimes(int $nbVictimes): self
- {
- $this->nbVictimes = $nbVictimes;
- return $this;
- }
- public function getNbMorts(): ?int
- {
- return $this->nbMorts;
- }
- public function setNbMorts(int $nbMorts): self
- {
- $this->nbMorts = $nbMorts;
- return $this;
- }
- public function getJustesse(): ?int
- {
- return $this->justesse;
- }
- public function setJustesse(int $justesse): self
- {
- $this->justesse = $justesse;
- return $this;
- }
- /**
- * @return mixed
- */
- public function getNbParties()
- {
- return $this->nbParties;
- }
- /**
- * @param mixed $nbParties
- */
- public function setNbParties($nbParties): void
- {
- $this->nbParties = $nbParties;
- }
- /**
- * @return mixed
- */
- public function getCartes()
- {
- return $this->cartes;
- }
- /**
- * @param mixed $cartes
- */
- public function setCartes($cartes): void
- {
- $this->cartes = $cartes;
- }
- /**
- * @return mixed
- */
- public function getEquipe()
- {
- return $this->equipe;
- }
- /**
- * @param mixed $equipe
- */
- public function setEquipe($equipe): void
- {
- $this->equipe = $equipe;
- }
- /**
- * @return mixed
- */
- public function getCentres()
- {
- return $this->centres;
- }
- /**
- * @param mixed $centre
- */
- public function setCentres($centres): void
- {
- $this->centres = $centres;
- }
- /**
- * Returns the salt that was originally used to encode the password.
- *
- * This can return null if the password was not encoded using a salt.
- *
- * @return string|null The salt
- */
- public function getSalt()
- {
- return null;
- }
- /**
- * Returns the username used to authenticate the user.
- *
- * @return string The username
- */
- public function getUsername()
- {
- return $this->username;
- }
- /**
- * Removes sensitive data from the user.
- *
- * This is important if, at any given point, sensitive information like
- * the plain-text password is stored on this object.
- */
- public function eraseCredentials()
- {
- }
- }
- {
- "@context": "/api/contexts/Entrypoint",
- "@id": "/api",
- "@type": "Entrypoint",
- "user": "/api/users",
- "carte": "/api/cartes",
- "equipe": "/api/equipes",
- "centre": "/api/centres",
- "partie": "/api/parties"
- }
Add Comment
Please, Sign In to add comment