From 1c3804973517f603e68d2252a6d5bbd0c65c344c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 24 Sep 2023 00:42:26 +0200 Subject: [PATCH] add new getters to userrepository --- src/Repository/UserRepository.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 2062739..f69a99c 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -22,6 +22,23 @@ class UserRepository implements IUserRepository return \Container::$persistentDataManager->selectFromDb($select, User::class); } + public function getByUsername(string $username): ?User + { + $select = new Select(\Container::$dbConnection); + $select->where('username', '=', $username); + + return \Container::$persistentDataManager->selectFromDb($select, User::class); + } + + public function getByEmailOrUsername(string $emailOrUsername): ?User + { + if (filter_var($emailOrUsername, FILTER_VALIDATE_EMAIL)) { + return $this->getByEmail($emailOrUsername); + } + + return $this->getByUsername($emailOrUsername); + } + public function getByGoogleSub(string $sub): ?User { $select = new Select(\Container::$dbConnection);