first commit
This commit is contained in:
47
app/Rules/ValidTeamInvitation.php
Normal file
47
app/Rules/ValidTeamInvitation.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Models\TeamInvitation;
|
||||
use App\Models\User;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Translation\PotentiallyTranslatedString;
|
||||
|
||||
class ValidTeamInvitation implements ValidationRule
|
||||
{
|
||||
public function __construct(protected ?User $user)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*
|
||||
* @param Closure(string, ?string=): PotentiallyTranslatedString $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (! $value instanceof TeamInvitation || ! $this->user instanceof User) {
|
||||
$fail(__('This invitation was sent to a different email address.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value->isAccepted()) {
|
||||
$fail(__('This invitation has already been accepted.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value->isExpired()) {
|
||||
$fail(__('This invitation has expired.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (strtolower($value->email) !== strtolower($this->user->email)) {
|
||||
$fail(__('This invitation was sent to a different email address.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user