Allow wildcards in email domains
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
fffb627844
commit
d18ee78454
|
|
@ -222,7 +222,21 @@ class RegistrationService {
|
|||
|
||||
foreach ($allowedDomains as $domain) {
|
||||
// valid domain, everything's fine
|
||||
if ($mailDomain === $domain) {
|
||||
|
||||
// Wildcards
|
||||
if (strpos($domain, '*') !== false) {
|
||||
// *.example.com
|
||||
// Make save for regex:
|
||||
// \*\.example\.com
|
||||
$regexDomain = preg_quote($domain, '\\');
|
||||
// Replace "\*" with an actual regex wildcard and set start and end:
|
||||
// /^.+\.example\.com$/
|
||||
$regexDomain = '/^' . str_replace('\\*', '.+', $regexDomain) . '$/';
|
||||
|
||||
if (preg_match($regexDomain, $mailDomain)) {
|
||||
return true;
|
||||
}
|
||||
} elseif ($mailDomain === $domain) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,6 +110,8 @@ class RegistrationServiceTest extends TestCase {
|
|||
['aaaa@example.com', 'example.com'],
|
||||
['aaaa@example.com', 'eXample.com'],
|
||||
['aaaa@eXample.com', 'example.com'],
|
||||
['aaaa@cloud.example.com', '*.example.com'],
|
||||
['aaaa@cloud.example.com', 'cloud.example.*'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue