/** * Initialize order confirmation controller * @see FrontController::init() */ public function init() { parent::init(); $this->id_cart = (int) Tools::getValue('id_cart', 0); $is_guest = false; /* check if the cart has been made by a Guest customer, for redirect link */ if (Cart::isGuestCartByCartId($this->id_cart)) { $is_guest = true; $redirectLink = 'index.php?controller=guest-tracking'; } else { $redirectLink = 'index.php?controller=history'; } $this->id_module = (int) Tools::getValue('id_module', 0); $this->id_order = Order::getOrderByCartId((int) $this->id_cart); $this->secure_key = Tools::getValue('key', false); $order = new Order((int) $this->id_order); if ($is_guest) { $customer = new Customer((int) $order->id_customer); $customer->transformToCustomer(2); //nox $redirectLink .= '&id_order=' . $order->reference . '&email=' . urlencode($customer->email); } if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key)) { Tools::redirect($redirectLink . (Tools::isSubmit('slowvalidation') ? '&slowvalidation' : '')); } $this->reference = $order->reference; if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) { Tools::redirect($redirectLink); } $module = Module::getInstanceById((int) $this->id_module); if ($order->payment != $module->displayName) { Tools::redirect($redirectLink); } }
public function __construct() { parent::__construct(); try { TTransaction::open('samples'); // abre uma transação // cria novo objeto $giovani = new Customer(); $giovani->name = 'Giovanni Dall Oglio'; $giovani->address = 'Rua da Conceicao'; $giovani->phone = '(51) 8111-2222'; $giovani->birthdate = '2013-02-15'; $giovani->status = 'S'; $giovani->email = '*****@*****.**'; $giovani->gender = 'M'; $giovani->category_id = '1'; $giovani->city_id = '1'; $giovani->store(); // armazena o objeto new TMessage('info', 'Objeto armazenado com sucesso'); TTransaction::close(); // fecha a transação. } catch (Exception $e) { new TMessage('error', $e->getMessage()); } }
protected function changePassword() { $token = Tools::getValue('token'); $id_customer = (int) Tools::getValue('id_customer'); if ($email = Db::getInstance()->getValue('SELECT `email` FROM ' . _DB_PREFIX_ . 'customer c WHERE c.`secure_key` = \'' . pSQL($token) . '\' AND c.id_customer = ' . $id_customer)) { $customer = new Customer(); $customer->getByEmail($email); if (!Validate::isLoadedObject($customer)) { $this->errors[] = $this->trans('Customer account not found', array(), 'Shop.Notifications.Error'); } elseif (!$customer->active) { $this->errors[] = $this->trans('You cannot regenerate the password for this account.', array(), 'Shop.Notifications.Error'); } // Case if both password params not posted or different, then "change password" form is not POSTED, show it. if (!Tools::isSubmit('passwd') || !Tools::isSubmit('confirmation') || ($passwd = Tools::getValue('passwd')) !== ($confirmation = Tools::getValue('confirmation')) || !Validate::isPasswd($passwd) || !Validate::isPasswd($confirmation)) { // Check if passwords are here anyway, BUT does not match the password validation format if (Tools::isSubmit('passwd') || Tools::isSubmit('confirmation')) { $this->errors[] = $this->trans('The password and its confirmation do not match.', array(), 'Shop.Notifications.Error'); } $this->context->smarty->assign(['customer_email' => $customer->email, 'customer_token' => $token, 'id_customer' => $id_customer, 'reset_token' => Tools::getValue('reset_token')]); $this->setTemplate('customer/password-new'); } else { // Both password fields posted. Check if all is right and store new password properly. if (!Tools::getValue('reset_token') || strtotime($customer->last_passwd_gen . '+' . (int) Configuration::get('PS_PASSWD_TIME_FRONT') . ' minutes') - time() > 0) { Tools::redirect('index.php?controller=authentication&error_regen_pwd'); } else { // To update password, we must have the temporary reset token that matches. if ($customer->getValidResetPasswordToken() !== Tools::getValue('reset_token')) { $this->errors[] = $this->trans('The password change request expired. You should ask for a new one.', array(), 'Shop.Notifications.Error'); } else { try { $crypto = new Hashing(); } catch (\PrestaShop\PrestaShop\Adapter\CoreException $e) { $this->errors[] = $this->trans('An error occurred with your account, which prevents us from updating the new password. Please report this issue using the contact form.', array(), 'Shop.Notifications.Error'); return false; } $customer->passwd = $crypto->encrypt($password = Tools::getValue('passwd'), _COOKIE_KEY_); $customer->last_passwd_gen = date('Y-m-d H:i:s', time()); if ($customer->update()) { Hook::exec('actionPasswordRenew', array('customer' => $customer, 'password' => $password)); $customer->removeResetPasswordToken(); $customer->update(); $mail_params = ['{email}' => $customer->email, '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname]; if (Mail::Send($this->context->language->id, 'password', Mail::l('Your new password'), $mail_params, $customer->email, $customer->firstname . ' ' . $customer->lastname)) { $this->context->smarty->assign(['customer_email' => $customer->email]); $this->success[] = $this->trans('Your password has been successfully reset and a confirmation has been sent to your email address: %s', array($customer->email), 'Shop.Notifications.Success'); $this->context->updateCustomer($customer); $this->redirectWithNotifications('index.php?controller=my-account'); } else { $this->errors[] = $this->trans('An error occurred while sending the email.', array(), 'Shop.Notifications.Error'); } } else { $this->errors[] = $this->trans('An error occurred with your account, which prevents us from updating the new password. Please report this issue using the contact form.', array(), 'Shop.Notifications.Error'); } } } } } else { $this->errors[] = $this->trans('We cannot regenerate your password with the data you\'ve submitted', array(), 'Shop.Notifications.Error'); } }
public function testSetExternalIdValid() { $externalId = 'abc'; $customer = new Customer('*****@*****.**'); $customer->setExternalId($externalId); $this->assertEquals($externalId, $customer->getExternalId()); }
public function getContent() { if (Tools::isSubmit('submitUpdate')) { Configuration::updateValue('NW_CONFIRMATION_EMAIL', (bool) Tools::getValue('NW_CONFIRMATION_EMAIL')); Configuration::updateValue('NW_VERIFICATION_EMAIL', (bool) Tools::getValue('NW_VERIFICATION_EMAIL')); $voucher = Tools::getValue('NW_VOUCHER_CODE'); if ($voucher && !Validate::isDiscountName($voucher)) { $this->_html .= $this->displayError($this->l('The voucher code is invalid.')); } else { Configuration::updateValue('NW_VOUCHER_CODE', pSQL($voucher)); $this->_html .= $this->displayConfirmation($this->l('Settings updated')); } } elseif (Tools::isSubmit('subscribedmerged')) { $id = Tools::getValue('id'); if (preg_match('/(^N)/', $id)) { $id = (int) substr($id, 1); $sql = 'UPDATE ' . _DB_PREFIX_ . 'newsletter SET active = 0 WHERE id = ' . $id; Db::getInstance()->execute($sql); } else { $c = new Customer((int) $id); $c->newsletter = (int) (!$c->newsletter); $c->update(); } Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&conf=4&token=' . Tools::getAdminTokenLite('AdminModules')); } elseif (Tools::isSubmit('exportSubscribers')) { $header = array('id', 'shop_name', 'gender', 'lastname', 'firstname', 'email', 'subscribed', 'subscribed_on'); // TODO $array_to_export = array_merge(array($header), $this->getSubscribers()); $file_name = time() . '.csv'; $fd = fopen($this->getLocalPath() . $file_name, 'w+'); foreach ($array_to_export as $tab) { $line = implode(';', $tab); $line .= "\n"; fwrite($fd, $line, 4096); } fclose($fd); Tools::redirect(_PS_BASE_URL_ . __PS_BASE_URI__ . 'modules/' . $this->name . '/' . $file_name); } elseif (Tools::isSubmit('exportOnlyBlockNews')) { $array_to_export = $this->getBlockNewsletterSubscriber(); $file_name = time() . '.csv'; $fd = fopen($this->getLocalPath() . $file_name, 'w+'); foreach ($array_to_export as $tab) { $line = implode(';', $tab); $line .= "\n"; fwrite($fd, $line, 4096); } fclose($fd); Tools::redirect(_PS_BASE_URL_ . __PS_BASE_URI__ . 'modules/' . $this->name . '/' . $file_name); } elseif (Tools::isSubmit('searchEmail')) { $this->_searched_email = Tools::getValue('searched_email'); } $this->_html .= $this->renderForm(); $this->_html .= $this->renderSearchForm(); $this->_html .= $this->renderList(); $this->_html .= '<div class="panel"><a href="' . $this->context->link->getAdminLink('AdminModules', false) . '&exportSubscribers&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules') . '"> <button class="btn btn-default btn-lg"><span class="icon icon-share"></span> ' . $this->l('Export as CSV') . '</button> </a></div>'; $this->_html .= $this->renderExportForm(); return $this->_html; }
/** * Start forms process. * * @see FrontController::postProcess() */ public function postProcess() { $order_reference = current(explode('#', Tools::getValue('order_reference'))); $email = Tools::getValue('email'); if (!$email && !$order_reference) { return; } elseif (!$email || !$order_reference) { $this->errors[] = $this->getTranslator()->trans('Please provide the required information', array(), 'Shop.Notifications.Error'); return; } $isCustomer = Customer::customerExists($email, false, true); if ($isCustomer) { $this->info[] = $this->trans('Please log in to your customer account to view the order', array(), 'Shop.Notifications.Info'); $this->redirectWithNotifications($this->context->link->getPageLink('history')); } else { $this->order = Order::getByReferenceAndEmail($order_reference, $email); if (!Validate::isLoadedObject($this->order)) { $this->errors[] = $this->getTranslator()->trans('We couldn\'t find your order with the information provided, please try again', array(), 'Shop.Notifications.Error'); } } if (Tools::isSubmit('submitTransformGuestToCustomer') && Tools::getValue('password')) { $customer = new Customer((int) $this->order->id_customer); $password = Tools::getValue('password'); if (strlen($password) < Validate::PASSWORD_LENGTH) { $this->errors[] = $this->trans('Your password must be at least %min% characters long.', array('%min%' => Validate::PASSWORD_LENGTH), 'Shop.Forms.Help'); } elseif ($customer->transformToCustomer($this->context->language->id, $password)) { $this->success[] = $this->trans('Your guest account has been successfully transformed into a customer account. You can now log in as a registered shopper.', array(), 'Shop.Notifications.Success'); } else { $this->success[] = $this->trans('An unexpected error occurred while creating your account.', array(), 'Shop.Notifications.Error'); } } }
public function run() { $this->init(); $this->preProcess(); if (Tools::getValue('ajax') == 'true') { if (Tools::getIsset('summary')) { if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { if (self::$cookie->id_customer) { $customer = new Customer((int) self::$cookie->id_customer); $groups = $customer->getGroups(); } else { $groups = array(1); } if ((int) self::$cart->id_address_delivery) { $deliveryAddress = new Address((int) self::$cart->id_address_delivery); } $result = array('carriers' => Carrier::getCarriersForOrder((int) Country::getIdZone((isset($deliveryAddress) and (int) $deliveryAddress->id) ? (int) $deliveryAddress->id_country : (int) Configuration::get('PS_COUNTRY_DEFAULT')), $groups)); } $result['summary'] = self::$cart->getSummaryDetails(); $result['customizedDatas'] = Product::getAllCustomizedDatas((int) self::$cart->id); $result['HOOK_SHOPPING_CART'] = Module::hookExec('shoppingCart', $result['summary']); $result['HOOK_SHOPPING_CART_EXTRA'] = Module::hookExec('shoppingCartExtra', $result['summary']); die(Tools::jsonEncode($result)); } else { $this->includeCartModule(); } } else { $this->setMedia(); $this->displayHeader(); $this->process(); $this->displayContent(); $this->displayFooter(); } }
public function __construct() { parent::__construct(); try { TTransaction::open('samples'); // open transaction // create a new object $giovani = new Customer(); $giovani->name = 'Giovanni Dall Oglio'; $giovani->address = 'Rua da Conceicao'; $giovani->phone = '(51) 8111-2222'; $giovani->birthdate = '2013-02-15'; $giovani->status = 'S'; $giovani->email = '*****@*****.**'; $giovani->gender = 'M'; $giovani->category_id = '1'; $giovani->city_id = '1'; $giovani->store(); // store the object new TMessage('info', 'Objeto stored successfully'); TTransaction::close(); // Closes the transaction } catch (Exception $e) { new TMessage('error', $e->getMessage()); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $rules = array("customerId" => "required", "firstAddress" => "required", "secondAddress" => "required", "thirdAddress" => "required", "fourthAddress" => "required", "area" => "required", "region" => "required", "customerPhone" => "required|numeric", "customerFax" => "required|numeric", "customerEmail" => "required|email", "customerContact" => "required", "poBirth" => "required|date", "doBirth" => "required|date", "customerReligion" => "required", "customerPosition" => "required", "customerStatus" => "required", "customerChildren" => "required|integer", "customerPhoneHome" => "required|numeric", "customerMobile" => "required|numeric", "customerPinBB" => "required"); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/customer/create')->withErrors($validator); } // $customer = new Customer(); $customer->customerID = Input::get('customerId'); $customer->customerAddress1 = Input::get('firstAddress'); $customer->customerAddress2 = Input::get('secondAddress'); $customer->customerAddress3 = Input::get('thirdAddress'); $customer->customerAddress4 = Input::get('fourthAddress'); $customer->areaID = Input::get('area'); $customer->regionID = Input::get('region'); $customer->customerPhone = Input::get('customerPhone'); $customer->customerFax = Input::get('customerFax'); $customer->customerEmail = Input::get('customerEmail'); $customer->customerContact = Input::get('customerContact'); $customer->POBirth = Input::get('poBirth'); $customer->DOBirth = Input::get('doBirth'); $customer->customerReligion = Input::get('customerReligion'); $customer->customerPosition = Input::get('customerPosition'); $customer->customerStatus = Input::get('customerStatus'); $customer->customerChildren = Input::get('customerChildren'); $customer->customerPhoneHome = Input::get('customerPhoneHome'); $customer->customerMobile = Input::get('customerMobile'); $customer->customerPinBB = Input::get('customerPinBB'); $customer->save(); return Redirect::to('/customer'); }
public function init() { parent::init(); /* * Piqué dans le AuthController. J'aurais bien aimé utiliser le AuthController, mais le premier contrôle dans son init() * c'est pour vérifier si l'utilisateur est loggé ou non, ce qui mettait à plat ma stratégie. * * Je me suis posé la question 'Faut il que ca marche pour des admin ?', j'ai supposé que non, * mais s'il avait fallu, il suffisait de tester un 'Employee' en plus d'un 'Customer' */ $passwd = trim(Tools::getValue('passwd')); $_POST['passwd'] = null; $email = trim(Tools::getValue('email')); if (!empty($email) && Validate::isEmail($email) && !empty($passwd) && Validate::isPasswd($passwd)) { $customer = new Customer(); $authentication = $customer->getByEmail(trim($email), trim($passwd)); if (isset($authentication->active) && $authentication->active && $customer->id) { Tools::redirect(Configuration::get("ADMIN_TAB_MODULE_URLBACK")); } } /* * Ici, je ne suis vraiment pas satisfait de la méthode employée, je trouve ça plutôt crade * de transmettre des infos sur les erreurs via un param en GET, mais dans l'immédiat je n'ai pas trouvé mieux */ Tools::redirect("index.php?urlback_haserror=1"); }
/** * Test whether correct methods are invoked in case of custom behaviour for each row in action column */ public function testImportDataWithCustomBehaviour() { $this->_model = $this->_getModelMockForTestImportDataWithCustomBehaviour(); $this->_model->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_CUSTOM]); // validation in validateSaveCustomerEntities and validateDeleteCustomerEntities $this->_model->importData(); }
public function get($customerId = null, $carId = null) { $sql = "SELECT * FROM {$this->tableName} WHERE 1=1"; if (!empty($customerId)) { $sql .= " AND `owner` = " . $this->db->escape($customerId); } if (!empty($carId)) { $sql .= " AND `id` = " . $this->db->escape($carId); } $result = array(); $service = new Service(); if (!empty($carId)) { $result = $this->db->fetchOne($sql); $customer = new Customer(false); $owner = $customer->get($result['owner']); if (!empty($owner)) { $result['owner'] = $owner; } $result['services'] = $service->getForCar($carId); } else { $result = $this->db->fetchAll($sql); $customer = new Customer(false); foreach ($result as $index => $car) { $owner = $customer->get($car['owner']); if (!empty($owner)) { $result[$index]['owner'] = $owner; } $result[$index]['services'] = $service->getForCar($car['id']); } } new Respond($result); }
public function preProcess() { parent::preProcess(); $customer = new Customer((int) self::$cookie->id_customer); if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days'])) { $customer->birthday = (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days']; } if (Tools::isSubmit('submitIdentity')) { if (Module::getInstanceByName('blocknewsletter')->active) { if (!isset($_POST['optin'])) { $customer->optin = 0; } if (!isset($_POST['newsletter'])) { $customer->newsletter = 0; } } if (!isset($_POST['id_gender'])) { $_POST['id_gender'] = 9; } if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) && !(Tools::getValue('months') == '' && Tools::getValue('days') == '' && 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']; $id_customer_exists = (int) Customer::customerExists(Tools::getValue('email'), true, false); if ($id_customer_exists && $id_customer_exists != (int) self::$cookie->id_customer) { $this->errors[] = Tools::displayError('An account is already registered with this e-mail.'); } $_POST['old_passwd'] = trim($_POST['old_passwd']); if (empty($_POST['old_passwd']) || 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 = array_unique(array_merge($this->errors, $customer->validateController(true, true))); } if (!count($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()); } $birthday = $customer->birthday ? explode('-', $customer->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); }
public function savedbAction(array $data) { $customer = new Customer(); $customer->exchangeArray($data); $customersTable = $this->getServiceLocator()->get('CustomersTable'); $customersTable->saveCustomer($customer); return true; }
public function delete() { if ($this->f3->exists('PARAMS.id')) { $user = new Customer($this->db); $user->delete($this->f3->get('PARAMS.id')); } $this->f3->reroute('/customer'); }
/** * @param $email * @param $password * @return int */ public function getCustomerIdByEmailAndPassword($email, $password) { /** @var CustomerCore $customer */ $customer = new Customer(); /** @var CustomerCore $authentication */ $authentication = $customer->getByEmail(trim($email), trim($password)); return $authentication->id; }
public function addCustomer($company, $firstname, $lastname, $address, $zip, $city) { $person = new Person(); $person->setCompany($company)->setFirstname($firstname)->setLastname($lastname)->setAddress($address)->setCity($city)->setZip($zip)->save(); $customer = new Customer(); $customer->setPerson($person)->save(); return $customer; }
public function testMarshalling() { $expectedXml = <<<XML <?xml version="1.0"?> <purchase-order xmlns="http://openuri.org/easypo"> <customer> <name>Gladys Kravitz</name> <address>Anytown, PA</address> </customer> <date>2003-01-07T14:16:00-05:00</date> <line-item> <description>Burnham's Celestial Handbook, Vol 1</description> <per-unit-ounces>5</per-unit-ounces> <price>21.79</price> <quantity>2</quantity> </line-item> <line-item> <description>Burnham's Celestial Handbook, Vol 2</description> <per-unit-ounces>5</per-unit-ounces> <price>19.89</price> <quantity>2</quantity> </line-item> <shipper> <name>ZipShip</name> <per-ounce-rate>0.74</per-ounce-rate> </shipper> </purchase-order> XML; $filepath = dirname(__FILE__) . '/../../_files/EasyPO/'; $binding = new PiBX_Runtime_Binding($filepath . '/binding.xml'); $marshaller = new PiBX_Runtime_Marshaller($binding); $po = new PurchaseOrder(); $po->setDate('2003-01-07T14:16:00-05:00'); $customer = new Customer(); $customer->setName('Gladys Kravitz'); $customer->setAddress('Anytown, PA'); $lineItem1 = new LineItem(); $lineItem1->setDescription('Burnham\'s Celestial Handbook, Vol 1'); $lineItem1->setPerUnitOunces('5'); $lineItem1->setPrice(21.79); $lineItem1->setQuantity(2); $lineItem2 = new LineItem(); $lineItem2->setDescription('Burnham\'s Celestial Handbook, Vol 2'); $lineItem2->setPerUnitOunces('5'); $lineItem2->setPrice(19.89); $lineItem2->setQuantity(2); $shipper = new Shipper(); $shipper->setName('ZipShip'); $shipper->setPerOunceRate(0.74); $po->setCustomer($customer); $po->setLineItems(array($lineItem1, $lineItem2)); $po->setShipper($shipper); $xml = $marshaller->marshal($po); $this->assertEquals($expectedXml, $xml); $dom = new DOMDocument(); $dom->loadXML($xml); $this->assertTrue($dom->schemaValidate($filepath . '/easypo.xsd')); }
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); }
public function actionAdmin() { $model = new Customer('search'); $model->unsetAttributes(); if (isset($_GET['Customer'])) { $model->setAttributes($_GET['Customer']); } $this->render('admin', array('model' => $model)); }
/** * Start forms process * @see FrontController::postProcess() */ public function postProcess() { if (Tools::isSubmit('email')) { if (!($email = Tools::getValue('email')) || !Validate::isEmail($email)) { $this->errors[] = Tools::displayError('Invalid e-mail address'); } else { $customer = new Customer(); $customer->getByemail($email); if (!Validate::isLoadedObject($customer)) { $this->errors[] = Tools::displayError('There is no account registered to this e-mail address.'); } elseif (!$customer->active) { $this->errors[] = Tools::displayError('You cannot regenerate the password for this account.'); } elseif (strtotime($customer->last_passwd_gen . '+' . (int) ($min_time = Configuration::get('PS_PASSWD_TIME_FRONT')) . ' minutes') - time() > 0) { $this->errors[] = sprintf(Tools::displayError('You can regenerate your password only every %d minute(s)'), (int) $min_time); } else { $mail_params = array('{email}' => $customer->email, '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{url}' => $this->context->link->getPageLink('password', true, null, 'token=' . $customer->secure_key . '&id_customer=' . (int) $customer->id)); if (Mail::Send($this->context->language->id, 'password_query', Mail::l('Password query confirmation'), $mail_params, $customer->email, $customer->firstname . ' ' . $customer->lastname)) { $this->context->smarty->assign(array('confirmation' => 2, 'email' => $customer->email)); } else { $this->errors[] = Tools::displayError('Error occurred while sending the e-mail.'); } } } } elseif (($token = Tools::getValue('token')) && ($id_customer = (int) Tools::getValue('id_customer'))) { $email = Db::getInstance()->getValue('SELECT `email` FROM ' . _DB_PREFIX_ . 'customer c WHERE c.`secure_key` = \'' . pSQL($token) . '\' AND c.id_customer = ' . (int) $id_customer); if ($email) { $customer = new Customer(); $customer->getByemail($email); if (!Validate::isLoadedObject($customer)) { $this->errors[] = Tools::displayError('Customer account not found'); } elseif (!$customer->active) { $this->errors[] = Tools::displayError('You cannot regenerate the password for this account.'); } elseif (strtotime($customer->last_passwd_gen . '+' . (int) Configuration::get('PS_PASSWD_TIME_FRONT') . ' minutes') - time() > 0) { Tools::redirect('index.php?controller=authentication&error_regen_pwd'); } else { $customer->passwd = Tools::encrypt($password = Tools::passwdGen(MIN_PASSWD_LENGTH)); $customer->last_passwd_gen = date('Y-m-d H:i:s', time()); if ($customer->update()) { Hook::exec('actionPasswordRenew', array('customer' => $customer, 'password' => $password)); $mail_params = array('{email}' => $customer->email, '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{passwd}' => $password); if (Mail::Send($this->context->language->id, 'password', Mail::l('Your new password'), $mail_params, $customer->email, $customer->firstname . ' ' . $customer->lastname)) { $this->context->smarty->assign(array('confirmation' => 1, 'email' => $customer->email)); } else { $this->errors[] = Tools::displayError('Error occurred while sending the e-mail.'); } } else { $this->errors[] = Tools::displayError('An error occurred with your account and your new password cannot be sent to your e-mail. Please report your problem using the contact form.'); } } } else { $this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted'); } } elseif (Tools::getValue('token') || Tools::getValue('id_customer')) { $this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted'); } }
/** * Добавляем покупку * @param Purchase $purchase */ public function addPurchase(Purchase $purchase) { $id = $purchase->getProduct()->getId(); if (isset($this->purchases[$id])) { $this->purchases[$id]->setCount($this->purchases[$id]->getCount() + $purchase->getCount()); } else { $this->purchases[$id] = $purchase; } $this->customer->addOrder($this); }
public function executeNew(sfWebRequest $request) { $i18n = $this->getContext()->getI18N(); $customer = new Customer(); $customer->fromArray(array('name' => $i18n->__('Client Name'), 'identification' => $i18n->__('Client Legal Id'), 'contact_person' => $i18n->__('Contact Person'), 'invoicing_address' => $i18n->__('Invoicing Address'), 'shipping_address' => $i18n->__('Shipping Address'), 'email' => $i18n->__('Client Email'))); $this->customerForm = new CustomerForm($customer, array('culture' => $this->culture)); $this->title = $i18n->__('New Customer'); $this->action = 'create'; $this->setTemplate('edit'); }
public static function checkRights($page, $action, $token) { loadClass('status'); loadClass('token'); loadClass('action'); loadClass('right'); loadClass('customer'); if (is_null($action)) { Functions::setResponse(400); } $pagename = str_replace('.php', '', basename($page)); $actionName = $pagename . '-' . $action; $whereClause = 'name=:name'; $params = array(array('id' => ':name', 'value' => $actionName)); $result = Action::search($whereClause, $params); if (!count($result)) { echo 'Please update actions and rights!'; Functions::setResponse(500); } $action = $result[0]; define('LOGGED_OUT_STATUS', 'standard'); $loggedOut = false; if (is_null($token) || strtolower($token) == 'none') { $loggedOut = true; } else { $whereClause = 'value=:value'; $params = array(array('id' => ':value', 'value' => $token)); $result = Token::search($whereClause, $params); if (!count($result)) { Functions::setResponse(498); } else { $token = $result[0]; $customer = new Customer($token->get('customerId')); $status = new Status($customer->get('statusId')); } } if ($loggedOut) { $whereClause = 'name=:name'; $params = array(array('id' => ':name', 'value' => LOGGED_OUT_STATUS)); $result = Status::search($whereClause, $params); if (!count($result)) { Functions::setResponse(500); } $status = $result[0]; } $whereClause = 'action_id=:action_id AND status_id=:status_id'; $params = array(array('id' => ':action_id', 'value' => $action->get('id')), array('id' => ':status_id', 'value' => $status->get('id'))); $result = Right::search($whereClause, $params); if (!count($result)) { Functions::setResponse(401); } if ($result[0]->get('right') == 'deny') { Functions::setResponse(401); } }
public function test_accessors() { /** === Test Data === */ $CUST_REF = 'cust ref'; $STOCK_REF = 'stock ref'; /** === Call and asserts === */ $this->obj->setCustomerRef($CUST_REF); $this->obj->setStockRef($STOCK_REF); $this->assertEquals($CUST_REF, $this->obj->getCustomerRef()); $this->assertEquals($STOCK_REF, $this->obj->getStockRef()); }
public function action_do_create() { $v = Customer::validate(Input::all()); if ($v->fails()) { return Redirect::to_route('create_customer')->with('user', Auth::user())->with_errors($v)->with_input(); } $new_customer = array('name' => Input::get('name'), 'description' => Input::get('description'), 'organization_id' => Auth::user()->organization->id); $customer = new Customer($new_customer); $customer->save(); return Redirect::to_route('customers'); }
public static function update_models($action, array $fromData, Customer $toMember) { $updateData = []; foreach ($fromData as $fieldName => $value) { // TODO what if we have a field with an underscore? $updateData[str_replace('_', '.', $fieldName)] = $value; } $updateData = self::filter_data($action, $updateData); $toMember->update($updateData); $toMember->write(); return $fromData; }
/** * @param $email * @param $password * @param $company * @param $firstname * @param $lastname * @param $street * @param $zip * @param $city * @param $country * @param int $level * @return Customer * @throws \Propel\Runtime\Exception\PropelException */ public function createLogin($email, $password, $company, $firstname, $lastname, $street, $zip, $city, $country, $level = 0) { $user = new User(); $user->setEmail($email)->setPassword(hash("sha256", $password)); $user->save(); $country_query = new CountryQuery(); $country = $country_query::create()->findOneByCode($country); $customer = new Customer(); $customer->setFirstname($firstname)->setLastname($lastname)->setCompany($company)->setAddress($street)->setZip(intval($zip))->setCity($city)->setCountry($country)->addUser($user); $customer->save(); return $user; }
/** Override __construct() because we're not passing user/pass */ public function __construct() { $user = new Customer(); $user->record_type = Customer::GUEST; $user->last_login = new CDbExpression('NOW()'); if ($user->save() === false) { print_r($user->getErrors()); } $this->setState('fullname', 'Guest'); $this->setState('firstname', 'Guest'); $this->_id = $user->id; }
public function index() { $data = array(); $this->load->model('customer'); $customer = new Customer(); $customer->load(1); $data['customer'] = $customer; $this->load->model('fault'); $fault = new Fault(); $fault->load(1); $data['fault'] = $fault; $this->load->view('fault', $data); }