From 1de1b58a087afbadb55b7f18b93fb0b502a2de3a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 11 May 2017 19:01:04 -0700 Subject: consolidate email validation checks --- Zotlabs/Module/Invite.php | 2 +- Zotlabs/Module/Settings/Account.php | 2 +- include/account.php | 2 +- include/text.php | 13 ------------- tests/unit/includes/TextTest.php | 12 ------------ 5 files changed, 3 insertions(+), 28 deletions(-) diff --git a/Zotlabs/Module/Invite.php b/Zotlabs/Module/Invite.php index 6b6f80a31..927e7beae 100644 --- a/Zotlabs/Module/Invite.php +++ b/Zotlabs/Module/Invite.php @@ -49,7 +49,7 @@ class Invite extends \Zotlabs\Web\Controller { if(! $recip) continue; - if(! valid_email($recip)) { + if(! validate_email($recip)) { notice( sprintf( t('%s : Not a valid email address.'), $recip) . EOL); continue; } diff --git a/Zotlabs/Module/Settings/Account.php b/Zotlabs/Module/Settings/Account.php index ec176797d..18890e89f 100644 --- a/Zotlabs/Module/Settings/Account.php +++ b/Zotlabs/Module/Settings/Account.php @@ -16,7 +16,7 @@ class Account { $account = \App::get_account(); if($email != $account['account_email']) { - if(! valid_email($email)) + if(! validate_email($email)) $errs[] = t('Not valid email.'); $adm = trim(get_config('system','admin_email')); if(($adm) && (strcasecmp($email,$adm) == 0)) { diff --git a/include/account.php b/include/account.php index 5e57d53a8..c188ce0d7 100644 --- a/include/account.php +++ b/include/account.php @@ -31,7 +31,7 @@ function check_account_email($email) { if(! strlen($email)) return $result; - if((! valid_email($email)) || (! validate_email($email))) + if(! validate_email($email)) $result['message'] .= t('Not a valid email address') . EOL; elseif(! allowed_email($email)) $result['message'] = t('Your email domain is not among those allowed on this site'); diff --git a/include/text.php b/include/text.php index dc01f97bd..fb39313a2 100644 --- a/include/text.php +++ b/include/text.php @@ -1042,19 +1042,6 @@ function searchbox($s,$id='search-box',$url='/search',$save = false) { )); } -function valid_email_regex($x){ - if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x)) - return true; - return false; -} - -function valid_email($x){ - if(get_config('system','disable_email_validation')) - return true; - - return valid_email_regex($x); -} - /** * @brief Replace naked text hyperlink with HTML formatted hyperlink. * diff --git a/tests/unit/includes/TextTest.php b/tests/unit/includes/TextTest.php index e2c7cbb9a..25a997f7a 100644 --- a/tests/unit/includes/TextTest.php +++ b/tests/unit/includes/TextTest.php @@ -11,18 +11,6 @@ use Zotlabs\Tests\Unit\UnitTestCase; */ class TextTest extends UnitTestCase { - public function testGoodEmail() { - $this->assertTrue(valid_email_regex('ken@spaz.org')); - $this->assertTrue(valid_email_regex('ken@restivo.org')); - $this->assertTrue(valid_email_regex('nobody@hubzilla.org')); - $this->assertTrue(valid_email_regex('foo+nobody@hubzilla.org')); - } - - public function testBadEmail() { - $this->assertFalse(valid_email_regex('nobody!uses!these!any.more')); - $this->assertFalse(valid_email_regex('foo@bar@hubzilla.org')); - } - public function testPurifyHTML() { // linebreaks $htmlbr = 'first line
-- cgit v1.2.3