2016-10-04 15:17:02 +02:00

82 lines
2.3 KiB
PHP

<?php
require_once __DIR__ . '/../../config/config.inc.php';
$email = Tools::getValue('email');
$firstname = Tools::getValue('firstname');
$lastname = Tools::getValue('lastname');
$id_gender = Tools::getValue('id_gender') === false ? 1 : intval(Tools::getValue('id_gender'));
$check_b2b = Tools::getValue('check_b2b') === false ? 0 : intval(Tools::getValue('check_b2b'));
if (!Validate::isEmail($email) || mb_strlen($email) > 128)
bad_request('L\'email n\'est invalide.');
if (!Validate::isName($firstname) || mb_strlen($firstname) > 32)
bad_request('Le prénom n\'est pas valide.');
if (!Validate::isName($lastname) || mb_strlen($firstname) > 32)
bad_request('Le nom n\'est pas valide.');
if (!in_array($id_gender, array(1, 2)))
bad_request('Le genre n\'est pas valide.');
if (Customer::customerExists($email))
bad_request('Cet email existe déjà.');
$customer = new Customer();
$customer->email = $email;
$customer->firstname = $firstname;
$customer->lastname = $lastname;
$customer->id_gender = $id_gender;
$customer->date_add = date('Y-m-d H:i:s');
$customer->is_affilnet_lead = true;
$password_tmp = Tools::passwdGen();
$customer->passwd = Tools::encrypt($password_tmp);
$customer->active = 1;
$customer->newsletter = 1;
$customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr());
$customer->is_guest = 0;
$customer->pro = $check_b2b;
$sent = Mail::Send(
1,
'account',
Mail::l('Welcome!'),
array(
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{email}' => $customer->email,
'{passwd}' => $password_tmp,
),
$customer->email,
$customer->firstname.' '.$customer->lastname
);
if ($sent && $customer->add()) {
Hook::exec('actionCustomerAccountAdd', array(
'_POST' => array(
'firstname' => $customer->firstname,
'lastname' => $customer->lastname,
'email' => $customer->email,
'id_gender' => $customer->id_gender,
'check_b2b' => $check_b2b,
),
'newCustomer' => $customer
));
} else {
$sent === false ? error(1) : error(2);
}
//close connection
curl_close($ch);
function error($type) {
header('HTTP/1.1 400 Bad Request', true, 400);
echo $type === 1 ?
"L'envoie du mail a échoué." :
"Un erreur serveur inattendue est survenue.";
}
function bad_request($message)
{
header('HTTP/1.1 400 Bad Request', true, 400);
echo $message;
}