roles, true); } public function loadUser(): bool { if (isset($_SESSION['userID'])) { // try to load user from id! $user = DatabaseHandler::get()->getOne("SELECT * FROM users WHERE id = :id OR username = :name AND isActive = 1", [ ':id' => $_SESSION['userID'], ':name' => $this->username ]); if ($user) { $this->username = $user->username ?? ''; $this->email = $user->email ?? ''; $this->password = $user->password ?? ''; $this->token = $user->token ?? ''; $this->salt = $user->salt ?? ''; $this->id = $user->id ?? '-1'; $this->roles = explode(',', $user->roles ?? ''); $this->isLoaded = true; return true; } } return false; } public function getUsername(): string { return $this->username; } public function setUsername(string $username): void { $this->username = $username; } public function getEmail(): string { return $this->email; } public function setEmail(string $email): void { $this->email = $email; } public function getPassword(): string { return $this->password; } public function setPassword(string $password): void { $this->password = $password; } public function getSalt(): string { return $this->salt; } public function setSalt(string $salt): void { $this->salt = $salt; } public function getToken(): string { return $this->token; } public function setToken(string $token): void { $this->token = $token; } public function getRoles(): array { return $this->roles; } public function setRoles(array $roles): void { $this->roles = $roles; } public function addRole($value): void { if (!in_array($value, $this->roles, true)) { $this->roles[] = $value; } } public function isLoaded(): bool { return $this->isLoaded; } public function getId(): string { return $this->id; } }