public function registerDiscount($id_customer, $register = false, $id_currency = 0) { $configurations = Configuration::getMultiple(array('REFERRAL_DISCOUNT_TYPE', 'REFERRAL_PERCENTAGE', 'REFERRAL_DISCOUNT_VALUE_' . (int) $id_currency)); $cartRule = new CartRule(); if ($configurations['REFERRAL_DISCOUNT_TYPE'] == Discount::PERCENT) { $cartRule->reduction_percent = (double) $configurations['REFERRAL_PERCENTAGE']; } elseif ($configurations['REFERRAL_DISCOUNT_TYPE'] == Discount::AMOUNT and isset($configurations['REFERRAL_DISCOUNT_VALUE_' . (int) $id_currency])) { $cartRule->reduction_amount = (double) $configurations['REFERRAL_DISCOUNT_VALUE_' . (int) $id_currency]; } $cartRule->quantity = 1; $cartRule->quantity_per_user = 1; $cartRule->date_from = date('Y-m-d H:i:s', time()); $cartRule->date_to = date('Y-m-d H:i:s', time() + 31536000); // + 1 year $cartRule->code = $this->getDiscountPrefix() . Tools::passwdGen(6); $cartRule->name = Configuration::getInt('REFERRAL_DISCOUNT_DESCRIPTION'); $cartRule->id_customer = (int) $id_customer; $cartRule->id_currency = (int) $id_currency; if ($cartRule->add()) { if ($register != false) { if ($register == 'sponsor') { $this->id_cart_rule_sponsor = (int) $cartRule->id; } elseif ($register == 'sponsored') { $this->id_cart_rule = (int) $cartRule->id; } return $this->save(); } return true; } return false; }
public function __construct() { global $cookie; $this->name = 'ebay'; $this->tab = 'market_place'; $this->version = '1.3.1'; $this->author = 'PrestaShop'; parent::__construct(); $this->displayName = $this->l('eBay'); $this->description = $this->l('Open your shop on the eBay market place !'); $this->id_lang = Language::getIdByIso('fr'); // Check the country and ask the bypass if not 'fr' if (strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))) != 'fr' && !isset($cookie->ebay_country_default_fr)) { $this->warning = $this->l('eBay module currently works only for eBay.fr'); return false; } // Checking Extension if (!extension_loaded('curl') || !ini_get('allow_url_fopen')) { if (!extension_loaded('curl') && !ini_get('allow_url_fopen')) { $this->warning = $this->l('You must enable cURL extension and allow_url_fopen option on your server if you want to use this module.'); } elseif (!extension_loaded('curl')) { $this->warning = $this->l('You must enable cURL extension on your server if you want to use this module.'); } elseif (!ini_get('allow_url_fopen')) { $this->warning = $this->l('You must enable allow_url_fopen option on your server if you want to use this module.'); } return false; } // Checking compatibility with older PrestaShop and fixing it if (!Configuration::get('PS_SHOP_DOMAIN')) { Configuration::updateValue('PS_SHOP_DOMAIN', $_SERVER['HTTP_HOST']); } // Generate eBay Security Token if not exists if (!Configuration::get('EBAY_SECURITY_TOKEN')) { Configuration::updateValue('EBAY_SECURITY_TOKEN', Tools::passwdGen(30)); } /* For 1.4.3 and less compatibility */ $updateConfig = array('PS_OS_CHEQUE', 'PS_OS_PAYMENT', 'PS_OS_PREPARATION', 'PS_OS_SHIPPING', 'PS_OS_CANCELED', 'PS_OS_REFUND', 'PS_OS_ERROR', 'PS_OS_OUTOFSTOCK', 'PS_OS_BANKWIRE', 'PS_OS_PAYPAL', 'PS_OS_WS_PAYMENT'); if (!Configuration::get('PS_OS_PAYMENT')) { foreach ($updateConfig as $u) { if (!Configuration::get($u) && defined('_' . $u . '_')) { Configuration::updateValue($u, constant('_' . $u . '_')); } } } // Check if installed if (self::isInstalled($this->name)) { // Upgrade eBay module if (Configuration::get('EBAY_VERSION') != $this->version) { $this->upgrade(); } // Generate warnings if (!Configuration::get('EBAY_API_TOKEN')) { $this->warning = $this->l('You must register your module on eBay.'); } // Loading Shipping Method $this->loadShippingMethod(); // Warning uninstall $this->confirmUninstall = $this->l('Are you sure you want uninstall this module ? All your configuration will be lost.'); } }
/** * Installation du module. */ public function install() { if (!parent::install() || !$this->registerHook('displayHeader') || !$this->registerHook('actionValidateOrder') || !$this->registerHook('actionObjectOrderHistoryAddAfter') || !$this->registerHook('actionObjectOrderUpdateAfter') || !$this->registerHook('displayAdminOrder') || !$this->installSQL() || !$this->installExternalOrderState()) { return false; } Configuration::updateValue('SHIPTOMYID_CRON_TOKEN', Tools::passwdGen(16)); Configuration::updateValue('SHIPTOMYID_ENABLE', 0); Configuration::updateValue('SHIPTOMYID_BASE64_MODE', 0); Configuration::updateValue('SHIPTOMYID_USERNAME', ''); Configuration::updateValue('SHIPTOMYID_PASSWORD', ''); Configuration::updateValue('SHIPTOMYID_WEBSERVICE_URL', Configuration::get('PS_SSL_ENABLED') ? 'https://hotfix-app.ship2myid.com/ship2myid/rest/' : 'http://hotfix-app.ship2myid.com/ship2myid/rest/'); Configuration::updateValue('SHIPTOMYID_TERMS_URL', 'http://www.ship2myid.com/terms-of-use'); Configuration::updateValue('SHIPTOMYID_PRIVACY_URL', 'http://www.ship2myid.com/privacy'); Configuration::updateValue('SHIPTOMYID_VIDEO_LINK', 'http://www.youtube.com/watch?v=_4yvWDuyCis'); Configuration::updateValue('SHIPTOMYID_DEFAULT_ADDR_ADDRESS', 'The shipping address is protected by Ship2MyID.'); Configuration::updateValue('SHIPTOMYID_DEFAULT_ADDR_ADDRESS2', 'X'); Configuration::updateValue('SHIPTOMYID_DEFAULT_ADDR_CITY', 'XX'); Configuration::updateValue('SHIPTOMYID_DEFAULT_ADDR_POSTCODE', 'XXX'); Configuration::updateValue('SHIPTOMYID_DEFAULT_ADDR_PHONE', 'XXXX'); Configuration::updateValue('SHIPTOMYID_DEFAULT_ADDR_ALIAS', 'Ship2MyId'); Configuration::updateValue('SHIPTOMYID_DEFAULT_ADDR_COUNTRY', Configuration::get('PS_COUNTRY_DEFAULT')); Configuration::updateValue('SHIPTOMYID_DEFAULT_ADDR_STATE', 0); Configuration::updateValue('SHIPTOMYID_POPUP_URL', Configuration::get('PS_SSL_ENABLED') ? 'https://hotfix-app.ship2myid.com/ship2myid/shopping_cart_popup/index.jsp?plateform=prestashop' : 'http://hotfix-app.ship2myid.com/ship2myid/shopping_cart_popup/index.jsp?plateform=prestashop'); Configuration::updateValue('SHIPTOMYID_POPUP_WIDTH', '634'); Configuration::updateValue('SHIPTOMYID_POPUP_HEIGHT', '774'); Configuration::updateValue('SHIPTOMYID_CANCEL_ORDER_STATE', Configuration::get('PS_OS_CANCELED')); return true; }
public function registerDiscount($id_customer, $amount, $day, $type, $name) { $languages = Language::getLanguages(false); $cartRule = new CartRule(); if ($type == 'percent') { $cartRule->reduction_percent = $amount; } else { $cartRule->reduction_amount = $amount; } $cartRule->quantity = 1; $cartRule->quantity_per_user = 1; $cartRule->date_from = date('Y-m-d H:i:s', time()); $cartRule->date_to = date('Y-m-d H:i:s', time() + 86000 * $day); //$cartRule->minimum_amount = ''; // Utile ? $cartRule->minimum_amount_tax = true; $cartRule->code = $name . '_' . strtoupper(Tools::passwdGen(6)); //$cartRule->code = $name; // QUESTION ? // It does not work if I do not use languages but it works with the referalprogam module (Prestashop Module) foreach ($languages as $lang) { $cartRule->name[$lang['id_lang']] = $name . ' Customer ID :' . $id_customer; } $cartRule->id_customer = (int) $id_customer; $cartRule->reduction_tax = true; $cartRule->highlight = 1; if ($cartRule->add()) { return $cartRule; } return false; }
public function install() { if (!parent::install() || !Configuration::updateValue('PS_NEWSLETTER_RAND', rand() . rand()) || !$this->registerHook(array('displayFooterBefore', 'actionCustomerAccountAdd', 'additionalCustomerFormFields'))) { return false; } Configuration::updateValue('NW_SALT', Tools::passwdGen(16)); $conditions = array(); $languages = Language::getLanguages(false); foreach ($languages as $lang) { $conditions[(int) $lang['id_lang']] = $this->getConditionFixtures($lang); } Configuration::updateValue('NW_CONDITIONS', $conditions, true); return Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'emailsubscription` ( `id` int(6) NOT NULL AUTO_INCREMENT, `id_shop` INTEGER UNSIGNED NOT NULL DEFAULT \'1\', `id_shop_group` INTEGER UNSIGNED NOT NULL DEFAULT \'1\', `email` varchar(255) NOT NULL, `newsletter_date_add` DATETIME NULL, `ip_registration_newsletter` varchar(15) NOT NULL, `http_referer` VARCHAR(255) NULL, `active` TINYINT(1) NOT NULL DEFAULT \'0\', PRIMARY KEY(`id`) ) ENGINE=' . _MYSQL_ENGINE_ . ' default CHARSET=utf8'); }
/** * Generate settings file */ public function generateSettingsFile($database_server, $database_login, $database_password, $database_name, $database_prefix, $database_engine) { // Check permissions for settings file if (file_exists(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE) && !is_writable(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE)) { $this->setError($this->language->l('%s file is not writable (check permissions)', self::SETTINGS_FILE)); return false; } elseif (!file_exists(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE) && !is_writable(_PS_ROOT_DIR_ . '/' . dirname(self::SETTINGS_FILE))) { $this->setError($this->language->l('%s folder is not writable (check permissions)', dirname(self::SETTINGS_FILE))); return false; } // Generate settings content and write file $settings_constants = array('_DB_SERVER_' => $database_server, '_DB_NAME_' => $database_name, '_DB_USER_' => $database_login, '_DB_PASSWD_' => $database_password, '_DB_PREFIX_' => $database_prefix, '_MYSQL_ENGINE_' => $database_engine, '_PS_CACHING_SYSTEM_' => 'CacheMemcache', '_PS_CACHE_ENABLED_' => '0', '_MEDIA_SERVER_1_' => '', '_MEDIA_SERVER_2_' => '', '_MEDIA_SERVER_3_' => '', '_COOKIE_KEY_' => Tools::passwdGen(56), '_COOKIE_IV_' => Tools::passwdGen(8), '_PS_CREATION_DATE_' => date('Y-m-d'), '_PS_VERSION_' => _PS_INSTALL_VERSION_); // If mcrypt is activated, add Rijndael 128 configuration if (function_exists('mcrypt_encrypt')) { $settings_constants['_RIJNDAEL_KEY_'] = Tools::passwdGen(mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB)); $settings_constants['_RIJNDAEL_IV_'] = base64_encode(mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND)); } $settings_content = "<?php\n"; foreach ($settings_constants as $constant => $value) { $settings_content .= "define('{$constant}', '" . str_replace('\'', '\\\'', $value) . "');\n"; } if (!file_put_contents(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE, $settings_content)) { $this->setError($this->language->l('Cannot write settings file')); return false; } return true; }
public static function generateReference() { do { $reference = strtoupper(Tools::passwdGen(9, 'NO_NUMERIC')); } while (Order::getByReference($reference)); return $reference; }
public function registerDiscount($id_customer, $register = false) { $configurations = Configuration::getMultiple(array('REFERRAL_DISCOUNT_TYPE', 'REFERRAL_DISCOUNT_VALUE')); $discount = new Discount(); $discount->id_discount_type = intval($configurations['REFERRAL_DISCOUNT_TYPE']); $discount->value = floatval($configurations['REFERRAL_DISCOUNT_VALUE']); $discount->quantity = 1; $discount->quantity_per_user = 1; $discount->date_from = date('Y-m-d H:i:s', time()); $discount->date_to = date('Y-m-d H:i:s', time() + 31536000); // + 1 year $discount->name = $this->getDiscountPrefix() . Tools::passwdGen(6); $discount->description = Configuration::getInt('REFERRAL_DISCOUNT_DESCRIPTION'); $discount->id_customer = intval($id_customer); if ($discount->add()) { if ($register != false) { if ($register == 'sponsor') { $this->id_discount_sponsor = $discount->id; } elseif ($register == 'sponsored') { $this->id_discount = $discount->id; } return $this->save(); } return true; } return false; }
public function install() { if (!parent::install() || !$this->installExternalCarrier($this->_config) || !Configuration::updateValue('EXTERNAL_CARRIER_OVERCOST', 5) || !$this->registerHook('updateCarrier') || !$this->registerHook('extraCarrier') || !$this->registerHook('newOrder') || !$this->registerHook('processCarrier') || !$this->registerHook('orderDetailDisplayed') || !$this->registerHook('updateOrderStatus') || !Configuration::updateValue('KIALASMALL_VERSION', $this->version) || !Configuration::updateValue('KIALASMALL_SECURITY_TOKEN', Tools::passwdGen(30)) || !Configuration::updateValue('KIALASMALL_WS_URL', $this->ws_url) || !Configuration::updateValue('KIALASMALL_SEARCH_BY', 'order')) { return false; } // Install SQL include dirname(__FILE__) . '/sql-install.php'; foreach ($sql as $s) { if (!Db::getInstance()->Execute($s)) { return false; } } // Create country settings foreach ($this->countries as $iso_code) { $id_country = Country::getByIso($iso_code); if ($id_country) { $kiala_country = new SmKialaCountry(); $kiala_country->id_country = $id_country; $kiala_country->preparation_delay = $this->default_preparation_delay; $kiala_country->active = 0; // Is this the merchant home country? if ($id_country == Country::getByIso('ES')) { $kiala_country->pickup_country = 1; $kiala_country->dspid = '34600160'; } $kiala_country->save(); } } return true; }
/** * Start forms process * @see FrontController::postProcess() */ public function postProcess() { if (Tools::isSubmit('submitMessage')) { $idOrder = (int) Tools::getValue('id_order'); $msgText = Tools::getValue('msgText'); if (!$idOrder || !Validate::isUnsignedId($idOrder)) { $this->errors[] = Tools::displayError('The order is no longer valid.'); } elseif (empty($msgText)) { $this->errors[] = Tools::displayError('The message cannot be blank.'); } elseif (!Validate::isMessage($msgText)) { $this->errors[] = Tools::displayError('This message is invalid (HTML is not allowed).'); } if (!count($this->errors)) { $order = new Order($idOrder); if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) { //check if a thread already exist $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($this->context->customer->email, $order->id); $cm = new CustomerMessage(); if (!$id_customer_thread) { $ct = new CustomerThread(); $ct->id_contact = 0; $ct->id_customer = (int) $order->id_customer; $ct->id_shop = (int) $this->context->shop->id; if (($id_product = (int) Tools::getValue('id_product')) && $order->orderContainProduct((int) $id_product)) { $ct->id_product = $id_product; } $ct->id_order = (int) $order->id; $ct->id_lang = (int) $this->context->language->id; $ct->email = $this->context->customer->email; $ct->status = 'open'; $ct->token = Tools::passwdGen(12); $ct->add(); } else { $ct = new CustomerThread((int) $id_customer_thread); } $cm->id_customer_thread = $ct->id; $cm->message = $msgText; $cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']); $cm->add(); if (!Configuration::get('PS_MAIL_EMAIL_MESSAGE')) { $to = strval(Configuration::get('PS_SHOP_EMAIL')); } else { $to = new Contact((int) Configuration::get('PS_MAIL_EMAIL_MESSAGE')); $to = strval($to->email); } $toName = strval(Configuration::get('PS_SHOP_NAME')); $customer = $this->context->customer; if (Validate::isLoadedObject($customer)) { Mail::Send($this->context->language->id, 'order_customer_comment', Mail::l('Message from a customer'), array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{email}' => $customer->email, '{id_order}' => (int) $order->id, '{order_name}' => $order->getUniqReference(), '{message}' => Tools::nl2br($msgText)), $to, $toName, $customer->email, $customer->firstname . ' ' . $customer->lastname); } if (Tools::getValue('ajax') != 'true') { Tools::redirect('index.php?controller=order-detail&id_order=' . (int) $idOrder); } $this->context->smarty->assign('message_confirmation', true); } else { $this->errors[] = Tools::displayError('Order not found'); } } } }
public function createDefaultBcashDiscounts() { foreach ($this->names as $name) { $coupon = new Discount(); $coupon->name = $this->getLangsForName($name); $coupon->quantity = self::billion; $coupon->quantity_per_user = self::billion; $coupon->date_from = date('Y-m-d H:i:s'); $coupon->date_to = date('Y-m-d', strtotime('+30 year')); $coupon->partial_use = 0; $coupon->code = 'gerenciado_pelo_modulo_' . Tools::passwdGen(8); $coupon->active = 0; //Invisivel $coupon->highlight = 0; //Envio excluido $coupon->minimum_amount_shipping = 0; //Acoes $coupon->free_shipping = 0; $coupon->reduction_percent = 0; if ($coupon->add()) { Configuration::updateValue(self::prefix . self::bcash . $name, (int) $coupon->id); } } return true; }
public function install() { $ps_ct_immediat_payment = Configuration::get($this->prefix . 'IMMEDIAT_PAYMENT') ? Configuration::get($this->prefix . 'IMMEDIAT_PAYMENT') : '1'; $ps_ct_salt = Configuration::get($this->prefix . 'SALT') ? Configuration::get($this->prefix . 'SALT') : strtoupper(Tools::passwdGen(8)); $ps_ct_business_type = Configuration::get($this->prefix . 'BUSINESS_TYPE') ? Configuration::get($this->prefix . 'BUSINESS_TYPE') : 'I'; $ps_ct_environment = Configuration::get($this->prefix . 'ENVIRONMENT') ? Configuration::get($this->prefix . 'ENVIRONMENT') : 'T'; return parent::install() and Disposition::createTable() and $this->_createOrderState() and $this->registerHook('payment') and $this->registerHook('paymentReturn') and $this->registerHook('adminOrder') and Configuration::updateValue($this->prefix . 'IMMEDIAT_PAYMENT', $ps_ct_immediat_payment) and Configuration::updateValue($this->prefix . 'SALT', $ps_ct_salt) and Configuration::updateValue($this->prefix . 'BUSINESS_TYPE', $ps_ct_business_type) and Configuration::updateValue($this->prefix . 'ENVIRONMENT', $ps_ct_environment); }
/** * Set customer information * Used to create user account with PayPal account information */ function setCustomerInformation($ppec, $email) { $customer = new Customer(); $customer->email = $email; $customer->lastname = $ppec->result['LASTNAME']; $customer->firstname = $ppec->result['FIRSTNAME']; $customer->passwd = Tools::encrypt(Tools::passwdGen()); return $customer; }
/** * Construct Method * **/ public function __construct() { $this->name = 'ebay'; $this->tab = 'market_place'; $this->version = '1.6.5'; $this->author = 'PrestaShop'; parent::__construct(); /** Backward compatibility */ require _PS_MODULE_DIR_ . $this->name . '/backward_compatibility/backward.php'; $this->displayName = $this->l('eBay'); $this->description = $this->l('Easily export your products from PrestaShop to eBay, the biggest market place, to acquire new customers and realize more sales.'); $this->module_key = '7a6b007a219bab59c1611254347f21d5'; $this->ps_versions_compliancy = array('min' => '1.4', 'max' => _PS_VERSION_); // Checking Extension $this->_checkExtensionsLoading(); // Checking compatibility with older PrestaShop and fixing it if (!Configuration::get('PS_SHOP_DOMAIN')) { $this->setConfiguration('PS_SHOP_DOMAIN', $_SERVER['HTTP_HOST']); } // Generate eBay Security Token if not exists if (!Configuration::get('EBAY_SECURITY_TOKEN')) { $this->setConfiguration('EBAY_SECURITY_TOKEN', Tools::passwdGen(30)); } // For 1.4.3 and less compatibility $update_config = array('PS_OS_CHEQUE' => 1, 'PS_OS_PAYMENT' => 2, 'PS_OS_PREPARATION' => 3, 'PS_OS_SHIPPING' => 4, 'PS_OS_DELIVERED' => 5, 'PS_OS_CANCELED' => 6, 'PS_OS_REFUND' => 7, 'PS_OS_ERROR' => 8, 'PS_OS_OUTOFSTOCK' => 9, 'PS_OS_BANKWIRE' => 10, 'PS_OS_PAYPAL' => 11, 'PS_OS_WS_PAYMENT' => 12); foreach ($update_config as $key => $value) { if (!Configuration::get($key)) { $const_name = '_' . $key . '_'; if ((int) constant($const_name)) { $this->setConfiguration($key, constant($const_name)); } else { $this->setConfiguration($key, $value); } } } // Check if installed if (self::isInstalled($this->name)) { if (class_exists('EbayCountrySpec')) { // Check the country $this->ebay_country = EbayCountrySpec::getInstanceByKey(Configuration::get('EBAY_COUNTRY_DEFAULT')); if (!$this->ebay_country->checkCountry()) { $this->warning = $this->l('The eBay module currently works for eBay.fr, eBay.it, eBay.co.uk, eBay.pl, eBay.nl and eBay.es'); return false; } } // Upgrade eBay module if (Configuration::get('EBAY_VERSION') != $this->version) { $this->_upgrade(); } // Generate warnings if (!Configuration::get('EBAY_API_TOKEN')) { $this->warning = $this->l('You must register your module on eBay.'); } // Warning uninstall $this->confirmUninstall = $this->l('Are you sure you want to uninistall this module? All configuration settings will be lost'); } }
/** * 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'); } }
public function install() { if (!function_exists('curl_init')) { return $this->_abortInstall($this->l('CURL is not installed')); } if (!parent::install() || !$this->registerHook('leftColumn') || !$this->registerHook('header') || !$this->registerHook('top') || !$this->registerHook('productTab') || !$this->registerHook('actionCartSave') || !$this->registerHook('actionPaymentConfirmation') || !$this->registerHook('actionProductAdd') || !$this->registerHook('actionProductUpdate') || !$this->registerHook('actionProductDelete') || !Configuration::updateValue('CONVERMAX_URL', 'https://api.convermax.com/v2') || !Configuration::updateValue('CONVERMAX_CRON_KEY', Tools::passwdGen(8))) { return false; } return true; }
public function install() { foreach ($this->available_languages as $language) { Configuration::updateValue('TS_TAB0_ID_' . (int) Language::getIdByIso($language), ''); Configuration::updateValue('TS_TAB0_ID_ACTIVE_' . (int) Language::getIdByIso($language), ''); } Configuration::updateValue('TS_TAB0_DISPLAY_IN_SHOP', ''); Configuration::updateValue('TS_TAB0_DISPLAY_RATING_FRONT_END', ''); Configuration::updateValue('TS_TAB0_DISPLAY_RATING_OC', ''); Configuration::updateValue('TS_TAB0_SEND_RATING', ''); Configuration::updateValue('TS_TAB0_SEND_SEPERATE_MAIL', ''); Configuration::updateValue('TS_TAB0_SEND_SEPERATE_MAIL_DELAY', ''); return RatingAlert::createTable() and Configuration::updateValue('PS_TS_TAB0_SECURE_KEY', strtoupper(Tools::passwdGen(16))); }
/** * Creates a new customer based on the given data. */ public static function create_customer_from_data(array $data, $send_email_to_admin = false, $send_email_to_customer = false) { if (is_array($data) && !empty($data['user_token']) && !empty($data['identity_token'])) { $password = Tools::passwdGen(); // Build customer fields. $customer = new CustomerCore(); $customer->firstname = $data['user_first_name']; $customer->lastname = $data['user_last_name']; $customer->id_gender = $data['user_gender']; $customer->birthday = $data['user_birthdate']; $customer->active = true; $customer->deleted = false; $customer->is_guest = false; $customer->passwd = Tools::encrypt($password); // We could get the email. if (!empty($data['user_email'])) { // It already exists. if (self::get_id_customer_for_email_address($data['user_email']) !== false) { // Create a new one. $customer->email = self::generate_random_email_address(); $customer->newsletter = false; } else { $customer->email = $data['user_email']; $customer->newsletter = true; } } else { // Create a new one. $customer->email = self::generate_random_email_address(); $customer->newsletter = false; } // Create a new user account. if ($customer->add()) { // Tie the tokens to the newly created member. if (self::link_tokens_to_id_customer($customer->id, $data['user_token'], $data['identity_token'], $data['identity_provider'])) { //Send an email to the customer if ($send_email_to_customer === true) { self::send_confirmation_to_customer($customer, $password, $data['identity_provider']); } //Send an email to the administratos if ($send_email_to_admin === true) { self::send_confirmation_to_administrators($customer, $data['identity_provider']); } //Done return $customer->id; } } } //Error return false; }
public function process() { parent::process(); if (Tools::isSubmit('email')) { if (!($email = Tools::getValue('email')) or !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.'); } else { if (strtotime($customer->last_passwd_gen . '+' . (int) ($min_time = Configuration::get('PS_PASSWD_TIME_FRONT')) . ' minutes') - time() > 0) { $this->errors[] = Tools::displayError('You can regenerate your password only every') . ' ' . (int) $min_time . ' ' . Tools::displayError('minute(s)'); } else { if (Mail::Send((int) self::$cookie->id_lang, 'password_query', Mail::l('Password query confirmation'), array('{email}' => $customer->email, '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{url}' => self::$link->getPageLink('password.php', true) . '?token=' . $customer->secure_key . '&id_customer=' . (int) $customer->id), $customer->email, $customer->firstname . ' ' . $customer->lastname)) { self::$smarty->assign(array('confirmation' => 2, 'email' => $customer->email)); } else { $this->errors[] = Tools::displayError('Error occurred when 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 (strtotime($customer->last_passwd_gen . '+' . (int) ($min_time = Configuration::get('PS_PASSWD_TIME_FRONT')) . ' minutes') - time() > 0) { Tools::redirect('authentication.php?error_regen_pwd'); } else { $customer->passwd = Tools::encrypt($password = Tools::passwdGen((int) MIN_PASSWD_LENGTH)); $customer->last_passwd_gen = date('Y-m-d H:i:s', time()); if ($customer->update()) { if (Mail::Send((int) self::$cookie->id_lang, 'password', Mail::l('Your password'), array('{email}' => $customer->email, '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{passwd}' => $password), $customer->email, $customer->firstname . ' ' . $customer->lastname)) { self::$smarty->assign(array('confirmation' => 1, 'email' => $customer->email)); } else { $this->errors[] = Tools::displayError('Error occurred when 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 (($token = Tools::getValue('token')) || ($id_customer = Tools::getValue('id_customer'))) { $this->errors[] = Tools::displayError('We cannot regenerate your password with the data you submitted'); } }
/** * Create virtual customer to associate address for country selection * * @return bool */ private function createCustomer() { $customer = new Customer(); $customer->email = 'shipping_estimation@prestashop_virtual.com'; $customer->lastname = 'Shipping'; $customer->firstname = 'Estimation'; $customer->deleted = 1; // Keep it Hidden $customer->passwd = Tools::encrypt(Tools::passwdGen()); if ($customer->add()) { Configuration::updateValue(CarrierCompare::VIRTUAL_CUSTOMER, $customer->id); return true; } return false; }
public function __construct() { global $cookie; $this->name = 'ebay'; $this->tab = 'market_place'; $this->version = '1.1'; parent::__construct(); $this->displayName = $this->l('eBay'); $this->description = $this->l('Open your shop on the eBay market place !'); $this->id_lang = Language::getIdByIso('fr'); // Check the country and ask the bypass if not 'fr' if (strtolower(Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))) != 'fr' && !isset($cookie->ebay_country_default_fr)) { $this->warning = $this->l('eBay module currently works only for eBay.fr'); return false; } // Checking Extension if (!extension_loaded('curl') || !ini_get('allow_url_fopen')) { if (!extension_loaded('curl') && !ini_get('allow_url_fopen')) { $this->warning = $this->l('You must enable cURL extension and allow_url_fopen option on your server if you want to use this module.'); } else { if (!extension_loaded('curl')) { $this->warning = $this->l('You must enable cURL extension on your server if you want to use this module.'); } else { if (!ini_get('allow_url_fopen')) { $this->warning = $this->l('You must enable allow_url_fopen option on your server if you want to use this module.'); } } } return false; } // Checking compatibility with older PrestaShop and fixing it if (!Configuration::get('PS_SHOP_DOMAIN')) { Configuration::updateValue('PS_SHOP_DOMAIN', $_SERVER['HTTP_HOST']); } // Generate eBay Security Token if not exists if (!Configuration::get('EBAY_SECURITY_TOKEN')) { Configuration::updateValue('EBAY_SECURITY_TOKEN', Tools::passwdGen(30)); } // Check if installed if (self::isInstalled($this->name)) { // Generate warnings if (!Configuration::get('EBAY_API_TOKEN')) { $this->warning = $this->l('You must register your module on eBay.'); } // Shipping methods $this->_shippingMethod = array(7104 => array('description' => 'Colissimo', 'shippingService' => 'FR_ColiposteColissimo', 'shippingServiceID' => '7104'), 7112 => array('description' => 'Ecopli', 'shippingService' => 'FR_Ecopli', 'shippingServiceID' => '7112'), 57104 => array('description' => 'La Poste - Courrier International Prioritaire', 'shippingService' => 'FR_LaPosteInternationalPriorityCourier', 'shippingServiceID' => '57104'), 7101 => array('description' => 'Lettre', 'shippingService' => 'FR_PostOfficeLetter', 'shippingServiceID' => '7101'), 57105 => array('description' => 'La Poste - Courrier International Economique', 'shippingService' => 'FR_LaPosteInternationalEconomyCourier', 'shippingServiceID' => '57105'), 57106 => array('description' => 'La Poste - Colissimo International', 'shippingService' => 'FR_LaPosteColissimoInternational', 'shippingServiceID' => '57106'), 7102 => array('description' => 'Lettre avec suivi', 'shippingService' => 'FR_PostOfficeLetterFollowed', 'shippingServiceID' => '7102'), 57107 => array('description' => 'La Poste - Colis Economique International', 'shippingService' => 'FR_LaPosteColisEconomiqueInternational', 'shippingServiceID' => '57107'), 7103 => array('description' => 'Lettre recommandée', 'shippingService' => 'FR_PostOfficeLetterRecommended', 'shippingServiceID' => '7103'), 7121 => array('description' => 'Lettre Max', 'shippingService' => 'FR_LaPosteLetterMax', 'shippingServiceID' => '7121'), 7113 => array('description' => 'Coliéco', 'shippingService' => 'FR_Colieco', 'shippingServiceID' => '7113'), 57108 => array('description' => 'La Poste - Colissimo Emballage International', 'shippingService' => 'FR_LaPosteColissimoEmballageInternational', 'shippingServiceID' => '57108'), 57114 => array('description' => 'Chronopost Express International', 'shippingService' => 'FR_ChronopostExpressInternational', 'shippingServiceID' => '57114'), 7106 => array('description' => 'Colissimo Recommandé', 'shippingService' => 'FR_ColiposteColissimoRecommended', 'shippingServiceID' => '7106'), 57109 => array('description' => 'Chronopost Classic International', 'shippingService' => 'FR_ChronopostClassicInternational', 'shippingServiceID' => '57109'), 57110 => array('description' => 'Chronopost Premium International', 'shippingService' => 'FR_ChronopostPremiumInternational', 'shippingServiceID' => '57110'), 7117 => array('description' => 'Chronopost - Chrono Relais', 'shippingService' => 'FR_ChronopostChronoRelais', 'shippingServiceID' => '7117'), 57111 => array('description' => 'UPS Standard', 'shippingService' => 'FR_UPSStandardInternational', 'shippingServiceID' => '57111'), 7111 => array('description' => 'Autre mode d\'envoi de courrier', 'shippingService' => 'FR_Autre', 'shippingServiceID' => '7111'), 57112 => array('description' => 'UPS Express', 'shippingService' => 'FR_UPSExpressInternational', 'shippingServiceID' => '57112'), 7114 => array('description' => 'Autre mode d\'envoi de colis', 'shippingService' => 'FR_AuteModeDenvoiDeColis', 'shippingServiceID' => '7114'), 57113 => array('description' => 'DHL', 'shippingService' => 'FR_DHLInternational', 'shippingServiceID' => '57113'), 57101 => array('description' => 'Frais de livraison internationale fixes', 'shippingService' => 'FR_StandardInternational', 'shippingServiceID' => '57101'), 7116 => array('description' => 'Chronopost', 'shippingService' => 'FR_Chronopost', 'shippingServiceID' => '7116'), 57102 => array('description' => 'Frais fixes pour livraison internationale express', 'shippingService' => 'FR_ExpeditedInternational', 'shippingServiceID' => '57102'), 57103 => array('description' => 'Autres livraisons internationales (voir description)', 'shippingService' => 'FR_OtherInternational', 'shippingServiceID' => '57103'), 7118 => array('description' => 'Chrono 10', 'shippingService' => 'FR_Chrono10', 'shippingServiceID' => '7118'), 7119 => array('description' => 'Chrono 13', 'shippingService' => 'FR_Chrono13', 'shippingServiceID' => '7119'), 7120 => array('description' => 'Chrono 18', 'shippingService' => 'FR_Chrono18', 'shippingServiceID' => '7120'), 7105 => array('description' => 'Coliposte - Colissimo Direct', 'shippingService' => 'FR_ColiposteColissimoDirect', 'shippingServiceID' => '7105'), 7107 => array('description' => 'Chronoposte - Chrono Classic International', 'shippingService' => 'FR_ChronoposteInternationalClassic', 'shippingServiceID' => '7107'), 7108 => array('description' => 'DHL - Express Europack', 'shippingService' => 'FR_DHLExpressEuropack', 'shippingServiceID' => '7108'), 7109 => array('description' => 'UPS - Standard', 'shippingService' => 'FR_UPSStandard', 'shippingServiceID' => '7109')); } }
public function install() { if (!parent::install() || !$this->registerHook(array('header', 'footer', 'actionCustomerAccountAdd', 'displayNewsletter'))) { return false; } Configuration::updateValue('NW_SALT', Tools::passwdGen(16)); return Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'newsletter` ( `id` int(6) NOT NULL AUTO_INCREMENT, `id_shop` INTEGER UNSIGNED NOT NULL DEFAULT \'1\', `id_shop_group` INTEGER UNSIGNED NOT NULL DEFAULT \'1\', `email` varchar(255) NOT NULL, `newsletter_date_add` DATETIME NULL, `ip_registration_newsletter` varchar(15) NOT NULL, `http_referer` VARCHAR(255) NULL, `active` TINYINT(1) NOT NULL DEFAULT \'0\', PRIMARY KEY(`id`) ) ENGINE=' . _MYSQL_ENGINE_ . ' default CHARSET=utf8'); }
public function install() { // Database Table include dirname(__FILE__) . '/sql/install.php'; // Token for "wget" style crons Configuration::updateGlobalValue('AUTOZIP_TOKEN_NAME', Tools::passwdGen(10)); Configuration::updateGlobalValue('AUTOZIP_TOKEN_KEY', Tools::passwdGen(10)); // Module Tab $tab = new Tab(); $tab->active = 1; $tab->class_name = 'AdminAutozip'; $tab->name = array(); foreach (Language::getLanguages(true) as $lang) { $tab->name[$lang['id_lang']] = 'AutoZip'; } $tab->module = $this->name; $tab->id_parent = (int) Tab::getIdFromClassName('AdminCatalog'); return parent::install() && $tab->add(); }
function install() { if (!parent::install()) { return false; } $this->registerHook('extraLeft'); $this->registerHook('footer'); $this->registerHook('orderConfirmation'); $token = Configuration::get('TREEPODIA_TOKEN') ? Configuration::get('TREEPODIA_TOKEN') : Tools::passwdGen(16); $type = Configuration::get('TREEPODIA_INTEGRATION_TYPE') ? Configuration::get('TREEPODIA_INTEGRATION_TYPE') : 0; $logo = Configuration::get('TREEPODIA_PLAY_LOGO') ? Configuration::get('TREEPODIA_PLAY_LOGO') : '4-7.png'; $position = Configuration::get('TREEPODIA_POSITION') ? Configuration::get('TREEPODIA_POSITION') : 1; $hook = Configuration::get('TREEPODIA_HOOK') ? Configuration::get('TREEPODIA_HOOK') : 0; Configuration::updateValue('TREEPODIA_TOKEN', $token); Configuration::updateValue('TREEPODIA_INTEGRATION_TYPE', $type); Configuration::updateValue('TREEPODIA_PLAY_LOGO', $logo); Configuration::updateValue('TREEPODIA_POSITION', $position); Configuration::updateValue('TREEPODIA_HOOK', $hook); return true; }
/** * Stripe's module installation * * @return boolean Install result */ public function install() { if (!$this->backward && _PS_VERSION_ < 1.5) { echo '<div class="error">' . Tools::safeOutput($this->backward_error) . '</div>'; return false; } /* For 1.4.3 and less compatibility */ $updateConfig = array('PS_OS_CHEQUE' => 1, 'PS_OS_PAYMENT' => 2, 'PS_OS_PREPARATION' => 3, 'PS_OS_SHIPPING' => 4, 'PS_OS_DELIVERED' => 5, 'PS_OS_CANCELED' => 6, 'PS_OS_REFUND' => 7, 'PS_OS_ERROR' => 8, 'PS_OS_OUTOFSTOCK' => 9, 'PS_OS_BANKWIRE' => 10, 'PS_OS_PAYPAL' => 11, 'PS_OS_WS_PAYMENT' => 12); foreach ($updateConfig as $u => $v) { if (!Configuration::get($u) || (int) Configuration::get($u) < 1) { if (defined('_' . $u . '_') && (int) constant('_' . $u . '_') > 0) { Configuration::updateValue($u, constant('_' . $u . '_')); } else { Configuration::updateValue($u, $v); } } } $ret = parent::install() && $this->registerHook('payment') && $this->registerHook('header') && $this->registerHook('backOfficeHeader') && $this->registerHook('paymentReturn') && Configuration::updateValue('STRIPE_MODE', 0) && Configuration::updateValue('STRIPE_SAVE_TOKENS', 1) && Configuration::updateValue('STRIPE_SAVE_TOKENS_ASK', 1) && Configuration::updateValue('STRIPE_PENDING_ORDER_STATUS', (int) Configuration::get('PS_OS_PAYMENT')) && Configuration::updateValue('STRIPE_PAYMENT_ORDER_STATUS', (int) Configuration::get('PS_OS_PAYMENT')) && Configuration::updateValue('STRIPE_CHARGEBACKS_ORDER_STATUS', (int) Configuration::get('PS_OS_ERROR')) && Configuration::updateValue('STRIPE_WEBHOOK_TOKEN', md5(Tools::passwdGen())) && $this->installDb(); /* The hook "displayMobileHeader" has been introduced in v1.5.x - Called separately to fail silently if the hook does not exist */ $this->registerHook('displayMobileHeader'); return $ret; }
/** * Generate the settings file. */ public function generateSettingsFile($database_host, $database_user, $database_password, $database_name, $database_prefix, $database_engine) { // Check permissions for settings file if (file_exists(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . self::SETTINGS_FILE) && !is_writable(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . self::SETTINGS_FILE)) { $this->setError($this->translator->trans('%file% file is not writable (check permissions)', array('%file%' => self::SETTINGS_FILE), 'Install')); return false; } elseif (!file_exists(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . self::SETTINGS_FILE) && !is_writable(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . dirname(self::SETTINGS_FILE))) { $this->setError($this->translator->trans('%folder% folder is not writable (check permissions)', array('%folder%' => dirname(self::SETTINGS_FILE)), 'Install')); return false; } $secret = Tools::passwdGen(56); $cookie_key = Tools::passwdGen(56); $cookie_iv = Tools::passwdGen(8); $database_port = null; $splits = preg_split('#:#', $database_host); $nbSplits = count($splits); if ($nbSplits >= 2) { $database_port = array_pop($splits); $database_host = implode(':', $splits); } $parameters = array_replace_recursive(Yaml::parse(file_get_contents(_PS_ROOT_DIR_ . '/app/config/parameters.yml.dist')), array('parameters' => array('database_host' => $database_host, 'database_port' => $database_port, 'database_user' => $database_user, 'database_password' => $database_password, 'database_name' => $database_name, 'database_prefix' => $database_prefix, 'database_engine' => $database_engine, 'cookie_key' => $cookie_key, 'cookie_iv' => $cookie_iv, 'ps_creation_date' => date('Y-m-d'), 'secret' => $secret, 'locale' => $this->language->getLanguage()->getLocale()))); // If mcrypt is activated, add Rijndael 128 configuration if (function_exists('mcrypt_encrypt')) { if (!isset($config['parameters']['_rijndael_key'])) { $parameters['parameters']['_rijndael_key'] = Tools::passwdGen(mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB)); $parameters['parameters']['_rijndael_iv'] = base64_encode(mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND)); } } $settings_content = "<?php\n"; $settings_content .= "//@deprecated 1.7"; if (!file_put_contents(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE, $settings_content)) { $this->setError($this->translator->trans('Cannot write settings file', array(), 'Install')); return false; } if (!$this->processParameters($parameters)) { return false; } return true; }
public function transformToCustomer($id_lang, $password = null) { if (!$this->isGuest()) { return false; } if (empty($password)) { $password = Tools::passwdGen(8, 'RANDOM'); } if (!Validate::isPasswd($password)) { return false; } $this->is_guest = 0; $this->passwd = Tools::encrypt($password); $this->cleanGroups(); $this->addGroups(array(Configuration::get('PS_CUSTOMER_GROUP'))); // add default customer group if ($this->update()) { $vars = array('{firstname}' => $this->firstname, '{lastname}' => $this->lastname, '{email}' => $this->email, '{passwd}' => $password); Mail::Send((int) $id_lang, 'guest_to_customer', Mail::l('Your guest account has been transformed into a customer account', (int) $id_lang), $vars, $this->email, $this->firstname . ' ' . $this->lastname, null, null, null, null, _PS_MAIL_DIR_, false, (int) $this->id_shop); return true; } return false; }
public function processForgot() { if (_PS_MODE_DEMO_) { $this->errors[] = Tools::displayError('This functionality has been disabled.'); } elseif (!($email = trim(Tools::getValue('email_forgot')))) { $this->errors[] = Tools::displayError('Email is empty.'); } elseif (!Validate::isEmail($email)) { $this->errors[] = Tools::displayError('Invalid email address.'); } else { $employee = new Employee(); if (!$employee->getByEmail($email) || !$employee) { $this->errors[] = Tools::displayError('This account does not exist.'); } elseif (strtotime($employee->last_passwd_gen . '+' . Configuration::get('PS_PASSWD_TIME_BACK') . ' minutes') - time() > 0) { $this->errors[] = sprintf(Tools::displayError('You can regenerate your password only every %d minute(s)'), Configuration::get('PS_PASSWD_TIME_BACK')); } } if (!count($this->errors)) { $pwd = Tools::passwdGen(10, 'RANDOM'); $employee->passwd = Tools::encrypt($pwd); $employee->last_passwd_gen = date('Y-m-d H:i:s', time()); $params = array('{email}' => $employee->email, '{lastname}' => $employee->lastname, '{firstname}' => $employee->firstname, '{passwd}' => $pwd); if (Mail::Send($employee->id_lang, 'employee_password', Mail::l('Your new password', $employee->id_lang), $params, $employee->email, $employee->firstname . ' ' . $employee->lastname)) { // Update employee only if the mail can be sent Shop::setContext(Shop::CONTEXT_SHOP, (int) min($employee->getAssociatedShops())); $result = $employee->update(); if (!$result) { $this->errors[] = Tools::displayError('An error occurred while attempting to change your password.'); } else { die(Tools::jsonEncode(array('hasErrors' => false, 'confirm' => $this->l('Your password has been emailed to you.', 'AdminTab', false, false)))); } } else { die(Tools::jsonEncode(array('hasErrors' => true, 'errors' => array(Tools::displayError('An error occurred while attempting to change your password.'))))); } } elseif (Tools::isSubmit('ajax')) { die(Tools::jsonEncode(array('hasErrors' => true, 'errors' => $this->errors))); } }
public static function getPSMId($module) { $key = 'PSM_ID_' . Tools::strtoupper($module->name); if (!isset(self::$s_cache[$key])) { self::$s_cache[$key] = Configuration::getGlobalValue($key); if (self::$s_cache[$key] === false) { self::$s_cache[$key] = ''; for ($i = 0; $i < 3; $i++) { self::$s_cache[$key] .= Tools::passwdGen(4, 'NUMERIC') . '-'; } self::$s_cache[$key] .= Tools::passwdGen(4, 'NUMERIC'); Configuration::updateGlobalValue($key, self::$s_cache[$key]); } } return self::$s_cache[$key]; }
public function install() { if (Configuration::updateValue('TWENGA_TOKEN', Tools::passwdGen())) { return parent::install(); } else { return false; } }