Skip to content

Commit 9d4e13c

Browse files
committed
Improve domain restriction
1 parent 69da1f1 commit 9d4e13c

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

Plugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getPluginAuthor()
4747

4848
public function getPluginVersion()
4949
{
50-
return '1.0.6';
50+
return '1.0.7';
5151
}
5252

5353
public function getPluginHomepage()

Test/Validator/RegistrationValidatorTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ public function testWithDomainRestriction()
3939
));
4040

4141
$this->assertTrue($result);
42+
43+
list($result,) = $validator->validateCreation(array(
44+
'username' => 'test',
45+
'email' => 'test@mydomain.tld.example.org',
46+
'password' => 'test123',
47+
'confirmation' => 'test123',
48+
));
49+
50+
$this->assertFalse($result);
51+
52+
list($result,) = $validator->validateCreation(array(
53+
'username' => 'test',
54+
'email' => 'test+mydomain.tld@example.org',
55+
'password' => 'test123',
56+
'confirmation' => 'test123',
57+
));
58+
59+
$this->assertFalse($result);
4260
}
4361

4462
public function testWithMultipleDomainRestriction()

Validator/RegistrationValidator.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ public function validateCreation(array $values)
5555
*/
5656
private function validateDomainRestriction(array $values, $domains)
5757
{
58-
foreach (explode(',', $domains) as $domain) {
59-
$domain = trim($domain);
58+
if (strpos($values['email'], '@') === false) {
59+
return false;
60+
}
6061

61-
if (strpos($values['email'], $domain) > 0) {
62+
list(, $hostname) = explode('@', $values['email']);
63+
$hostname = trim($hostname);
64+
65+
foreach (explode(',', $domains) as $domain) {
66+
if ($hostname === trim($domain)) {
6267
return true;
6368
}
6469
}

0 commit comments

Comments
 (0)