mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 06:40:33 -04:00
More type hinting
This commit is contained in:
parent
cb79832092
commit
1c3640fab6
6 changed files with 56 additions and 29 deletions
|
@ -1,4 +1,6 @@
|
|||
<?
|
||||
|
||||
use Exceptions\InvalidLoginException;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Safe\DateTime;
|
||||
use function Safe\strtotime;
|
||||
|
@ -33,33 +35,38 @@ class Session extends PropertiesBase{
|
|||
// *******
|
||||
|
||||
public function Create(?string $email = null, ?string $password = null): void{
|
||||
$this->User = User::GetIfRegistered($email, $password);
|
||||
$this->UserId = $this->User->UserId;
|
||||
try{
|
||||
$this->User = User::GetIfRegistered($email, $password);
|
||||
$this->UserId = $this->User->UserId;
|
||||
|
||||
$existingSessions = Db::Query('
|
||||
SELECT SessionId,
|
||||
Created
|
||||
from Sessions
|
||||
where UserId = ?
|
||||
', [$this->UserId]);
|
||||
$existingSessions = Db::Query('
|
||||
SELECT SessionId,
|
||||
Created
|
||||
from Sessions
|
||||
where UserId = ?
|
||||
', [$this->UserId]);
|
||||
|
||||
if(sizeof($existingSessions) > 0){
|
||||
$this->SessionId = $existingSessions[0]->SessionId;
|
||||
$this->Created = $existingSessions[0]->Created;
|
||||
if(sizeof($existingSessions) > 0){
|
||||
$this->SessionId = $existingSessions[0]->SessionId;
|
||||
$this->Created = $existingSessions[0]->Created;
|
||||
}
|
||||
else{
|
||||
$uuid = Uuid::uuid4();
|
||||
$this->SessionId = $uuid->toString();
|
||||
$this->Created = new DateTime();
|
||||
Db::Query('
|
||||
INSERT into Sessions (UserId, SessionId, Created)
|
||||
values (?,
|
||||
?,
|
||||
?)
|
||||
', [$this->UserId, $this->SessionId, $this->Created]);
|
||||
}
|
||||
|
||||
self::SetSessionCookie($this->SessionId);
|
||||
}
|
||||
else{
|
||||
$uuid = Uuid::uuid4();
|
||||
$this->SessionId = $uuid->toString();
|
||||
$this->Created = new DateTime();
|
||||
Db::Query('
|
||||
INSERT into Sessions (UserId, SessionId, Created)
|
||||
values (?,
|
||||
?,
|
||||
?)
|
||||
', [$this->UserId, $this->SessionId, $this->Created]);
|
||||
catch(Exceptions\InvalidUserException){
|
||||
throw new InvalidLoginException();
|
||||
}
|
||||
|
||||
self::SetSessionCookie($this->SessionId);
|
||||
}
|
||||
|
||||
public static function GetLoggedInUser(): ?User{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue