-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove authorized email trait in favour of rule
- Loading branch information
1 parent
297031a
commit 807c790
Showing
6 changed files
with
44 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
app/Http/Controllers/Auth/Traits/AuthorizedDomainTrait.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Rules; | ||
|
||
use Closure; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
|
||
class AuthorizedEmailDomain implements ValidationRule | ||
{ | ||
/** | ||
* Determine if the email is a valid domain. | ||
* | ||
* @return Closure | ||
*/ | ||
public function validate(string $attribute, mixed $value, Closure $fail): void | ||
{ | ||
if (! $this->isEmailDomainAllowed($value)) { | ||
$fail(__('Email domain not allowed')); | ||
} | ||
} | ||
|
||
/** | ||
* Check if the email domain is part of the allowed domains | ||
*/ | ||
private function isEmailDomainAllowed(string $email): bool | ||
{ | ||
$allowedDomains = config('osp.allowed_registration_email_domains'); | ||
|
||
if ($allowedDomains) { | ||
$emailDomain = explode('@', $email)[1]; | ||
if (! in_array($emailDomain, $allowedDomains)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |