src/Entity/Usuario.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Component\Security\Core\User\UserInterface;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  6. use App\Repository\UsuarioRepository;
  7. // src/Entity/Usuario.php
  8. #[ORM\Entity(repositoryClassUsuarioRepository::class)]
  9. #[ORM\Table(
  10.     name"users",
  11.     uniqueConstraints: [
  12.         new ORM\UniqueConstraint(name"uniq_users_email_empresa"columns: ["email""empresa_id"])
  13.     ]
  14. )]
  15. class Usuario implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     private ?int $id null;
  21.     #[ORM\Column(length180)]
  22.     private string $email;
  23.     #[ORM\Column]
  24.     private string $password;
  25.     #[ORM\Column]
  26.     private bool $status;
  27.     #[ORM\Column]
  28.     private int $isAdmin;
  29.     #[ORM\Column
  30.     private int $connection;
  31.     #[ORM\ManyToOne(inversedBy'usuarios')]
  32.     #[ORM\JoinColumn(nullablefalse)]
  33.     private Empresa $empresa;
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getEmail(): string
  39.     {
  40.         return $this->email;
  41.     }
  42.     public function setEmail(string $email): self
  43.     {
  44.         $this->email $email;
  45.         return $this;
  46.     }
  47.     public function getPassword(): string
  48.     {
  49.         return $this->password;
  50.     }
  51.     public function setPassword(string $password): self
  52.     {
  53.         $this->password $password;
  54.         return $this;
  55.     }
  56.     public function isStatus(): bool
  57.     {
  58.         return $this->status;
  59.     }
  60.     public function setStatus(bool $status): self
  61.     {
  62.         $this->status $status;
  63.         return $this;
  64.     }
  65.     public function getIsAdmin(): int
  66.     {
  67.         return $this->isAdmin;
  68.     }
  69.     public function setIsAdmin(int $isAdmin): self
  70.     {
  71.         $this->isAdmin $isAdmin;
  72.         return $this;
  73.     }
  74.     public function getEmpresa(): Empresa
  75.     {
  76.         return $this->empresa;
  77.     }
  78.     public function setEmpresa(Empresa $empresa): self
  79.     {
  80.         $this->empresa $empresa;
  81.         return $this;
  82.     }
  83.     
  84.     public function getConnection(): int
  85.     {
  86.         return $this->connection;
  87.     }
  88.     
  89.     public function setConnection($c): self
  90.     {
  91.         $this->connection $c;
  92.         return $this;
  93.     }
  94.     // Métodos requeridos por UserInterface
  95.     public function getRoles(): array
  96.     {
  97.         return $this->isAdmin === ? ['ROLE_ADMIN'] : ['ROLE_USER'];
  98.     }
  99.     public function getUserIdentifier(): string
  100.     {
  101.         return $this->email;
  102.     }
  103.     public function eraseCredentials(): void
  104.     {
  105.         // Si almacenas datos temporales o sensibles, límpialos aquí
  106.     }
  107.     public function getSalt(): ?string
  108.     {
  109.         return null// No necesario si usas bcrypt o sodium
  110.     }
  111.     public function getUsername(): string
  112.     {
  113.         return $this->getUserIdentifier(); // Obsoleto pero usado en versiones anteriores
  114.     }
  115.     // + métodos de seguridad requeridos por UserInterface
  116. }