97 lines
2.1 KiB
PHP
97 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Ulmus\User\Entity;
|
|
|
|
use Ulmus\Entity\EntityInterface;
|
|
use Ulmus\Entity\Field\Datetime;
|
|
|
|
use Ulmus\Attribute\Property\Field;
|
|
|
|
abstract class User implements UserInterface {
|
|
|
|
#[Field\Id(readonly: true)]
|
|
public int $id;
|
|
|
|
#[Field(length: 35, name: "first_name")]
|
|
public ? string $firstName;
|
|
|
|
#[Field(length: 35, name: "last_name")]
|
|
public ? string $lastName;
|
|
|
|
#[Field(length: 150)]
|
|
public string $email;
|
|
|
|
#[Field(length: 150)]
|
|
public ? string $address;
|
|
|
|
#[Field(length: 15, name: "zip_code")]
|
|
public ? string $zipCode;
|
|
|
|
#[Field(length: 45)]
|
|
public ? string $province;
|
|
|
|
#[Field(length: 3)]
|
|
public ? string $country;
|
|
|
|
#[Field(length: 15)]
|
|
public ? string $phone;
|
|
|
|
#[Field(length: 15)]
|
|
public ? string $ext;
|
|
|
|
#[Field(length: 15)]
|
|
public ? string $mobile;
|
|
|
|
#[Field(length: 255)]
|
|
public ? string $username;
|
|
|
|
#[Field]
|
|
public string $password;
|
|
|
|
#[Field\UpdatedAt(name: "updated_at", readonly: true)]
|
|
public ? Datetime $updatedAt;
|
|
|
|
#[Field\CreatedAt(name: "created_at", readonly: true)]
|
|
public Datetime $createdAt;
|
|
|
|
public bool $logged = false;
|
|
|
|
public function __toString() : string
|
|
{
|
|
return $this->fullName();
|
|
}
|
|
|
|
public function setPassword($password) : static
|
|
{
|
|
$this->password = $password;
|
|
|
|
return $this->hashPassword();
|
|
}
|
|
|
|
public function hashPassword(? string $password = null) : static
|
|
{
|
|
$this->password = password_hash($password ?: $this->password, PASSWORD_DEFAULT);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function verifyPassword(string $password) : bool
|
|
{
|
|
return password_verify($password, $this->password ?? null);
|
|
}
|
|
|
|
public function fullname(bool $reverse = false) : string
|
|
{
|
|
if (! $this->isLoaded() ) {
|
|
return "???";
|
|
}
|
|
|
|
return trim($reverse ? "{$this->lastName}, {$this->firstName}" : "{$this->firstName} {$this->lastName}");
|
|
}
|
|
|
|
public function loggedIn(?bool $set = null): bool
|
|
{
|
|
return $set !== null ? $this->logged = $set : $this->logged;
|
|
}
|
|
}
|