本文整理汇总了PHP中Customer::validateControler方法的典型用法代码示例。如果您正苦于以下问题:PHP Customer::validateControler方法的具体用法?PHP Customer::validateControler怎么用?PHP Customer::validateControler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Customer
的用法示例。
在下文中一共展示了Customer::validateControler方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initContent
//.........这里部分代码省略.........
} else {
if (!Validate::isEmail($response_email)) {
$this->errors[] = Tools::displayError('Invalid email address.');
} else {
if (Customer::customerExists($response_email)) {
// Need to clean up the code here most of it is from
// IDFBCon_v.0.2 (Chandra R. Atmaja <chandra.r.atmaja@gmail.com>)
// Someone has already registered with this e-mail address
// This will link the 1st existing email/account on site with Facebook
// and log the user in to the account. Is this safe?
$customer = new Customer();
$authentication = $customer->getByEmail($response['registration']['email']);
// This is done to see if a existing users try's to re-registrar
$sql = 'SELECT `facebook_id`
FROM `' . _DB_PREFIX_ . 'customer_profile_connect`
WHERE `id_customer` = \'' . (int) $customer->id . '\' ' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER);
$customer_fb_id = Db::getInstance()->getValue($sql);
if ($customer_fb_id) {
if ($customer_fb_id == (int) $response['user_id']) {
Tools::redirect($this->context->link->getModuleLink('fbconnect_psb', 'login', array(), false, $this->context->language->id));
} else {
$this->errors[] = Tools::displayError('An error occurred while linking your Facebook account.');
}
} else {
if (Db::getInstance()->insert('customer_profile_connect', array('id_customer' => (int) $customer->id, 'facebook_id' => (int) $response['user_id']))) {
$this->errors[] = Tools::displayError('an error occurred while linking your Facebook account.');
}
$customer->active = 1;
$customer->deleted = 0;
$this->context->cookie->id_customer = intval($customer->id);
$this->context->cookie->customer_lastname = $customer->lastname;
$this->context->cookie->customer_firstname = $customer->firstname;
$this->context->cookie->logged = 1;
$this->context->cookie->passwd = $customer->passwd;
$this->context->cookie->email = $customer->email;
if (Configuration::get('PS_CART_FOLLOWING') and (empty($this->context->cookie->id_cart) or Cart::getNbProducts($this->context->cookie->id_cart) == 0)) {
$this->context->cookie->id_cart = intval(Cart::lastNoneOrderedCart(intval($customer->id)));
}
Module::hookExec('authentication');
if ($back = Tools::getValue('back')) {
Tools::redirect($back);
}
Tools::redirect('index.php?controller=my-account');
}
}
}
}
if (!sizeof($this->errors)) {
// TODO: use this->context for customer instead of new object?
// Need to clean up the code here most of it is from
// IDFBCon_v.0.2 (Chandra R. Atmaja <chandra.r.atmaja@gmail.com>)
$customer = new Customer();
$customer_birthday = explode('/', $response['registration']['birthday']);
$customer->birthday = intval($customer_birthday[2]) . '-' . intval($customer_birthday[0]) . '-' . intval($customer_birthday[1]);
if ($response['registration']['last_name'] == "male") {
$_POST['id_gender'] = 1;
} else {
if ($response['registration']['last_name'] == "female") {
$_POST['id_gender'] = 2;
} else {
$_POST['id_gender'] = 0;
}
}
$_POST['lastname'] = $response['registration']['last_name'];
$_POST['firstname'] = $response['registration']['first_name'];
$_POST['passwd'] = $response['registration']['password'];
$_POST['email'] = $response['registration']['email'];
$this->errors = $customer->validateControler();
if (!sizeof($this->errors)) {
$customer->active = 1;
if (!$customer->add()) {
$this->errors[] = Tools::displayError('an error occurred while creating your account');
} else {
if (Db::getInstance()->insert('customer_profile_connect', array('id_customer' => (int) $customer->id, 'facebook_id' => (int) $response['user_id']))) {
$this->errors[] = Tools::displayError('an error occurred while linking your Facebook account.');
}
$email_var = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => $response['registration']['password']);
if (!Mail::Send(intval($this->context->cookie->id_lang), 'account', 'Welcome!', $email_var, $customer->email, $customer->firstname . ' ' . $customer->lastname)) {
$this->errors[] = Tools::displayError('cannot send email');
}
$this->context->smarty->assign('confirmation', 1);
$this->context->cookie->id_customer = intval($customer->id);
$this->context->cookie->customer_lastname = $customer->lastname;
$this->context->cookie->customer_firstname = $customer->firstname;
$this->context->cookie->passwd = $customer->passwd;
$this->context->cookie->logged = 1;
$this->context->cookie->email = $customer->email;
Module::hookExec('createAccount', array('_POST' => $_POST, 'newCustomer' => $customer));
if ($back) {
Tools::redirect($back);
}
Tools::redirect('index.php?controller=my-account');
}
}
}
}
$useSSL = isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode() ? true : false;
$this->context->smarty->assign(array('redirect_uri' => $this->redirect_uri, 'protocol_content' => $useSSL ? 'https://' : 'http://', 'fb_connect_appid' => $fb_connect_appid));
$this->setTemplate('registration_fb.tpl');
}
示例2: preProcess
public function preProcess()
{
parent::preProcess();
$customer = new Customer((int) self::$cookie->id_customer);
if (sizeof($_POST)) {
$exclusion = array('secure_key', 'old_passwd', 'passwd', 'active', 'date_add', 'date_upd', 'last_passwd_gen', 'newsletter_date_add', 'id_default_group');
$fields = $customer->getFields();
foreach ($fields as $key => $value) {
if (!in_array($key, $exclusion)) {
$customer->{$key} = key_exists($key, $_POST) ? trim($_POST[$key]) : 0;
}
}
}
if (isset($_POST['years']) and isset($_POST['months']) and isset($_POST['days'])) {
$customer->birthday = (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
}
if (Tools::isSubmit('submitIdentity')) {
if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) and !(Tools::getValue('months') == '' and Tools::getValue('days') == '' and Tools::getValue('years') == '')) {
$this->errors[] = Tools::displayError('Invalid date of birth');
} else {
$customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
$_POST['old_passwd'] = trim($_POST['old_passwd']);
if (empty($_POST['old_passwd']) or Tools::encrypt($_POST['old_passwd']) != self::$cookie->passwd) {
$this->errors[] = Tools::displayError('Your password is incorrect.');
} elseif ($_POST['passwd'] != $_POST['confirmation']) {
$this->errors[] = Tools::displayError('Password and confirmation do not match');
} else {
$prev_id_default_group = $customer->id_default_group;
$this->errors = $customer->validateControler();
}
if (!sizeof($this->errors)) {
$customer->id_default_group = (int) $prev_id_default_group;
$customer->firstname = Tools::ucfirst(Tools::strtolower($customer->firstname));
if (Tools::getValue('passwd')) {
self::$cookie->passwd = $customer->passwd;
}
if ($customer->update()) {
self::$cookie->customer_lastname = $customer->lastname;
self::$cookie->customer_firstname = $customer->firstname;
self::$smarty->assign('confirmation', 1);
} else {
$this->errors[] = Tools::displayError('Cannot update information');
}
}
}
} else {
$_POST = array_map('stripslashes', $customer->getFields());
}
if ($customer->birthday) {
$birthday = explode('-', $customer->birthday);
} else {
$birthday = array('-', '-', '-');
}
/* Generate years, months and days */
self::$smarty->assign(array('years' => Tools::dateYears(), 'sl_year' => $birthday[0], 'months' => Tools::dateMonths(), 'sl_month' => $birthday[1], 'days' => Tools::dateDays(), 'sl_day' => $birthday[2], 'errors' => $this->errors));
self::$smarty->assign('newsletter', (int) Module::getInstanceByName('blocknewsletter')->active);
}
示例3: elseif
$errors[] = $error[$validateDni];
} elseif (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) and !(Tools::getValue('months') == '' and Tools::getValue('days') == '' and Tools::getValue('years') == '')) {
$errors[] = Tools::displayError('invalid birthday');
} else {
$customer = new Customer();
if (Tools::isSubmit('newsletter')) {
$customer->ip_registration_newsletter = pSQL($_SERVER['REMOTE_ADDR']);
$customer->newsletter_date_add = pSQL(date('Y-m-d H:i:s'));
}
$customer->birthday = empty($_POST['years']) ? '' : intval($_POST['years']) . '-' . intval($_POST['months']) . '-' . intval($_POST['days']);
/* Customer and address, same fields, caching data */
$addrLastname = isset($_POST['lastname']) ? $_POST['lastname'] : $_POST['customer_lastname'];
$addrFirstname = isset($_POST['firstname']) ? $_POST['firstname'] : $_POST['customer_firstname'];
$_POST['lastname'] = $_POST['customer_lastname'];
$_POST['firstname'] = $_POST['customer_firstname'];
$errors = $customer->validateControler();
$_POST['lastname'] = $addrLastname;
$_POST['firstname'] = $addrFirstname;
$address = new Address();
$address->id_customer = 1;
$errors = array_unique(array_merge($errors, $address->validateControler()));
if (!sizeof($errors)) {
if (!($country = new Country($address->id_country)) or !Validate::isLoadedObject($country)) {
die(Tools::displayError());
}
if (intval($country->contains_states) and !intval($address->id_state)) {
$errors[] = Tools::displayError('this country require a state selection');
} else {
$customer->active = 1;
if (!$customer->add()) {
$errors[] = Tools::displayError('an error occurred while creating your account');
示例4: preProcess
public function preProcess()
{
parent::preProcess();
if (self::$cookie->isLogged() and !Tools::isSubmit('ajax')) {
Tools::redirect('my-account.php');
}
if (Tools::getValue('create_account')) {
$create_account = 1;
self::$smarty->assign('email_create', 1);
}
if (Tools::isSubmit('SubmitCreate')) {
if (!Validate::isEmail($email = Tools::getValue('email_create')) or empty($email)) {
$this->errors[] = Tools::displayError('Invalid e-mail address');
} elseif (Customer::customerExists($email)) {
$this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.');
$_POST['email'] = $_POST['email_create'];
unset($_POST['email_create']);
} else {
$create_account = 1;
self::$smarty->assign('email_create', Tools::safeOutput($email));
$_POST['email'] = $email;
}
}
if (Tools::isSubmit('submitAccount') or Tools::isSubmit('submitGuestAccount')) {
$create_account = 1;
if (Tools::isSubmit('submitAccount')) {
self::$smarty->assign('email_create', 1);
}
/* New Guest customer */
if (!Tools::getValue('is_new_customer', 1) and !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
$this->errors[] = Tools::displayError('You cannot create a guest account.');
}
if (!Tools::getValue('is_new_customer', 1)) {
$_POST['passwd'] = md5(time() . _COOKIE_KEY_);
}
if (isset($_POST['guest_email']) and $_POST['guest_email']) {
$_POST['email'] = $_POST['guest_email'];
}
/* Preparing customer */
$customer = new Customer();
$lastnameAddress = $_POST['lastname'];
$firstnameAddress = $_POST['firstname'];
$_POST['lastname'] = $_POST['customer_lastname'];
$_POST['firstname'] = $_POST['customer_firstname'];
if (!Tools::getValue('phone') and !Tools::getValue('phone_mobile')) {
$this->errors[] = Tools::displayError('You must register at least one phone number');
}
if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) and !(Tools::getValue('months') == '' and Tools::getValue('days') == '' and Tools::getValue('years') == '')) {
$this->errors[] = Tools::displayError('Invalid date of birth');
}
$customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
$this->errors = array_unique(array_merge($this->errors, $customer->validateControler()));
/* Preparing address */
$address = new Address();
$_POST['lastname'] = $lastnameAddress;
$_POST['firstname'] = $firstnameAddress;
$address->id_customer = 1;
$this->errors = array_unique(array_merge($this->errors, $address->validateControler()));
/* US customer: normalize the address */
if ($address->id_country == Country::getByIso('US')) {
include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
$normalize = new AddressStandardizationSolution();
$address->address1 = $normalize->AddressLineStandardization($address->address1);
$address->address2 = $normalize->AddressLineStandardization($address->address2);
}
$zip_code_format = Country::getZipCodeFormat((int) Tools::getValue('id_country'));
if (Country::getNeedZipCode((int) Tools::getValue('id_country'))) {
if ($postcode = Tools::getValue('postcode') and $zip_code_format) {
$zip_regexp = '/^' . $zip_code_format . '$/ui';
$zip_regexp = str_replace(' ', '( |)', $zip_regexp);
$zip_regexp = str_replace('-', '(-|)', $zip_regexp);
$zip_regexp = str_replace('N', '[0-9]', $zip_regexp);
$zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp);
$zip_regexp = str_replace('C', Country::getIsoById((int) Tools::getValue('id_country')), $zip_regexp);
if (!preg_match($zip_regexp, $postcode)) {
$this->errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', Country::getIsoById((int) Tools::getValue('id_country')), str_replace('N', '0', str_replace('L', 'A', $zip_code_format)));
}
} elseif ($zip_code_format) {
$this->errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is required.');
} elseif ($postcode and !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
$this->errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.');
}
}
if (Country::isNeedDniByCountryId($address->id_country) and (!Tools::getValue('dni') or !Validate::isDniLite(Tools::getValue('dni')))) {
$this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
} elseif (!Country::isNeedDniByCountryId($address->id_country)) {
$address->dni = NULL;
}
if (!sizeof($this->errors)) {
if (Customer::customerExists(Tools::getValue('email'))) {
$this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.');
}
if (Tools::isSubmit('newsletter')) {
$customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr());
$customer->newsletter_date_add = pSQL(date('Y-m-d H:i:s'));
}
if (!sizeof($this->errors)) {
if (!($country = new Country($address->id_country, Configuration::get('PS_LANG_DEFAULT'))) or !Validate::isLoadedObject($country)) {
die(Tools::displayError());
}
//.........这里部分代码省略.........
示例5: submitAccount
function submitAccount()
{
global $cookie, $errors, $smarty;
$email = Tools::getValue('email');
if (empty($email) or !Validate::isEmail($email)) {
$errors[] = Tools::displayError('e-mail not valid');
} elseif (!Validate::isPasswd(Tools::getValue('passwd'))) {
$errors[] = Tools::displayError('invalid password');
} elseif (Customer::customerExists($email)) {
$errors[] = Tools::displayError('someone has already registered with this e-mail address');
} elseif (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) and !(Tools::getValue('months') == '' and Tools::getValue('days') == '' and Tools::getValue('years') == '')) {
$errors[] = Tools::displayError('invalid birthday');
} else {
$customer = new Customer();
if (Tools::isSubmit('newsletter')) {
$customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr());
$customer->newsletter_date_add = pSQL(date('Y-m-d h:i:s'));
}
$customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
/* Customer and address, same fields, caching data */
$errors = $customer->validateControler();
$address = new Address();
$address->id_customer = 1;
$errors = array_unique(array_merge($errors, $address->validateControler()));
if (!sizeof($errors)) {
$customer->active = 1;
if (!$customer->add()) {
$errors[] = Tools::displayError('an error occurred while creating your account');
} else {
$address->id_customer = (int) $customer->id;
if (!$address->add()) {
$errors[] = Tools::displayError('an error occurred while creating your address');
} else {
if (Mail::Send((int) $cookie->id_lang, 'account', Mail::l('Welcome!', (int) $cookie->id_lang), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd')), $customer->email, $customer->firstname . ' ' . $customer->lastname)) {
$smarty->assign('confirmation', 1);
}
$cookie->id_customer = (int) $customer->id;
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->passwd = $customer->passwd;
$cookie->logged = 1;
$cookie->email = $customer->email;
Module::hookExec('createAccount', array('_POST' => $_POST, 'newCustomer' => $customer));
// Next !
$payerID = strval(Tools::getValue('payerID'));
displayProcess($payerID);
}
}
}
}
}
示例6: preProcess
public function preProcess()
{
parent::preProcess();
if ($this->nbProducts) {
self::$smarty->assign('virtual_cart', false);
}
$this->isLogged = (bool) ((int) self::$cookie->id_customer and Customer::customerIdExistsStatic((int) self::$cookie->id_customer));
if (self::$cart->nbProducts()) {
if (Tools::isSubmit('ajax')) {
if (Tools::isSubmit('method')) {
switch (Tools::getValue('method')) {
case 'updateMessage':
if (Tools::isSubmit('message')) {
$txtMessage = urldecode(Tools::getValue('message'));
$this->_updateMessage($txtMessage);
if (sizeof($this->errors)) {
die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
}
die(true);
}
break;
case 'updateCarrierAndGetPayments':
if (Tools::isSubmit('id_carrier') and Tools::isSubmit('recyclable') and Tools::isSubmit('gift') and Tools::isSubmit('gift_message')) {
if ($this->_processCarrier()) {
$return = array('summary' => self::$cart->getSummaryDetails(), 'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods());
die(Tools::jsonEncode($return));
} else {
$this->errors[] = Tools::displayError('Error occurred updating cart.');
}
if (sizeof($this->errors)) {
die('{"hasError" : true, "errors" : ["' . implode('\',\'', $this->errors) . '"]}');
}
exit;
}
break;
case 'updateTOSStatusAndGetPayments':
if (Tools::isSubmit('checked')) {
self::$cookie->checkedTOS = (int) Tools::getValue('checked');
die(Tools::jsonEncode(array('HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods())));
}
break;
case 'getCarrierList':
die(Tools::jsonEncode($this->_getCarrierList()));
break;
case 'editCustomer':
if (!$this->isLogged) {
exit;
}
$customer = new Customer((int) self::$cookie->id_customer);
if (Tools::getValue('years')) {
$customer->birthday = (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days');
}
$_POST['lastname'] = $_POST['customer_lastname'];
$_POST['firstname'] = $_POST['customer_firstname'];
$this->errors = $customer->validateControler();
$customer->newsletter = (int) Tools::isSubmit('newsletter');
$customer->optin = (int) Tools::isSubmit('optin');
$return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_customer' => (int) self::$cookie->id_customer, 'token' => Tools::getToken(false));
if (!sizeof($this->errors)) {
$return['isSaved'] = (bool) $customer->update();
} else {
$return['isSaved'] = false;
}
die(Tools::jsonEncode($return));
break;
case 'getAddressBlockAndCarriersAndPayments':
if (self::$cookie->isLogged()) {
// check if customer have addresses
if (!Customer::getAddressesTotalById((int) self::$cookie->id_customer)) {
die(Tools::jsonEncode(array('no_address' => 1)));
}
if (file_exists(_PS_MODULE_DIR_ . 'blockuserinfo/blockuserinfo.php')) {
include_once _PS_MODULE_DIR_ . 'blockuserinfo/blockuserinfo.php';
$blockUserInfo = new BlockUserInfo();
}
self::$smarty->assign('isVirtualCart', self::$cart->isVirtualCart());
$this->_processAddressFormat();
$this->_assignAddress();
// Wrapping fees
$wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
$wrapping_fees_tax = new Tax((int) Configuration::get('PS_GIFT_WRAPPING_TAX'));
$wrapping_fees_tax_inc = $wrapping_fees * (1 + (double) $wrapping_fees_tax->rate / 100);
$return = array('summary' => self::$cart->getSummaryDetails(), 'order_opc_adress' => self::$smarty->fetch(_PS_THEME_DIR_ . 'order-address.tpl'), 'block_user_info' => isset($blockUserInfo) ? $blockUserInfo->hookTop(array()) : '', 'carrier_list' => $this->_getCarrierList(), 'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'no_address' => 0, 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int) self::$cookie->id_currency))));
die(Tools::jsonEncode($return));
}
die(Tools::displayError());
break;
case 'makeFreeOrder':
/* Bypass payment step if total is 0 */
if ($id_order = $this->_checkFreeOrder() and $id_order) {
$email = self::$cookie->email;
if (self::$cookie->is_guest) {
self::$cookie->logout();
}
// If guest we clear the cookie for security reason
die('freeorder:' . $id_order . ':' . $email);
}
exit;
break;
case 'updateAddressesSelected':
//.........这里部分代码省略.........
示例7: handleBuyerRegisterUserPassword
public function handleBuyerRegisterUserPassword($metadata, $request, $encoder)
{
// prepare the fields inside the POST (so we can use Prestashop's validateController)
unset($_POST['email']);
if (isset($request['Buyer']['Username'])) {
$_POST['email'] = $request['Buyer']['Username'];
}
unset($_POST['passwd']);
if (isset($request['Buyer']['Password'])) {
$_POST['passwd'] = $request['Buyer']['Password'];
}
unset($_POST['firstname']);
if (isset($request['Buyer']['FirstName'])) {
$_POST['firstname'] = $request['Buyer']['FirstName'];
}
unset($_POST['lastname']);
if (isset($request['Buyer']['LastName'])) {
$_POST['lastname'] = $request['Buyer']['LastName'];
}
// verify fields are valid
$customer = new Customer();
if (_PS_VERSION_ < '1.5') {
$errors = $customer->validateControler();
} else {
$errors = $customer->validateController();
}
if (is_array($errors) && count($errors) > 0) {
CartAPI_Helpers::dieOnError($encoder, 'RegisterNotAuthorized', CartAPI_Handlers_Helpers::removeHtmlTags($errors[0]));
}
// make sure the customer doesn't already exist
if (Customer::customerExists($_POST['email'])) {
CartAPI_Helpers::dieOnError($encoder, 'RegisterNotAuthorized', CartAPI_Handlers_Helpers::removeHtmlTags(Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.')));
}
// add the new user
$customer->active = 1;
if (property_exists('Customer', 'is_guest')) {
$customer->is_guest = 0;
}
if (!$customer->add()) {
CartAPI_Helpers::dieOnError($encoder, 'RegisterNotAuthorized', CartAPI_Handlers_Helpers::removeHtmlTags(Tools::displayError('An error occurred while creating your account.')));
}
// see if we need to login too
if (!isset($request['Login']) || $request['Login'] == 'true') {
$cookie = $this->syncCookie($customer);
// run the after login events, actually don't since prestashop AuthController doesn't do it
// $this->afterBuyerLogin($customer);
}
// run the after register events
$this->afterBuyerRegister($customer, $request['Buyer']);
}
示例8: createCustomerGuestAccount
public function createCustomerGuestAccount($encoder, $buyerDictionary, $addressDictionary = array())
{
global $cookie;
// taken from AuthController
// no need to create if already logged in and has a customer id
if ($cookie->logged && $cookie->id_customer) {
return;
}
// make sure we can create a guest account
if (!Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
CartAPI_Helpers::dieOnError($encoder, 'RegisterNotAuthorized', CartAPI_Handlers_Helpers::removeHtmlTags(Tools::displayError('You cannot create a guest account.')));
}
// prepare the fields inside the POST (so we can use Prestashop's validateController)
unset($_POST['email']);
if (isset($buyerDictionary['Email'])) {
$_POST['email'] = $buyerDictionary['Email'];
}
unset($_POST['passwd']);
$_POST['passwd'] = md5(time() . _COOKIE_KEY_);
unset($_POST['firstname']);
if (isset($addressDictionary['FirstName'])) {
$_POST['firstname'] = $addressDictionary['FirstName'];
}
// take from address as backup
if (isset($buyerDictionary['FirstName'])) {
$_POST['firstname'] = $buyerDictionary['FirstName'];
}
// take from buyer if given
unset($_POST['lastname']);
if (isset($addressDictionary['LastName'])) {
$_POST['lastname'] = $addressDictionary['LastName'];
}
// take from address as backup
if (isset($buyerDictionary['LastName'])) {
$_POST['lastname'] = $buyerDictionary['LastName'];
}
// take from buyer if given
// verify fields are valid
$customer = new Customer();
if (_PS_VERSION_ < '1.5') {
$errors = $customer->validateControler();
} else {
$errors = $customer->validateController();
}
if (is_array($errors) && count($errors) > 0) {
CartAPI_Helpers::dieOnError($encoder, 'RegisterNotAuthorized', CartAPI_Handlers_Helpers::removeHtmlTags($errors[0]));
}
// add the new user
$customer->active = 1;
$customer->is_guest = 1;
if (!$customer->add()) {
CartAPI_Helpers::dieOnError($encoder, 'RegisterNotAuthorized', CartAPI_Handlers_Helpers::removeHtmlTags(Tools::displayError('An error occurred while creating your account.')));
}
// sync the cookie
$loginHandler = CartAPI_Handlers_Helpers::newHandlerInstance($encoder, 'Login');
$loginHandler->syncCookie($customer);
}
示例9: preProcess
public function preProcess()
{
parent::preProcess();
if (self::$cookie->isLogged() and !Tools::isSubmit('ajax')) {
Tools::redirect('history.php');
}
if (Tools::getValue('create_account')) {
$create_account = 1;
self::$smarty->assign('email_create', 1);
}
if (Tools::isSubmit('SubmitCreate')) {
if (!Validate::isEmail($email = Tools::getValue('email_create')) or empty($email)) {
$this->errors[] = Tools::displayError('Invalid e-mail address');
} elseif (Customer::customerExists($email)) {
$this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.');
$_POST['email'] = $_POST['email_create'];
unset($_POST['email_create']);
} else {
$create_account = 1;
self::$smarty->assign('email_create', Tools::safeOutput($email));
$_POST['email'] = $email;
}
}
if (Tools::isSubmit('submitAccount') or Tools::isSubmit('submitGuestAccount')) {
$create_account = 1;
if (Tools::isSubmit('submitAccount')) {
self::$smarty->assign('email_create', 1);
}
/* New Guest customer */
if (!Tools::getValue('is_new_customer', 1) and !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
$this->errors[] = Tools::displayError('You cannot create a guest account.');
}
if (!Tools::getValue('is_new_customer', 1)) {
$_POST['passwd'] = md5(time() . _COOKIE_KEY_);
}
if (isset($_POST['guest_email']) and $_POST['guest_email']) {
$_POST['email'] = $_POST['guest_email'];
}
/* Preparing customer */
$customer = new Customer();
$lastnameAddress = $_POST['lastname'];
$firstnameAddress = $_POST['firstname'];
$_POST['lastname'] = $_POST['customer_lastname'];
$_POST['firstname'] = $_POST['customer_firstname'];
//if (!Tools::getValue('phone') AND !Tools::getValue('phone_mobile'))
//$this->errors[] = Tools::displayError('You must register at least one phone number');
if ($_POST['passwd'] != $_POST['retype_passwd']) {
$this->errors[] = Tools::displayError('password and confirmation do not match');
}
$this->errors = array_unique(array_merge($this->errors, $customer->validateControler()));
/*
// Preparing address
$address = new Address();
$_POST['lastname'] = $lastnameAddress;
$_POST['firstname'] = $firstnameAddress;
$address->id_customer = 1;
$this->errors = array_unique(array_merge($this->errors, $address->validateControler()));
// US customer: normalize the address
if($address->id_country == Country::getByIso('US'))
{
include_once(_PS_TAASC_PATH_.'AddressStandardizationSolution.php');
$normalize = new AddressStandardizationSolution;
$address->address1 = $normalize->AddressLineStandardization($address->address1);
$address->address2 = $normalize->AddressLineStandardization($address->address2);
}
$zip_code_format = Country::getZipCodeFormat((int)(Tools::getValue('id_country')));
if (Country::getNeedZipCode((int)(Tools::getValue('id_country'))))
{
if (($postcode = Tools::getValue('postcode')) AND $zip_code_format)
{
$zip_regexp = '/^'.$zip_code_format.'$/ui';
$zip_regexp = str_replace(' ', '( |)', $zip_regexp);
$zip_regexp = str_replace('-', '(-|)', $zip_regexp);
$zip_regexp = str_replace('N', '[0-9]', $zip_regexp);
$zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp);
$zip_regexp = str_replace('C', Country::getIsoById((int)(Tools::getValue('id_country'))), $zip_regexp);
if (!preg_match($zip_regexp, $postcode))
$this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.').'<br />'.Tools::displayError('Must be typed as follows:').' '.str_replace('C', Country::getIsoById((int)(Tools::getValue('id_country'))), str_replace('N', '0', str_replace('L', 'A', $zip_code_format)));
}
elseif ($zip_code_format)
$this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is required.');
elseif ($postcode AND !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode))
$this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.');
}
if (Country::isNeedDniByCountryId($address->id_country) AND (!Tools::getValue('dni') OR !Validate::isDniLite(Tools::getValue('dni'))))
$this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
elseif (!Country::isNeedDniByCountryId($address->id_country))
$address->dni = NULL;
*/
//create customer and login
if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) and !(Tools::getValue('months') == '' and Tools::getValue('days') == '' and Tools::getValue('years') == '')) {
$this->errors[] = Tools::displayError('Invalid date of birth');
}
if (!sizeof($this->errors)) {
if (Customer::customerExists(Tools::getValue('email'))) {
$this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.');
}
if (Tools::isSubmit('newsletter')) {
//.........这里部分代码省略.........