Style tweaks

This commit is contained in:
Alex Cabal 2024-06-03 15:10:18 -05:00
parent a54cca24b6
commit 2bfff1f962
2 changed files with 14 additions and 22 deletions

View file

@ -37,12 +37,14 @@ class Session{
// ******* // *******
/** /**
* @param ?string $identifier Either the email, or the UUID, of the user attempting to log in.
*
* @throws Exceptions\InvalidLoginException * @throws Exceptions\InvalidLoginException
* @throws Exceptions\PasswordRequiredException * @throws Exceptions\PasswordRequiredException
*/ */
public function Create(?string $email = null, ?string $password = null): void{ public function Create(?string $identifier = null, ?string $password = null): void{
try{ try{
$this->User = User::GetIfRegistered($email, $password); $this->User = User::GetIfRegistered($identifier, $password);
$this->UserId = $this->User->UserId; $this->UserId = $this->User->UserId;
$existingSessions = Db::Query(' $existingSessions = Db::Query('

View file

@ -1,5 +1,4 @@
<? <?
use Exceptions\UserExistsException;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
use Safe\DateTimeImmutable; use Safe\DateTimeImmutable;
@ -9,7 +8,6 @@ use Safe\DateTimeImmutable;
* @property Benefits $Benefits * @property Benefits $Benefits
*/ */
class User{ class User{
use Traits\Accessor; use Traits\Accessor;
public int $UserId; public int $UserId;
@ -81,7 +79,7 @@ class User{
// ******* // *******
/** /**
* @throws UserExistsException * @throws Exceptions\UserExistsException
*/ */
public function Create(?string $password = null): void{ public function Create(?string $password = null): void{
$uuid = Uuid::uuid4(); $uuid = Uuid::uuid4();
@ -125,13 +123,11 @@ class User{
throw new Exceptions\UserNotFoundException(); throw new Exceptions\UserNotFoundException();
} }
$result = Db::Query(' return Db::Query('
SELECT * SELECT *
from Users from Users
where UserId = ? where UserId = ?
', [$userId], User::class); ', [$userId], User::class)[0] ?? throw new Exceptions\UserNotFoundException();
return $result[0] ?? throw new Exceptions\UserNotFoundException();
} }
/** /**
@ -142,13 +138,11 @@ class User{
throw new Exceptions\UserNotFoundException(); throw new Exceptions\UserNotFoundException();
} }
$result = Db::Query(' return Db::Query('
SELECT * SELECT *
from Users from Users
where Email = ? where Email = ?
', [$email], User::class); ', [$email], User::class)[0] ?? throw new Exceptions\UserNotFoundException();
return $result[0] ?? throw new Exceptions\UserNotFoundException();
} }
/** /**
@ -163,27 +157,23 @@ class User{
throw new Exceptions\UserNotFoundException(); throw new Exceptions\UserNotFoundException();
} }
$result = Db::Query(' $user = Db::Query('
SELECT u.* SELECT u.*
from Users u from Users u
inner join Benefits using (UserId) inner join Benefits using (UserId)
where u.Email = ? where u.Email = ?
or u.Uuid = ? or u.Uuid = ?
', [$identifier, $identifier], User::class); ', [$identifier, $identifier], User::class)[0] ?? throw new Exceptions\UserNotFoundException();
if(sizeof($result) == 0){ if($user->PasswordHash !== null && $password === null){
throw new Exceptions\UserNotFoundException();
}
if($result[0]->PasswordHash !== null && $password === null){
// Indicate that a password is required before we log in // Indicate that a password is required before we log in
throw new Exceptions\PasswordRequiredException(); throw new Exceptions\PasswordRequiredException();
} }
if($result[0]->PasswordHash !== null && !password_verify($password ?? '', $result[0]->PasswordHash)){ if($user->PasswordHash !== null && !password_verify($password ?? '', $user->PasswordHash)){
throw new Exceptions\UserNotFoundException(); throw new Exceptions\UserNotFoundException();
} }
return $result[0]; return $user;
} }
} }