New regex to validate email
This commit is contained in:
parent
1febb99865
commit
b5f083a63a
@ -32,7 +32,7 @@ class AuthController extends AuthControllerCore
|
||||
$this->errors[] = Tools::displayError('An email address required.');
|
||||
} elseif (!Validate::isEmail($email)) {
|
||||
$this->errors[] = Tools::displayError('Invalid email address.');
|
||||
} elseif (!preg_match('/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD', $email)) {
|
||||
} elseif (!preg_match('/^(?=[A-Z0-9][A-Z0-9@._%+-]{5,253}+$)[A-Z0-9._%+-]{1,64}+@(?:(?=[A-Z0-9-]{1,63}+\.)[A-Z0-9]++(?:-[A-Z0-9]++)*+\.){1,8}+[A-Z]{2,63}+$/i', $email)) {
|
||||
$this->errors[] = Tools::displayError('Invalid email address.');
|
||||
} elseif (Customer::customerExists($email)) {
|
||||
$this->errors[] = Tools::displayError('An account using this email address has already been registered.', false);
|
||||
|
@ -19,7 +19,9 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
|
||||
public function ajaxCall($email, $action = 0, $page, $id_post = false)
|
||||
{
|
||||
if (empty($email) || !Validate::isEmail($email)) {
|
||||
if (empty($email)
|
||||
|| !preg_match('/^(?=[A-Z0-9][A-Z0-9@._%+-]{5,253}+$)[A-Z0-9._%+-]{1,64}+@(?:(?=[A-Z0-9-]{1,63}+\.)[A-Z0-9]++(?:-[A-Z0-9]++)*+\.){1,8}+[A-Z]{2,63}+$/i', $email)
|
||||
|| !Validate::isEmail($email)) {
|
||||
return array(
|
||||
'has_error' => true,
|
||||
'css' => 'alert alert-danger',
|
||||
@ -90,7 +92,9 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
*/
|
||||
protected function newsletterRegistration()
|
||||
{
|
||||
if (empty($_POST['email']) || !Validate::isEmail($_POST['email'])) {
|
||||
if (empty($_POST['email'])
|
||||
|| !preg_match('/^(?=[A-Z0-9][A-Z0-9@._%+-]{5,253}+$)[A-Z0-9._%+-]{1,64}+@(?:(?=[A-Z0-9-]{1,63}+\.)[A-Z0-9]++(?:-[A-Z0-9]++)*+\.){1,8}+[A-Z]{2,63}+$/i', $_POST['email'])
|
||||
|| !Validate::isEmail($_POST['email'])) {
|
||||
return $this->error = $this->l('Invalid email address.');
|
||||
} else if ($_POST['action'] == '1') {
|
||||
/* Unsubscription */
|
||||
@ -122,7 +126,7 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
$content = '';
|
||||
if (glob(_CMS_CAT_IMG_DIR_.'pdf/Tout-pratique.pdf')) {
|
||||
$content = file_get_contents(_CMS_CAT_IMG_DIR_.'pdf/Tout-pratique.pdf');
|
||||
}
|
||||
}
|
||||
$genericPdf = array(
|
||||
'content' => $content,
|
||||
'name' => 'Tout-pratique.pdf',
|
||||
@ -157,10 +161,10 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
return $this->error = $this->l('This email address is already registered.');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// envoi le pdf de la categorie
|
||||
elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $cmsCategory != false) {
|
||||
// enregistrement pour la categorie si pas enregistré
|
||||
// enregistrement pour la categorie si pas enregistré
|
||||
if ($this->isNewsletterCmsPsRegistered($email, $cmsCategory['id_category'], $register_status)) {
|
||||
// $this->valid = $this->l('You will recieve your PDF.');
|
||||
$this->valid = 'Vous allez reçevoir votre PDF.';
|
||||
@ -198,7 +202,7 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
$this->sendVoucher($email, Configuration::get('NW_VOUCHER_CODE'));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// envoi le pdf de la categorie
|
||||
elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $cmsCategory != false) {
|
||||
if($this->isNewsletterCmsPsRegistered($email, $cmsCategory['id_category'], $register_status)){
|
||||
@ -206,12 +210,12 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
$already_send = true;
|
||||
} else {
|
||||
return $this->error = $this->l('An error occurred during the subscription process.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// envoi le pdf générique
|
||||
elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $genericPdf != false) {
|
||||
$this->sendConfirmationEmail($email, false, $genericPdf);
|
||||
$this->sendConfirmationEmail($email, false, $genericPdf);
|
||||
$already_send = true;
|
||||
}
|
||||
/*}*/
|
||||
@ -222,7 +226,7 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
$content = '';
|
||||
if (glob(_CMS_CAT_IMG_DIR_.'pdf/Tout-pratique.pdf')) {
|
||||
$content = file_get_contents(_CMS_CAT_IMG_DIR_.'pdf/Tout-pratique.pdf');
|
||||
}
|
||||
}
|
||||
$genericPdf = array(
|
||||
'content' => $content,
|
||||
'name' => 'Tout-pratique.pdf',
|
||||
@ -323,7 +327,7 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
SELECT c.`id_customer`
|
||||
FROM '._DB_PREFIX_.'customer c
|
||||
WHERE c.`email` = \''.pSQL($email).'\'
|
||||
AND c.`newsletter` = \'1\'
|
||||
AND c.`newsletter` = \'1\'
|
||||
AND id_shop = '.$this->context->shop->id.'
|
||||
)
|
||||
)';
|
||||
@ -331,7 +335,7 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
|
||||
if(Db::getInstance()->execute($sql)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -361,7 +365,7 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
{
|
||||
if ($register_status == self::GUEST_REGISTERED) {
|
||||
$sql = 'DELETE FROM '._DB_PREFIX_.'newsletter_cmsps nc
|
||||
WHERE nc.`id_newsletter` =
|
||||
WHERE nc.`id_newsletter` =
|
||||
(
|
||||
SELECT n.`id`
|
||||
FROM '._DB_PREFIX_.'newsletter n
|
||||
@ -370,19 +374,19 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
)';
|
||||
} elseif ($register_status == self::CUSTOMER_REGISTERED) {
|
||||
$sql = 'DELETE FROM '._DB_PREFIX_.'newsletter_cmsps nc
|
||||
WHERE nc.`id_customer` =
|
||||
WHERE nc.`id_customer` =
|
||||
(
|
||||
SELECT c.`id_customer`
|
||||
FROM '._DB_PREFIX_.'customer c
|
||||
WHERE c.`email` = \''.pSQL($email).'\'
|
||||
AND c.`newsletter` = \'1\'
|
||||
AND c.`newsletter` = \'1\'
|
||||
AND id_shop = '.$this->context->shop->id.'
|
||||
)';
|
||||
}
|
||||
|
||||
if(Db::getInstance()->execute($sql)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -398,7 +402,7 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
if (glob(_CMS_CAT_IMG_DIR_.'pdf/Tout-pratique-'.$cmsCategory['slug'].'.pdf')) {
|
||||
$fileAttachment['content'] = file_get_contents(_CMS_CAT_IMG_DIR_.'pdf/Tout-pratique-'.$cmsCategory['slug'].'.pdf');
|
||||
$fileAttachment['name'] = 'Tout-pratique-'.$cmsCategory['slug'].'.pdf';
|
||||
$fileAttachment['mime'] = "application/pdf";
|
||||
$fileAttachment['mime'] = "application/pdf";
|
||||
|
||||
$data['{attached_file_url}'] = _PS_BASE_URL_.'/img/cms_c/pdf/Tout-pratique-'.$cmsCategory['slug'].'.pdf';
|
||||
$data['{attached_file}'] = "Tout-pratique-".$cmsCategory['slug'];
|
||||
@ -408,7 +412,7 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
$fileAttachment['content'] = file_get_contents(_CMS_CAT_IMG_DIR_.'pdf/Tout-pratique.pdf');
|
||||
}
|
||||
$fileAttachment['name'] = 'Tout-pratique.pdf';
|
||||
$fileAttachment['mime'] = "application/pdf";
|
||||
$fileAttachment['mime'] = "application/pdf";
|
||||
$data['{attached_file_url}'] = _PS_BASE_URL_.'/img/cms_c/pdf/Tout-pratique.pdf';
|
||||
$data['{attached_file}'] = "Tout-pratique";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user