mirror of
https://github.com/standardebooks/web.git
synced 2025-07-08 07:40:39 -04:00
Type tweaks for exceptions and some validation
This commit is contained in:
parent
5b3f8f7b77
commit
7eaa400ae3
13 changed files with 49 additions and 37 deletions
|
@ -31,8 +31,8 @@ class NewsletterSubscription extends Accessor{
|
|||
// METHODS
|
||||
// *******
|
||||
|
||||
public function Create(): void{
|
||||
$this->Validate();
|
||||
public function Create(?string $expectedCaptcha = null, ?string $receivedCaptcha = null): void{
|
||||
$this->Validate($expectedCaptcha, $receivedCaptcha);
|
||||
|
||||
// Do we need to create a user?
|
||||
try{
|
||||
|
@ -111,8 +111,8 @@ class NewsletterSubscription extends Accessor{
|
|||
', [$this->UserId]);
|
||||
}
|
||||
|
||||
public function Validate(): void{
|
||||
$error = new Exceptions\ValidationException();
|
||||
public function Validate(?string $expectedCaptcha = null, ?string $receivedCaptcha = null): void{
|
||||
$error = new Exceptions\InvalidNewsletterSubscription();
|
||||
|
||||
if($this->User === null || $this->User->Email == '' || !filter_var($this->User->Email, FILTER_VALIDATE_EMAIL)){
|
||||
$error->Add(new Exceptions\InvalidEmailException());
|
||||
|
@ -122,6 +122,12 @@ class NewsletterSubscription extends Accessor{
|
|||
$error->Add(new Exceptions\NewsletterRequiredException());
|
||||
}
|
||||
|
||||
if($expectedCaptcha !== null){
|
||||
if($expectedCaptcha === '' || mb_strtolower($expectedCaptcha) !== mb_strtolower($receivedCaptcha ?? '')){
|
||||
$error->Add(new Exceptions\InvalidCaptchaException());
|
||||
}
|
||||
}
|
||||
|
||||
if($error->HasExceptions){
|
||||
throw $error;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue