This commit is contained in:
2024-11-26 20:42:13 +01:00
parent 60d8b8bd1d
commit 855570b685
27 changed files with 1590 additions and 108 deletions

View File

@ -6,11 +6,16 @@ use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USERNAME', fields: ['username'])]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
#[UniqueEntity(fields: ['email'], message: 'Cet email est déjà utilisé.')]
#[UniqueEntity(fields: ['username'], message: 'Ce nom dutilisateur est déjà pris.')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
@ -18,24 +23,26 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180)]
#[ORM\Column(length: 180, unique: true)]
private ?string $username = null;
/**
* @var list<string> The user roles
*/
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
#[Assert\Regex(
pattern: '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\W).{8,}$/',
message: 'Le mot de passe doit contenir au moins 8 caractères, une lettre majuscule, une lettre minuscule et un caractère spécial.'
)]
private ?string $password = null;
/**
* @var Collection<int, Company>
*/
#[ORM\Column(length: 255, nullable: true)]
private ?string $avatar = null;
#[ORM\Column(length: 255, unique: true)]
#[Assert\Email(message: 'Veuillez entrer un email valide.')]
private ?string $email = null;
#[ORM\ManyToMany(targetEntity: Company::class, inversedBy: 'users')]
private Collection $companys;
@ -119,6 +126,30 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
// $this->plainPassword = null;
}
public function getAvatar(): ?string
{
return $this->avatar ? $this->avatar : 'medias/avatar/noavatar.png';
}
public function setAvatar(?string $avatar): static
{
$this->avatar = $avatar;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
/**
* @return Collection<int, Company>
*/