finished user prfile and passwords

This commit is contained in:
2022-11-01 14:57:36 +01:00
parent a488e489da
commit 560e96cf18
61 changed files with 1581 additions and 852 deletions

@@ -0,0 +1,39 @@
<?php
namespace App\Entity;
use App\Repository\ResetPasswordRequestRepository;
use Doctrine\ORM\Mapping as ORM;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;
#[ORM\Entity(repositoryClass: ResetPasswordRequestRepository::class)]
class ResetPasswordRequest implements ResetPasswordRequestInterface
{
use ResetPasswordRequestTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?User $user = null;
public function __construct(User $user, \DateTimeInterface $expiresAt, string $selector, string $hashedToken)
{
$this->user = $user;
$this->initialize(expiresAt: $expiresAt, selector: $selector, hashedToken: $hashedToken);
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): object
{
return $this->user;
}
}

@@ -2,48 +2,40 @@
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Repository\UserRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
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;
/**
* => ["security" => "is_granted('ROLE_ADMIN') or object.owner == user"]
attributes : ['security' => 'is_granted("ROLE_USER")']
*/
#[ORM\Entity(repositoryClass: UserRepository::class), ORM\HasLifecycleCallbacks]
#[ApiResource(
collectionOperations: ['get', 'post'],
itemOperations : ['get'],
)]
#[ApiFilter(filterClass: SearchFilter::class, properties: ['username' => 'exact'])]
#[UniqueEntity(fields: ['username', 'email'], message: 'There is already an account with this username or email.')]
class User implements UserInterface, PasswordAuthenticatedUserInterface, \Stringable
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private int $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
#[ORM\Column(type: 'string', length: 180, unique: true, nullable: false)]
private string $username;
#[ORM\Column(type: 'json')]
private array $roles = [];
#[ORM\Column(type: 'string')]
#[ORM\Column(type: 'string', nullable: false)]
private string $password;
private string $plainPassword;
#[ORM\Column(type: 'string', length: 255)]
#[ORM\Column(type: 'string', length: 255, nullable: false)]
#[Assert\Email(
message: 'The eMail {{ value }} is not a valid eMail.'
)]
private string $email;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
@@ -67,15 +59,18 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \String
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private $modifiedAt;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\Column]
private ?DateTimeImmutable $agreedTermsAt = null;
public function __construct()
{
$this->projects = new ArrayCollection();
$this->pages = new ArrayCollection();
}
/**
* @return string|null
*/
public function __toString(): string
{
return $this->username;
@@ -86,11 +81,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \String
return $this->id;
}
public function getPlainPassword(): string
{
return $this->plainPassword;
}
public function getUsername(): ?string
{
return $this->username;
@@ -293,9 +283,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \String
* @return string
*/
public function getAvatarUri()
{
return 'avatar';
}
{
return 'avatar';
}
#[ORM\PrePersist]
public function onPrePersist(): void
@@ -308,4 +298,28 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \String
{
$this->modifiedAt = new DateTimeImmutable(datetime: 'now');
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getAgreedTermsAt(): ?DateTimeImmutable
{
return $this->agreedTermsAt;
}
public function agreeTerms(): self
{
$this->agreedTermsAt = new DateTimeImmutable();
return $this;
}
}