Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4b4307c32 |
@@ -15,14 +15,14 @@
|
|||||||
"source": "https://git.leadmagnet.dev/LeadMagnet/leadmail-sdk"
|
"source": "https://git.leadmagnet.dev/LeadMagnet/leadmail-sdk"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.2",
|
"php": "^8.1",
|
||||||
"guzzlehttp/guzzle": "^7.0",
|
"guzzlehttp/guzzle": "^7.0",
|
||||||
"illuminate/mail": "^11.0|^12.0",
|
"illuminate/mail": "^9.0|^10.0",
|
||||||
"illuminate/support": "^11.0|^12.0"
|
"illuminate/support": "^9.0|^10.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"orchestra/testbench": "^9.0|^10.0",
|
"orchestra/testbench": "^7.0|^8.0",
|
||||||
"pestphp/pest": "^3.0|^4.0"
|
"pestphp/pest": "^1.0|^2.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@@ -44,13 +44,8 @@ class LeadMailServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
Validator::extend('leadmail_verify', function (string $attribute, mixed $value) {
|
Validator::extend('leadmail_verify', function (string $attribute, mixed $value) {
|
||||||
$rule = $this->app->make(LeadMailVerify::class);
|
$rule = $this->app->make(LeadMailVerify::class);
|
||||||
$passed = true;
|
|
||||||
|
|
||||||
$rule->validate($attribute, $value, function () use (&$passed) {
|
return $rule->passes($attribute, $value);
|
||||||
$passed = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
return $passed;
|
|
||||||
}, 'The :attribute email address could not be verified.');
|
}, 'The :attribute email address could not be verified.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,23 +2,24 @@
|
|||||||
|
|
||||||
namespace LeadM\LeadMail\Rules;
|
namespace LeadM\LeadMail\Rules;
|
||||||
|
|
||||||
use Closure;
|
use Illuminate\Contracts\Validation\Rule;
|
||||||
use Illuminate\Contracts\Validation\ValidationRule;
|
|
||||||
use LeadM\LeadMail\LeadMailClient;
|
use LeadM\LeadMail\LeadMailClient;
|
||||||
|
|
||||||
class LeadMailVerify implements ValidationRule
|
class LeadMailVerify implements Rule
|
||||||
{
|
{
|
||||||
|
protected string $failMessage = 'The :attribute email address could not be verified.';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected readonly LeadMailClient $client,
|
protected readonly LeadMailClient $client,
|
||||||
protected readonly bool $allowDisposable = false,
|
protected readonly bool $allowDisposable = false,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
public function passes($attribute, $value): bool
|
||||||
{
|
{
|
||||||
if (! is_string($value) || ! filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
if (! is_string($value) || ! filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
||||||
$fail('The :attribute must be a valid email address.');
|
$this->failMessage = 'The :attribute must be a valid email address.';
|
||||||
|
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -26,10 +27,20 @@ class LeadMailVerify implements ValidationRule
|
|||||||
|
|
||||||
if (! ($result['data']['valid'] ?? true)) {
|
if (! ($result['data']['valid'] ?? true)) {
|
||||||
$reason = $result['data']['reason'] ?? 'verification failed';
|
$reason = $result['data']['reason'] ?? 'verification failed';
|
||||||
$fail("The :attribute email address is not deliverable ({$reason}).");
|
$this->failMessage = "The :attribute email address is not deliverable ({$reason}).";
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
} catch (\Throwable) {
|
} catch (\Throwable) {
|
||||||
// Fail open — if the verification service is down, allow the email through
|
// Fail open — if the verification service is down, allow the email through
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function message(): string
|
||||||
|
{
|
||||||
|
return $this->failMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user