consolidate email validation checks

This commit is contained in:
zotlabs 2017-05-11 19:01:04 -07:00
parent 4f577cbdeb
commit 1de1b58a08
5 changed files with 3 additions and 28 deletions

View File

@ -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;
}

View File

@ -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)) {

View File

@ -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');

View File

@ -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.
*

View File

@ -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<br />