src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. /**
  9.  * UserAction
  10.  *
  11.  * @ORM\Table(name="fos_user")
  12.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  13.  */
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     /**
  17.      * @var int
  18.      *
  19.      * @ORM\Column(name="id", type="integer")
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue(strategy="AUTO")
  22.      */
  23.     private ?int $id null;
  24.     /**
  25.      * @ORM\Column(type="string", length=180, unique=true)
  26.      */
  27.     private $username;
  28.     /**
  29.      * @ORM\Column(type="string", length=180, unique=true)
  30.      */
  31.     private $email;
  32.     /**
  33.      * @ORM\Column(type="array")
  34.      */
  35.     private $roles = [];
  36.     /**
  37.      * @var string The hashed password
  38.      * @ORM\Column(type="string")
  39.      */
  40.     private $password;
  41.     /**
  42.      * @var boolean
  43.      * Activer ou desactiver le rappel automatique de changement de mot de passe
  44.      * @ORM\Column(name="rappel", type="boolean")
  45.      */
  46.     private $rappel true;
  47.     /**
  48.      * @var boolean
  49.      * Activer ou desactiver utilisateur
  50.      * @ORM\Column(name="enabled", type="boolean")
  51.      */
  52.     private $enabled true;
  53.     /**
  54.      * @var boolean
  55.      * set if remainder is sent
  56.      * @ORM\Column(name="two_week_remainder_sent", type="boolean")
  57.      */
  58.     private $twoWeekRemainderSent false;
  59.     /**
  60.      * @var boolean
  61.      * set if remainder is sent
  62.      * @ORM\Column(name="one_week_remainder_sent", type="boolean")
  63.      */
  64.     private $oneWeekRemainderSent false;
  65.     /**
  66.     *
  67.     * @ORM\Column(type="datetime", nullable = true)
  68.     */
  69.     private $passwordUpdatedAt;
  70.     /**
  71.     *
  72.     * @ORM\Column(type="datetime", nullable = true)
  73.     */
  74.     private $lastLogin;
  75.     /**
  76.     *
  77.     * @ORM\Column(type="string", nullable = true)
  78.     */
  79.     private $oldPasswords;
  80.     const ROLE_DEFAULT '';
  81.     const ROLE_SUPER_ADMIN 'ROLE_SUPER_ADMIN';
  82.     public function getId(): ?int
  83.     {
  84.         return $this->id;
  85.     }
  86.     /**
  87.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  88.      */
  89.     public function getUsername(): string
  90.     {
  91.         return (string) $this->username;
  92.     }
  93.     public function setUsername(string $username): self
  94.     {
  95.         $this->username $username;
  96.         return $this;
  97.     }
  98.     /**
  99.      * A visual identifier that represents this user.
  100.      *
  101.      * @see UserInterface
  102.      */
  103.     public function getUserIdentifier(): string
  104.     {
  105.         return (string) $this->username;
  106.     }
  107.     /**
  108.      * @see UserInterface
  109.      */
  110.     public function getRoles(): array
  111.     {
  112.         $roles $this->roles;
  113.         // guarantee every user at least has ROLE_USER
  114.         $roles[] = 'ROLE_USER';
  115.         return array_unique($roles);
  116.     }
  117.     public function setRoles(array $roles): self
  118.     {
  119.         $this->roles $roles;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @see PasswordAuthenticatedUserInterface
  124.      */
  125.     public function getPassword(): string
  126.     {
  127.         return $this->password;
  128.     }
  129.     public function setPassword(string $password): self
  130.     {
  131.         $this->password $password;
  132.         return $this;
  133.     }
  134.     /**
  135.      * Returning a salt is only needed, if you are not using a modern
  136.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  137.      *
  138.      * @see UserInterface
  139.      */
  140.     public function getSalt(): ?string
  141.     {
  142.         return null;
  143.     }
  144.     /**
  145.      * @see UserInterface
  146.      */
  147.     public function eraseCredentials()
  148.     {
  149.         // If you store any temporary, sensitive data on the user, clear it here
  150.         // $this->plainPassword = null;
  151.     }
  152.     /**
  153.      * Set rappel.
  154.      *
  155.      * @param bool $rappel
  156.      *
  157.      * @return User
  158.      */
  159.     public function setRappel($rappel)
  160.     {
  161.         $this->rappel $rappel;
  162.         return $this;
  163.     }
  164.     /**
  165.      * Get rappel.
  166.      *
  167.      * @return bool
  168.      */
  169.     public function getRappel()
  170.     {
  171.         return $this->rappel;
  172.     }
  173.     /**
  174.      * Set passwordUpdatedAt.
  175.      *
  176.      * @param \DateTime|null $passwordUpdatedAt
  177.      *
  178.      * @return User
  179.      */
  180.     public function setPasswordUpdatedAt($passwordUpdatedAt null)
  181.     {
  182.         $this->passwordUpdatedAt $passwordUpdatedAt;
  183.         return $this;
  184.     }
  185.     /**
  186.      * Get passwordUpdatedAt.
  187.      *
  188.      * @return \DateTime|null
  189.      */
  190.     public function getPasswordUpdatedAt()
  191.     {
  192.         return $this->passwordUpdatedAt;
  193.     }
  194.     /**
  195.      * Set oldPasswords.
  196.      *
  197.      * @param string|null $oldPasswords
  198.      *
  199.      * @return User
  200.      */
  201.     public function setOldPasswords($oldPasswords null)
  202.     {
  203.         $this->oldPasswords $oldPasswords;
  204.         return $this;
  205.     }
  206.     /**
  207.      * Get oldPasswords.
  208.      *
  209.      * @return string|null
  210.      */
  211.     public function getOldPasswords()
  212.     {
  213.         return $this->oldPasswords;
  214.     }
  215.     /**
  216.      * Set twoWeekRemainderSent.
  217.      *
  218.      * @param bool $twoWeekRemainderSent
  219.      *
  220.      * @return User
  221.      */
  222.     public function setTwoWeekRemainderSent($twoWeekRemainderSent)
  223.     {
  224.         $this->twoWeekRemainderSent $twoWeekRemainderSent;
  225.         return $this;
  226.     }
  227.     /**
  228.      * Get twoWeekRemainderSent.
  229.      *
  230.      * @return bool
  231.      */
  232.     public function getTwoWeekRemainderSent()
  233.     {
  234.         return $this->twoWeekRemainderSent;
  235.     }
  236.     /**
  237.      * Set oneWeekRemainderSent.
  238.      *
  239.      * @param bool $oneWeekRemainderSent
  240.      *
  241.      * @return User
  242.      */
  243.     public function setOneWeekRemainderSent($oneWeekRemainderSent)
  244.     {
  245.         $this->oneWeekRemainderSent $oneWeekRemainderSent;
  246.         return $this;
  247.     }
  248.     /**
  249.      * Get oneWeekRemainderSent.
  250.      *
  251.      * @return bool
  252.      */
  253.     public function getOneWeekRemainderSent()
  254.     {
  255.         return $this->oneWeekRemainderSent;
  256.     }
  257.     public function getEmail(): ?string
  258.     {
  259.         return $this->email;
  260.     }
  261.     public function setEmail(string $email): self
  262.     {
  263.         $this->email $email;
  264.         return $this;
  265.     }
  266.     public function isRappel(): ?bool
  267.     {
  268.         return $this->rappel;
  269.     }
  270.     public function isEnabled(): ?bool
  271.     {
  272.         return $this->enabled;
  273.     }
  274.     public function setEnabled(bool $enabled): self
  275.     {
  276.         $this->enabled $enabled;
  277.         return $this;
  278.     }
  279.     public function isTwoWeekRemainderSent(): ?bool
  280.     {
  281.         return $this->twoWeekRemainderSent;
  282.     }
  283.     public function isOneWeekRemainderSent(): ?bool
  284.     {
  285.         return $this->oneWeekRemainderSent;
  286.     }
  287.     public function getLastLogin(): ?\DateTimeInterface
  288.     {
  289.         return $this->lastLogin;
  290.     }
  291.     public function setLastLogin(?\DateTimeInterface $lastLogin): self
  292.     {
  293.         $this->lastLogin $lastLogin;
  294.         return $this;
  295.     }
  296.     public function hasRole(string $role): ?bool
  297.     {
  298.         return in_array($role$this->roles);
  299.     }
  300.     public function addRole(string $role): self
  301.     {
  302.         if (!in_array($role$this->roles)) {
  303.             $this->roles[] = $role;
  304.         }
  305.         return $this;
  306.     }
  307.     public function removeRole(string $role): self
  308.     {
  309.         $this->roles array_filter($this->roles, static function ($element) use ($role) {
  310.             return $element !== $role;
  311.         });
  312.         return $this;
  313.     }
  314. }