Complete profile image, password update functionality

This commit is contained in:
Ryan Prather 2025-01-03 15:31:07 +00:00
parent 8d97ab0345
commit ea322dc2ac
3 changed files with 52 additions and 0 deletions

View File

@ -12,6 +12,7 @@ use App\Form\UserFormType;
use App\Libs\Breadcrumb; use App\Libs\Breadcrumb;
use App\Libs\NavList; use App\Libs\NavList;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -145,6 +146,7 @@ class AdminController extends AbstractController
->setRate($form->get('rate')->getData()) ->setRate($form->get('rate')->getData())
->setLevel($form->get('level')->getData()) ->setLevel($form->get('level')->getData())
->setCompany($admin->getCompany()) ->setCompany($admin->getCompany())
->setPasswordChanged(new DateTime())
; ;
if ($form->get('imageName')->getData()) { if ($form->get('imageName')->getData()) {

View File

@ -6,6 +6,7 @@ use App\Entity\Messages;
use App\Entity\User; use App\Entity\User;
use App\Libs\Breadcrumb; use App\Libs\Breadcrumb;
use App\Libs\NavList; use App\Libs\NavList;
use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\EmailType;
@ -135,6 +136,7 @@ class DefaultController extends AbstractController
$plainPassword $plainPassword
) )
); );
$user->setPasswordChanged(new DateTime())
} }
if ($form['imageName']->getData()) { if ($form['imageName']->getData()) {

View File

@ -14,10 +14,13 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Uid\Uuid; use Symfony\Component\Uid\Uuid;
use Vich\UploaderBundle\Entity\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: UserRepository::class)] #[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USERNAME', fields: ['username'])] #[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USERNAME', fields: ['username'])]
#[UniqueEntity(fields: ['username'], message: 'There is already an account with this username')] #[UniqueEntity(fields: ['username'], message: 'There is already an account with this username')]
#[Vich\Uploadable]
class User implements UserInterface, PasswordAuthenticatedUserInterface class User implements UserInterface, PasswordAuthenticatedUserInterface
{ {
#[ORM\Id] #[ORM\Id]
@ -80,6 +83,15 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\OneToMany(targetEntity: UserCase::class, mappedBy: 'user')] #[ORM\OneToMany(targetEntity: UserCase::class, mappedBy: 'user')]
private Collection $userCases; private Collection $userCases;
#[Vich\UploadableField(mapping: 'profile_image', fileNameProperty: 'imageName', size: 'size', mimeType: 'mimeType', originalName: 'originalName', dimensions: 'dimensions')]
private ?File $imageFile = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
private ?string $imageName = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $passwordChanged = null;
public function __construct() public function __construct()
{ {
$this->userCases = new ArrayCollection(); $this->userCases = new ArrayCollection();
@ -351,4 +363,40 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $jobs; return $jobs;
} }
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageFile(?File $imageFile): static
{
$this->imageFile = $imageFile;
return $this;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageName(?string $imageName): static
{
$this->imageName = $imageName;
return $this;
}
public function getPasswordChanged(): ?\DateTimeInterface
{
return $this->passwordChanged;
}
public function setPasswordChanged(\DateTimeInterface $passwordChanged): static
{
$this->passwordChanged = $passwordChanged;
return $this;
}
} }