73 lines
1.5 KiB
PHP
73 lines
1.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* User model represents an authenticated user for auth functionality only
|
|
*/
|
|
class User
|
|
{
|
|
public int|string $id;
|
|
public string $username;
|
|
public string $email;
|
|
public string $password;
|
|
public ?string $rememberToken;
|
|
public string $role;
|
|
public ?string $lastLogin;
|
|
|
|
public function __construct(array $data = [])
|
|
{
|
|
$this->id = $data['id'] ?? 0;
|
|
$this->username = $data['username'] ?? '';
|
|
$this->email = $data['email'] ?? '';
|
|
$this->password = $data['password'] ?? '';
|
|
$this->rememberToken = $data['remember_token'] ?? $data['rememberToken'] ?? null;
|
|
$this->role = $data['role'] ?? 'user';
|
|
$this->lastLogin = $data['last_login'] ?? $data['lastLogin'] ?? null;
|
|
}
|
|
|
|
/**
|
|
* Get user identifier (email or username)
|
|
*/
|
|
public function getIdentifier(): string
|
|
{
|
|
return $this->email ?: $this->username;
|
|
}
|
|
|
|
/**
|
|
* Get user ID
|
|
*/
|
|
public function getId(): int|string
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* Convert to array
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'username' => $this->username,
|
|
'email' => $this->email,
|
|
'password' => $this->password,
|
|
'remember_token' => $this->rememberToken,
|
|
'role' => $this->role,
|
|
'last_login' => $this->lastLogin,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Convert to safe array (without sensitive data)
|
|
*/
|
|
public function toSafeArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'username' => $this->username,
|
|
'email' => $this->email,
|
|
'role' => $this->role,
|
|
'last_login' => $this->lastLogin,
|
|
];
|
|
}
|
|
}
|