Get login working

This commit is contained in:
2024-11-28 11:37:56 -05:00
parent 17b399aa3f
commit 2656d93208
18 changed files with 1577 additions and 15 deletions

202
src/Entity/Company.php Normal file
View File

@ -0,0 +1,202 @@
<?php
namespace App\Entity;
use App\Repository\CompanyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: CompanyRepository::class)]
class Company
{
#[ORM\Id]
#[ORM\Column(type: UuidType::NAME, unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
private ?Uuid $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(length: 255)]
private ?string $address = null;
#[ORM\Column(length: 255)]
private ?string $city = null;
#[ORM\Column(length: 10)]
private ?string $state = null;
#[ORM\Column(length: 15)]
private ?string $zip = null;
#[ORM\Column(length: 15)]
private ?string $phone = null;
#[ORM\Column(length: 64)]
private ?string $email = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $url = null;
/**
* @var Collection<int, User>
*/
#[ORM\OneToMany(targetEntity: User::class, mappedBy: 'company')]
private Collection $users;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?User $owner = null;
public function __construct()
{
$this->users = new ArrayCollection();
}
public function getId(): ?Uuid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): static
{
$this->address = $address;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): static
{
$this->city = $city;
return $this;
}
public function getState(): ?string
{
return $this->state;
}
public function setState(string $state): static
{
$this->state = $state;
return $this;
}
public function getZip(): ?string
{
return $this->zip;
}
public function setZip(string $zip): static
{
$this->zip = $zip;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): static
{
$this->phone = $phone;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(?string $url): static
{
$this->url = $url;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): static
{
if (!$this->users->contains($user)) {
$this->users->add($user);
$user->setCompany($this);
}
return $this;
}
public function removeUser(User $user): static
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getCompany() === $this) {
$user->setCompany(null);
}
}
return $this;
}
public function getOwner(): ?User
{
return $this->owner;
}
public function setOwner(User $owner): static
{
$this->owner = $owner;
return $this;
}
}

267
src/Entity/User.php Normal file
View File

@ -0,0 +1,267 @@
<?php
namespace App\Entity;
use App\Repository\UserRepository;
use App\Enums\RateType;
use App\Enums\JobType;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Uid\Uuid;
use \App\Enums\CaseLevel;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USERNAME', fields: ['username'])]
#[UniqueEntity(fields: ['username'], message: 'There is already an account with this username')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\Column(type: UuidType::NAME, unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
private ?Uuid $id = null;
#[ORM\Column(length: 45)]
private ?string $username = null;
/**
* @var list<string> The user roles
*/
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(length: 45)]
private ?string $name = null;
#[ORM\Column(length: 45)]
private ?string $email = null;
#[ORM\Column(length: 45)]
private ?JobType $job = null;
#[ORM\Column(enumType: RateType::class)]
private ?RateType $rateType = null;
#[ORM\Column(type: Types::DECIMAL, precision: 6, scale: 2)]
private ?string $rate = null;
/**
* @var Collection<int, UserCase>
*/
#[ORM\OneToMany(targetEntity: UserCase::class, mappedBy: 'userId')]
private Collection $userCases;
#[ORM\ManyToOne(inversedBy: 'users')]
#[ORM\JoinColumn(nullable: true)]
private ?Company $company = null;
#[ORM\Column(enumType: CaseLevel::class)]
private ?CaseLevel $level = null;
public function __construct()
{
$this->userCases = new ArrayCollection();
}
public function getId(): ?Uuid
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): static
{
$this->username = $username;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->username;
}
/**
* @see UserInterface
*
* @return list<string>
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
/**
* @param list<string> $roles
*/
public function setRoles(array $roles): static
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
public function getJob(): ?JobType
{
return $this->job;
}
public function setJob(JobType $job): static
{
$this->job = $job;
return $this;
}
public function getRateType(): ?RateType
{
return $this->rateType;
}
public function setRateType(RateType $rateType): static
{
$this->rateType = $rateType;
return $this;
}
public function getRate(): ?string
{
return $this->rate;
}
public function setRate(string $rate): static
{
$this->rate = $rate;
return $this;
}
/**
* @return Collection<int, UserCase>
*/
public function getUserCases(): Collection
{
return $this->userCases;
}
public function addUserCase(UserCase $userCase): static
{
if (!$this->userCases->contains($userCase)) {
$this->userCases->add($userCase);
$userCase->setUserId($this);
}
return $this;
}
public function removeUserCase(UserCase $userCase): static
{
if ($this->userCases->removeElement($userCase)) {
// set the owning side to null (unless already changed)
if ($userCase->getUserId() === $this) {
$userCase->setUserId(null);
}
}
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): static
{
$this->company = $company;
return $this;
}
public function getLevel(): ?CaseLevel
{
return $this->level;
}
public function setLevel(CaseLevel $level): static
{
$this->level = $level;
return $this;
}
}