<?php /* * Copyright (c) 2022. Micha Espey <tracer@24unix.net> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * */ namespace App\Entity; use App\Enums\UserAuth; class User { public function __construct( private string $nick = '', private string $password = '', private readonly string $newPassword = '', private string $first = '', private string $last = '', private int $id = 0, private bool $isAdmin = false, private UserAuth $userAuth = UserAuth::AUTH_ANONYMOUS ) { if (!empty($this->newPassword)) { echo "password"; $this->password = password_hash(password: $this->newPassword, algo: PASSWORD_ARGON2I); } if (session_status() === PHP_SESSION_ACTIVE) { // ANONYMOUS has id 0 if ($this->id != 0) { if ($this->isAdmin) { $this->userAuth = UserAuth::AUTH_ADMIN; } else { $this->userAuth = UserAuth::AUTH_USER; } } } } public function getNick(): string { return $this->nick; } public function setNick(string $nick): void { $this->nick = $nick; } public function getPassword(): string { return $this->password; } public function setPassword(string $password): void { $this->password = $password; } public function getFirst(): string { return $this->first; } public function setFirst(string $first): void { $this->first = $first; } public function getLast(): string { return $this->last; } public function setLast(string $last): void { $this->last = $last; } public function getId(): int { return $this->id; } public function setId(int $id): void { $this->id = $id; } public function isAdmin(): bool { return $this->isAdmin; } public function setIsAdmin(bool $isAdmin): void { $this->isAdmin = $isAdmin; } public function getAuth(): UserAuth { return $this->userAuth; } public function setAuth(UserAuth $userAuth): void { $this->userAuth = $userAuth; } }