src/Entity/Admin.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\AdminRepository;
  5. use Doctrine\Common\Collections\Collection;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use App\Controller\ControllerAdminChangePassword;
  8. use App\Controller\ControllerResetPasswordAdmin;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. #[ORM\Entity(repositoryClassAdminRepository::class)]
  15. #[UniqueEntity(fields:'phone'message:'Le phone existe déjà')]
  16. #[ApiResource(
  17.     normalizationContext:['groups'=>['admin:read']],
  18.     denormalizationContext:['groups'=>['admin:write']],
  19.     collectionOperations: [
  20.         "get" ,
  21.         "post",
  22.         'changePassword' => [
  23.             'method' => 'GET',
  24.             'path' => "admins/change-password/{userId}/{lastpassword}/{newpassword}",
  25.             'controller' => ControllerAdminChangePassword::class,
  26.             'read' => false,
  27.         ],
  28.          'resetPassword' => [
  29.              'method' => 'GET',
  30.              'path' => '/reset-password/{phone}',
  31.              'controller' => ControllerResetPasswordAdmin::class,
  32.              'read' => false,
  33.          ],
  34.     ],
  35.     itemOperations: [
  36.         "get" ,
  37.         "put" ,
  38.         "delete"
  39.     ]
  40. )]
  41. class Admin implements UserInterfacePasswordAuthenticatedUserInterface
  42. {
  43.     #[ORM\Id]
  44.     #[ORM\GeneratedValue]
  45.     #[ORM\Column(type'integer')]
  46.     #[Groups(['admin:read','admin:write'])]
  47.     private $id;
  48.     #[ORM\Column(type'string'length70)]
  49.     #[Groups(['admin:read','admin:write'])]
  50.     private $firstName;
  51.     #[ORM\Column(type'string'length180)]
  52.     #[Groups(['admin:read','admin:write'])]
  53.     private $lastName;
  54.     #[ORM\Column(type'string'length80nullabletrue)]
  55.     #[Groups(['admin:read','admin:write'])]
  56.     private $email;
  57.     #[ORM\Column(type'string'length15)]
  58.     #[Groups(['admin:read','admin:write'])]
  59.     private $phone;
  60.     #[ORM\Column(type'string'length255)]
  61.     #[Groups(['admin:read','admin:write'])]
  62.     private $password '1234';
  63.     #[ORM\ManyToMany(targetEntityRole::class)]
  64.     #[Groups(['admin:read','admin:write'])]
  65.     private $role;
  66.     public function __construct()
  67.     {
  68.         $this->role = new ArrayCollection();
  69.     }
  70.     public function getId(): ?int
  71.     {
  72.         return $this->id;
  73.     }
  74.     public function getFirstName(): ?string
  75.     {
  76.         return $this->firstName;
  77.     }
  78.     public function setFirstName(string $firstName): self
  79.     {
  80.         $this->firstName $firstName;
  81.         return $this;
  82.     }
  83.     public function getLastName(): ?string
  84.     {
  85.         return $this->lastName;
  86.     }
  87.     public function setLastName(string $lastName): self
  88.     {
  89.         $this->lastName $lastName;
  90.         return $this;
  91.     }
  92.     public function getEmail(): ?string
  93.     {
  94.         return $this->email;
  95.     }
  96.     public function setEmail(?string $email): self
  97.     {
  98.         $this->email $email;
  99.         return $this;
  100.     }
  101.     public function getPhone(): ?string
  102.     {
  103.         return $this->phone;
  104.     }
  105.     public function setPhone(string $phone): self
  106.     {
  107.         $this->phone $phone;
  108.         return $this;
  109.     }
  110.     /**
  111.      * Removes sensitive data from the user.
  112.      *
  113.      * This is important if, at any given point, sensitive information like
  114.      * the plain-text password is stored on this object.
  115.      */
  116.     public function eraseCredentials()
  117.     {
  118.     }
  119.     /**
  120.      * Returns the identifier for this user (e.g. its username or email address).
  121.      */
  122.     public function getUserIdentifier(): string
  123.     {
  124.         return $this->phone;
  125.     }
  126.     public function getPassword(): ?string
  127.     {
  128.         return $this->password;
  129.     }
  130.     public function setPassword(string $password): self
  131.     {
  132.         $this->password $password;
  133.         return $this;
  134.     }
  135.     /**
  136.      * @return array
  137.      */
  138.     public function getRoles(): array
  139.     {
  140.         return ["ROLE_ADMIN"];
  141.     }
  142.     /**
  143.      * @return Collection<int, self>
  144.      */
  145.     public function getRole(): Collection
  146.     {
  147.         return $this->role;
  148.     }
  149.     public function addRole(Role $role): self
  150.     {
  151.         if (!$this->role->contains($role)) {
  152.             $this->role[] = $role;
  153.         }
  154.         return $this;
  155.     }
  156.     public function removeRole(Role $role): self
  157.     {
  158.         $this->role->removeElement($role);
  159.         return $this;
  160.     }
  161. }