87 lines
1.8 KiB
PHP
87 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Ulmus\User\Entity;
|
|
|
|
use Ulmus\Entity\Field\Datetime;
|
|
|
|
use Ulmus\Attribute\Property\Field;
|
|
|
|
class User {
|
|
|
|
#[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")]
|
|
public readonly ? Datetime $updatedAt;
|
|
|
|
#[Field\CreatedAt(name: "created_at")]
|
|
public readonly Datetime $createdAt;
|
|
|
|
public bool $logged = false;
|
|
|
|
public function __toString() : string
|
|
{
|
|
return "{$this->firstName} {$this->lastName}";
|
|
}
|
|
|
|
public function setPassword($password) : self
|
|
{
|
|
$this->password = $password;
|
|
|
|
return $this->hashPassword();
|
|
}
|
|
|
|
public function hashPassword(? string $password = null) : self
|
|
{
|
|
$this->password = password_hash($password ?: $this->password, PASSWORD_DEFAULT);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function verifyPassword(string $password) : bool
|
|
{
|
|
return password_verify($password, $this->password);
|
|
}
|
|
|
|
public function fullname() : string
|
|
{
|
|
return trim( ( $this->firstName ?? "" ) . " " . ( $this->lastName ?? "" ) );
|
|
}
|
|
}
|