Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

User.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace Lc\SovBundle\Model\User;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Lc\SovBundle\Doctrine\EntityInterface;
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. /**
  7. * @ORM\MappedSuperclass()
  8. */
  9. abstract class User implements EntityInterface, UserInterface
  10. {
  11. /**
  12. * @ORM\Column(type="string", length=180, unique=true)
  13. */
  14. protected $email;
  15. /**
  16. * @ORM\Column(type="json")
  17. */
  18. protected $roles = [];
  19. /**
  20. * @var string The hashed password
  21. * @ORM\Column(type="string")
  22. */
  23. protected $password;
  24. /**
  25. * @ORM\Column(type="string", length=255, nullable=true)
  26. */
  27. protected $lastname;
  28. /**
  29. * @ORM\Column(type="string", length=255, nullable=true)
  30. */
  31. protected $firstname;
  32. /**
  33. * @ORM\Column(type="boolean")
  34. */
  35. protected $isVerified = false;
  36. public function getEmail(): ?string
  37. {
  38. return $this->email;
  39. }
  40. public function setEmail(string $email): self
  41. {
  42. $this->email = $email;
  43. return $this;
  44. }
  45. /**
  46. * A visual identifier that represents this user.
  47. *
  48. * @see UserInterface
  49. */
  50. public function getUsername(): string
  51. {
  52. return (string)$this->email;
  53. }
  54. /**
  55. * @see UserInterface
  56. */
  57. public function getRoles(): array
  58. {
  59. $roles = $this->roles;
  60. // guarantee every user at least has ROLE_USER
  61. $roles[] = 'ROLE_USER';
  62. return array_unique($roles);
  63. }
  64. public function setRoles(array $roles): self
  65. {
  66. $this->roles = $roles;
  67. return $this;
  68. }
  69. public function hasRole($role)
  70. {
  71. return in_array(strtoupper($role), $this->getRoles(), true);
  72. }
  73. /**
  74. * @see UserInterface
  75. */
  76. public function getPassword(): string
  77. {
  78. return (string)$this->password;
  79. }
  80. public function setPassword(string $password): self
  81. {
  82. $this->password = $password;
  83. return $this;
  84. }
  85. /**
  86. * @see UserIn
  87. */
  88. public function getSalt()
  89. {
  90. // not needed when using the "bcrypt" algorithm in security.yaml
  91. }
  92. /**
  93. * @see UserInterface
  94. */
  95. public function eraseCredentials()
  96. {
  97. // If you store any temporary, sensitive data on the user, clear it here
  98. // $this->plainPassword = null;
  99. }
  100. public function getLastname(): ?string
  101. {
  102. return $this->lastname;
  103. }
  104. public function setLastname(?string $lastname): self
  105. {
  106. $this->lastname = $lastname;
  107. return $this;
  108. }
  109. public function getFirstname(): ?string
  110. {
  111. return $this->firstname;
  112. }
  113. public function setFirstname(?string $firstname): self
  114. {
  115. $this->firstname = $firstname;
  116. return $this;
  117. }
  118. public function getName(): ?string
  119. {
  120. return $this->getFirstname() . ' ' . strtoupper($this->getLastname());
  121. }
  122. public function isVerified(): bool
  123. {
  124. return $this->isVerified;
  125. }
  126. public function setIsVerified(bool $isVerified): self
  127. {
  128. $this->isVerified = $isVerified;
  129. return $this;
  130. }
  131. }