src/Entity/User.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Donation\DonationLevelEnum;
  4. use App\Repository\UserRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[ORM\HasLifecycleCallbacks]
  12. #[UniqueEntity(fields: ['userName'], message'There is already an account with this username, please pick another one.')]
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\Column(
  20.         length320,
  21. //        unique: true  // TODO DEMO FIXIT
  22.     )]
  23. //    #[Assert\Email] // TODO DEMO FIXIT
  24.     private ?string $email =  'disabled for the demo';
  25.     #[ORM\Column]
  26.     private array $roles = [];
  27.     /**
  28.      * @var string|null/string The hashed password
  29.      */
  30.     #[ORM\Column(length255)]
  31. //    #[Assert\NotCompromisedPassword(
  32. //        message: 'The password is too weak, it must not be used. Please use another password.'
  33. //    )]
  34.     #[Assert\Length(
  35.         min2// todo DEMO FIX IT
  36.         minMessage'Your password should be at least {{ limit }} characters'
  37.     )]
  38.     private ?string $password null;
  39.     #[ORM\Column(length255)]
  40.     #[Assert\NotBlank]
  41.     private ?string $fullName 'disabled for the demo';
  42.     #[ORM\Column(length255)]
  43.     #[Assert\NotBlank]
  44.     private ?string $employer 'disabled for the demo';
  45.     #[ORM\Column(length255)]
  46.     #[Assert\NotBlank]
  47.     private ?string $occupation 'disabled for the demo';
  48.     #[ORM\Column(
  49.         nullablefalse,
  50.         enumTypeDonationLevelEnum::class,
  51.         options: ['unsigned' => true]
  52.     )]
  53.     #[Assert\Type(
  54.         typeDonationLevelEnum::class,
  55.         groups: ['registration_step_stop']
  56.     )]
  57.     private ?DonationLevelEnum $transactionDefaultAmount DonationLevelEnum::One;
  58.     #[ORM\Column]
  59.     private ?\DateTimeImmutable $createdAt null;
  60.     #[ORM\Column(nullabletrue)]
  61.     private ?\DateTimeImmutable $lastLoginAt null;
  62.     #[ORM\Column]
  63.     private bool $active false;
  64.     #[ORM\Column(length255uniquetrue)]
  65.     private ?string $userName null;
  66.     public function activate(): self
  67.     {
  68.         $this->active true;
  69.         return $this;
  70.     }
  71.     /**
  72.      * @see UserInterface
  73.      */
  74.     public function eraseCredentials()
  75.     {
  76.         // If you store any temporary, sensitive data on the user, clear it here
  77.         // $this->plainPassword = null;
  78.     }
  79.     public function getCreatedAt(): ?\DateTimeImmutable
  80.     {
  81.         return $this->createdAt;
  82.     }
  83.     #[ORM\PrePersist]
  84.     public function setCreatedAt(): self
  85.     {
  86.         $this->createdAt = new \DateTimeImmutable();
  87.         return $this;
  88.     }
  89.     public function getEmail(): ?string
  90.     {
  91.         return $this->email;
  92.     }
  93.     public function setEmail(string $email): self
  94.     {
  95.         $this->email $email;
  96.         return $this;
  97.     }
  98.     public function getEmployer(): ?string
  99.     {
  100.         return $this->employer;
  101.     }
  102.     public function setEmployer(string $employer): self
  103.     {
  104.         $this->employer $employer;
  105.         return $this;
  106.     }
  107.     public function getFullName(): ?string
  108.     {
  109.         return $this->userName;
  110.     }
  111.     public function setFullName(string $fullName): self
  112.     {
  113.         $this->fullName $fullName;
  114.         return $this;
  115.     }
  116.     public function getId(): ?int
  117.     {
  118.         return $this->id;
  119.     }
  120.     public function getLastLoginAt(): ?\DateTimeImmutable
  121.     {
  122.         return $this->lastLoginAt;
  123.     }
  124.     public function setLastLoginAt(?\DateTimeImmutable $lastLoginAt): self
  125.     {
  126.         $this->lastLoginAt $lastLoginAt;
  127.         return $this;
  128.     }
  129.     public function getOccupation(): ?string
  130.     {
  131.         return $this->occupation;
  132.     }
  133.     public function setOccupation(string $occupation): self
  134.     {
  135.         $this->occupation $occupation;
  136.         return $this;
  137.     }
  138.     /**
  139.      * @see PasswordAuthenticatedUserInterface
  140.      */
  141.     public function getPassword(): string
  142.     {
  143.         return $this->password;
  144.     }
  145.     public function setPassword(string $password): self
  146.     {
  147.         $this->password $password;
  148.         return $this;
  149.     }
  150.     /**
  151.      * @see UserInterface
  152.      */
  153.     public function getRoles(): array
  154.     {
  155.         $roles $this->roles;
  156.         // guarantee every user at least has ROLE_USER
  157.         $roles[] = 'ROLE_USER';
  158.         return array_unique($roles);
  159.     }
  160.     public function setRoles(array $roles): self
  161.     {
  162.         $this->roles $roles;
  163.         return $this;
  164.     }
  165.     public function getTransactionDefaultAmount(): int
  166.     {
  167.         return $this->transactionDefaultAmount->value;
  168.     }
  169.     public function setTransactionDefaultAmount(DonationLevelEnum $transactionDefaultAmount): self
  170.     {
  171.         $this->transactionDefaultAmount $transactionDefaultAmount;
  172.         return $this;
  173.     }
  174.     /**
  175.      * A visual identifier that represents this user.
  176.      *
  177.      * @see UserInterface
  178.      */
  179.     public function getUserIdentifier(): string
  180.     {
  181.         return (string)$this->email;
  182.     }
  183.     public function getUserName(): ?string
  184.     {
  185.         return $this->userName;
  186.     }
  187.     public function setUserName(string $userName): self
  188.     {
  189.         $this->userName $userName;
  190.         return $this;
  191.     }
  192.     public function isActive(): ?bool
  193.     {
  194.         return $this->active;
  195.     }
  196.     // TODO DEMO FIXIT
  197. //    #[Assert\IsTrue(message: 'The password cannot match your name or email')]
  198. //    public function isPasswordSafe(): bool
  199. //    {
  200. //        return !($this->fullName == $this->password || $this->email == $this->password);
  201. //    }
  202. }