Merge branch 'ticket/r13360-validate-email' into 'master'

Ticket/r13360 validate email

See merge request !13
This commit is contained in:
Michael 2017-06-20 09:58:24 +02:00
commit 2cb1f2c30e
2 changed files with 63 additions and 27 deletions

View File

@ -26,14 +26,22 @@ class AuthController extends AuthControllerCore
$_POST['passwd'] = md5(time()._COOKIE_KEY_);
if (isset($_POST['guest_email']) && $_POST['guest_email'])
$_POST['email'] = $_POST['guest_email'];
// Checked the user address in case he changed his email address
if (Validate::isEmail($email = Tools::getValue('email')) && !empty($email))
if (Customer::customerExists($email))
$this->errors[] = Tools::displayError('An account using this email address has already been registered.', false);
$email = trim(Tools::getValue('email'));
if (empty($email)) {
$this->errors[] = Tools::displayError('An email address required.');
} elseif (!Validate::isEmail($email)) {
$this->errors[] = Tools::displayError('Invalid email address.');
} 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);
}
// Preparing customer
$customer = new Customer();
$lastnameAddress = Tools::getValue('lastname');
$firstnameAddress = Tools::getValue('firstname');
$firstnameAddress = Tools::getValue('firstname');
$_POST['lastname'] = Tools::getValue('customer_lastname', $lastnameAddress);
$_POST['firstname'] = Tools::getValue('customer_firstname', $firstnameAddress);
$addresses_types = array('address');
@ -49,7 +57,7 @@ class AuthController extends AuthControllerCore
if (!Tools::getValue('phone') && !Tools::getValue('phone_mobile'))
$error_phone = true;
}
elseif (((Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && Configuration::get('PS_ORDER_PROCESS_TYPE'))
elseif (((Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && Configuration::get('PS_ORDER_PROCESS_TYPE'))
|| (Configuration::get('PS_ORDER_PROCESS_TYPE') && !Tools::getValue('email_create'))
|| (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && Tools::getValue('email_create')))
&& (!Tools::getValue('phone') && !Tools::getValue('phone_mobile')))
@ -60,7 +68,7 @@ class AuthController extends AuthControllerCore
$passwd_confirm = Tools::getValue('passwd_confirm');
if ($passwd && $passwd_confirm)
{
if($passwd != $passwd_confirm)
if($passwd != $passwd_confirm)
{
$this->errors[] = Tools::displayError('Passwords aren\'t similar');
}
@ -162,7 +170,7 @@ class AuthController extends AuthControllerCore
if (!$country->active)
$this->errors[] = Tools::displayError('This country is not active.');
$postcode = Tools::getValue('postcode');
$postcode = Tools::getValue('postcode');
/* Check zip code format */
if ($country->zip_code_format && !$country->checkZipCode($postcode))
$this->errors[] = sprintf(Tools::displayError('The Zip/Postal code you\'ve entered is invalid. It must follow this format: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
@ -214,7 +222,7 @@ class AuthController extends AuthControllerCore
{
foreach($addresses_types as $addresses_type)
{
$$addresses_type->id_customer = (int)$customer->id;
$$addresses_type->id_customer = (int)$customer->id;
if ($addresses_type == 'address_invoice')
foreach($_POST as $key => &$post)
if (isset($_POST[$key.'_invoice']))
@ -320,4 +328,28 @@ class AuthController extends AuthControllerCore
$this->context->smarty->assign('account_error', $this->errors);
}
}
/**
* Process submit on a creation
*/
protected function processSubmitCreate()
{
if (!Validate::isEmail($email = Tools::getValue('email_create'))
|| 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)) {
$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. Please enter a valid password or request a new one. ', false);
$_POST['email'] = Tools::getValue('email_create');
unset($_POST['email_create']);
}
else
{
$this->create_account = true;
$this->context->smarty->assign('email_create', Tools::safeOutput($email));
$_POST['email'] = $email;
}
}
}

View File

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