This commit is contained in:
1 parent
f15d9a9cfd
commit
054e970df9
36 files changed
+1434
-363
No files matched your search
+53
-1
@@ -9,6 +9,9 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* User models an authenticated account that can create reviews and albums.
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||
#[ORM\Table(name: 'users')]
|
||||
#[UniqueEntity(fields: ['email'], message: 'This email is already registered.')]
|
||||
@@ -40,30 +43,49 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
#[Assert\Length(max: 120)]
|
||||
private ?string $displayName = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 255, nullable: true)]
|
||||
private ?string $profileImagePath = null;
|
||||
|
||||
/**
|
||||
* Returns the database identifier.
|
||||
*/
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the normalized email address.
|
||||
*/
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets and normalizes the email address.
|
||||
*/
|
||||
public function setEmail(string $email): void
|
||||
{
|
||||
$this->email = strtolower($email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Symfony security identifier alias for the email.
|
||||
*/
|
||||
public function getUserIdentifier(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique role list plus the implicit ROLE_USER.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getRoles(): array
|
||||
{
|
||||
$roles = $this->roles;
|
||||
// guarantee every user at least has ROLE_USER
|
||||
if (!in_array('ROLE_USER', $roles, true)) {
|
||||
$roles[] = 'ROLE_USER';
|
||||
}
|
||||
@@ -71,6 +93,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the granted role list.
|
||||
*
|
||||
* @param list<string> $roles
|
||||
*/
|
||||
public function setRoles(array $roles): void
|
||||
@@ -78,6 +102,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
$this->roles = array_values(array_unique($roles));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a single role if not already present.
|
||||
*/
|
||||
public function addRole(string $role): void
|
||||
{
|
||||
$roles = $this->getRoles();
|
||||
@@ -87,30 +114,55 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
$this->roles = $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hashed password string.
|
||||
*/
|
||||
public function getPassword(): string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the hashed password string.
|
||||
*/
|
||||
public function setPassword(string $hashedPassword): void
|
||||
{
|
||||
$this->password = $hashedPassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any sensitive transient data (no-op here).
|
||||
*/
|
||||
public function eraseCredentials(): void
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the optional display name.
|
||||
*/
|
||||
public function getDisplayName(): ?string
|
||||
{
|
||||
return $this->displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the optional display name.
|
||||
*/
|
||||
public function setDisplayName(?string $displayName): void
|
||||
{
|
||||
$this->displayName = $displayName;
|
||||
}
|
||||
|
||||
public function getProfileImagePath(): ?string
|
||||
{
|
||||
return $this->profileImagePath;
|
||||
}
|
||||
|
||||
public function setProfileImagePath(?string $profileImagePath): void
|
||||
{
|
||||
$this->profileImagePath = $profileImagePath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user