mirror of
https://github.com/standardebooks/web.git
synced 2025-07-05 22:30:30 -04:00
More type hinting
This commit is contained in:
parent
cb79832092
commit
1c3640fab6
6 changed files with 56 additions and 29 deletions
|
@ -72,18 +72,28 @@ class Artwork extends PropertiesBase{
|
|||
return $this->_UrlName;
|
||||
}
|
||||
|
||||
protected function GetSubmitter(): User{
|
||||
protected function GetSubmitter(): ?User{
|
||||
if($this->_Submitter === null){
|
||||
try{
|
||||
$this->_Submitter = User::Get($this->SubmitterUserId);
|
||||
}
|
||||
catch(Exceptions\InvalidUserException){
|
||||
// Return null
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_Submitter;
|
||||
}
|
||||
|
||||
protected function GetReviewer(): User{
|
||||
protected function GetReviewer(): ?User{
|
||||
if($this->_Reviewer === null){
|
||||
try{
|
||||
$this->_Reviewer = User::Get($this->ReviewerUserId);
|
||||
}
|
||||
catch(Exceptions\InvalidUserException){
|
||||
// Return null
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_Reviewer;
|
||||
}
|
||||
|
|
6
lib/Exceptions/InvalidLoginException.php
Normal file
6
lib/Exceptions/InvalidLoginException.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?
|
||||
namespace Exceptions;
|
||||
|
||||
class InvalidLoginException extends AppException{
|
||||
protected $message = 'We couldn’t validate your login information.';
|
||||
}
|
|
@ -2,5 +2,5 @@
|
|||
namespace Exceptions;
|
||||
|
||||
class InvalidUserException extends AppException{
|
||||
protected $message = 'We couldn’t validate your login information.';
|
||||
protected $message = 'We couldn’t locate that user.';
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<?
|
||||
|
||||
use Exceptions\InvalidLoginException;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Safe\DateTime;
|
||||
use function Safe\strtotime;
|
||||
|
@ -33,6 +35,7 @@ class Session extends PropertiesBase{
|
|||
// *******
|
||||
|
||||
public function Create(?string $email = null, ?string $password = null): void{
|
||||
try{
|
||||
$this->User = User::GetIfRegistered($email, $password);
|
||||
$this->UserId = $this->User->UserId;
|
||||
|
||||
|
@ -61,6 +64,10 @@ class Session extends PropertiesBase{
|
|||
|
||||
self::SetSessionCookie($this->SessionId);
|
||||
}
|
||||
catch(Exceptions\InvalidUserException){
|
||||
throw new InvalidLoginException();
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetLoggedInUser(): ?User{
|
||||
$sessionId = HttpInput::Str(COOKIE, 'sessionid');
|
||||
|
|
|
@ -114,6 +114,10 @@ class User extends PropertiesBase{
|
|||
// ***********
|
||||
|
||||
public static function Get(?int $userId): User{
|
||||
if($userId === null){
|
||||
throw new Exceptions\InvalidUserException();
|
||||
}
|
||||
|
||||
$result = Db::Query('
|
||||
SELECT *
|
||||
from Users
|
||||
|
|
|
@ -82,7 +82,7 @@ catch(Exceptions\ArtworkNotFoundException){
|
|||
<? if($isAdminView){ ?>
|
||||
<tr>
|
||||
<td>Submitted by</td>
|
||||
<td><? if($artwork->SubmitterUserId === null){ ?>Anonymous<? }else{ ?><a href="mailto:<?= Formatter::ToPlainText($artwork->Submitter->Email) ?>"><? if($artwork->Submitter->Name !== null){ ?> <?= Formatter::ToPlainText($artwork->Submitter->Name) ?><? }else{ ?><?= Formatter::ToPlainText($artwork->Submitter->Email) ?><? } ?></a><? } ?></td>
|
||||
<td><? if($artwork->Submitter === null){ ?>Anonymous<? }else{ ?><a href="mailto:<?= Formatter::ToPlainText($artwork->Submitter->Email) ?>"><? if($artwork->Submitter->Name !== null){ ?> <?= Formatter::ToPlainText($artwork->Submitter->Name) ?><? }else{ ?><?= Formatter::ToPlainText($artwork->Submitter->Email) ?><? } ?></a><? } ?></td>
|
||||
</tr>
|
||||
<? if($artwork->Reviewer !== null){ ?>
|
||||
<tr>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue