name = 'acactiv'; $this->displayName = $this->l('Account activation by email'); $this->description = $this->l('With this module your customers must activate their accounts with link that will be send to email used during register'); $this->tab = 'advertising_marketing'; $this->author = 'MyPresta.eu'; $this->bootstrap = true; $this->mypresta_link = 'https://mypresta.eu/modules/front-office-features/account-activation-by-email-link.html'; $this->module_key = '3ec1ba193b0e3c189c4f14761c9188e9'; $this->version = '1.5.1'; parent::__construct(); $this->checkforupdates(0, 0); } public function hookactionAdminControllerSetMedia($params) { //for update feature purposes } public function inconsistency($ret = false) { return; } public function psversion($part = 1) { $version = _PS_VERSION_; $exp = $explode = explode(".", $version); if ($part == 1) { return $exp[1]; } if ($part == 2) { return $exp[2]; } if ($part == 3) { return $exp[3]; } } public function checkforupdates($display_msg = 0, $form = 0) { // ---------- // // ---------- // // VERSION 16 // // ---------- // // ---------- // $this->mkey = "nlc"; if (@file_exists('../modules/' . $this->name . '/key.php')) { @require_once('../modules/' . $this->name . '/key.php'); } else { if (@file_exists(dirname(__FILE__) . $this->name . '/key.php')) { @require_once(dirname(__FILE__) . $this->name . '/key.php'); } else { if (@file_exists('modules/' . $this->name . '/key.php')) { @require_once('modules/' . $this->name . '/key.php'); } } } if ($form == 1) { return '
' . ($this->psversion() == 6 || $this->psversion() == 7 ? '
' . $this->l('MyPresta updates') . '
' : '') . '
' . ($this->psversion() == 5 ? '' . $this->l('MyPresta updates') . '' : '') . '
' . (Tools::isSubmit('submit_settings_updates_now') ? ($this->inconsistency(0) ? '' : '') . $this->checkforupdates(1) : '') . '

' . $this->l('Turn this option on if you want to check MyPresta.eu for module updates automatically. This option will display notification about new versions of this addon.') . '

' . $this->displayName . '

' . $this->l('This is direct link to official addon page, where you can read about changes in the module (changelog)') . '

'; } else { if (defined('_PS_ADMIN_DIR_')) { if (Tools::isSubmit('submit_settings_updates')) { Configuration::updateValue('mypresta_updates', Tools::getValue('mypresta_updates')); } if (Configuration::get('mypresta_updates') != 0 || (bool)Configuration::get('mypresta_updates') != false) { if (Configuration::get('update_' . $this->name) < (date("U") - 259200)) { $actual_version = acactivUpdate::verify($this->name, (isset($this->mkey) ? $this->mkey : 'nokey'), $this->version); } if (acactivUpdate::version($this->version) < acactivUpdate::version(Configuration::get('updatev_' . $this->name)) && Tools::getValue('ajax', 'false') == 'false') { $this->context->controller->warnings[] = '' . $this->displayName . ': ' . $this->l('New version available, check http://MyPresta.eu for more informations') . ' ' . $this->l('More details in changelog') . ''; $this->warning = $this->context->controller->warnings[0]; } } else { if (Configuration::get('update_' . $this->name) < (date("U") - 259200)) { $actual_version = acactivUpdate::verify($this->name, (isset($this->mkey) ? $this->mkey : 'nokey'), $this->version); } } if ($display_msg == 1) { if (acactivUpdate::version($this->version) < acactivUpdate::version(acactivUpdate::verify($this->name, (isset($this->mkey) ? $this->mkey : 'nokey'), $this->version))) { return "" . $this->l('New version available!') . ""; } else { return "" . $this->l('Module is up to date!') . ""; } } } } } public function install() { if (parent::install() == false || $this->registerHook('actionCustomerAccountAdd') == false || $this->registerHook('displayHeader') == false || $this->registerHook('actionAdminControllerSetMedia') == false || $this->installdb() == false) { return false; } return true; } private function installdb() { return true; } public function hookHeader($params) { if (Tools::getValue('act') == 1) { if (Configuration::get('ACACTIV_SENDTOME') != true) { $this->context->smarty->assign('actvtmsg', $this->l('We sent an email with account activation link to your email address.')); } else { $this->context->smarty->assign('actvtmsg', $this->l('Your account is registered properly. Now we have to review it and manually activate. Thank you for your patience.')); } $this->context->smarty->assign('alert_type', 'success'); $this->context->controller->addJqueryPlugin('fancybox'); $this->context->controller->addCSS($this->_path . 'views/acactiv.css'); $this->context->controller->addJS($this->_path . 'views/acactiv.js'); return $this->display(__file__, 'views/displayHeader.tpl'); } elseif (Tools::getValue('activation') == 1 && Tools::getValue('h', 'false') != 'false' && Tools::getValue('u', 'false') != 'false') { $user = new Customer(Tools::getValue('u')); $this->context->controller->addJqueryPlugin('fancybox'); $this->context->controller->addCSS($this->_path . 'views/acactiv.css'); $this->context->controller->addJS($this->_path . 'views/acactiv.js'); if ($user->active == 1 && $user->id != null) { if (Configuration::get('ACACTIV_SENDTOME') != true) { $this->context->smarty->assign('actvtmsg', $this->l('Your account is active.')); } else { $this->context->smarty->assign('actvtmsg', $this->l('You activated this customer account properly')); } if (Configuration::get('ACACTIV_AUTOLOGIN') == 1) { $this->AutoLogIn($user->id); $this->context->smarty->assign('alert_type', 'info'); $this->context->smarty->assign('acactiv_redirect', 1); } return $this->display(__file__, 'views/displayHeader.tpl'); } elseif (md5($user->id . $user->passwd) == Tools::getValue('h')) { $user->active = 1; $user->save(); if (Configuration::get('ACACTIV_SENDTOME') != true) { $this->context->smarty->assign('actvtmsg', $this->l('Account activated properly. You can log in now.')); } else { $id_lang = Context::getContext()->language->id; $id_shop = Context::getContext()->shop->id; $templatevars = array(); $templatevars['{customer_firstname}'] = $user->firstname; $templatevars['{customer_lastname}'] = $user->lastname; Mail::Send($id_lang, 'manually-activated', Configuration::get('ACACTIV_ATITLE', Context::getContext()->language->id), $templatevars, (string)($user->email), null, (string)Configuration::get('PS_SHOP_EMAIL', null, null, $id_shop), (string)Configuration::get('PS_SHOP_NAME', null, null, $id_shop), null, null, dirname(__file__) . '/mails/', false, $id_shop); $this->context->smarty->assign('actvtmsg', $this->l('You activated this customer account properly')); } $this->context->smarty->assign('alert_type', 'success'); if (Configuration::get('ACACTIV_AUTOLOGIN') == 1) { $this->AutoLogIn($user->id); $this->context->smarty->assign('alert_type', 'info'); $this->context->smarty->assign('acactiv_redirect', 1); $this->context->smarty->assign('actvtmsg', $this->l('Account activated properly.')); } return $this->display(__file__, 'views/displayHeader.tpl'); } else { $this->context->smarty->assign('actvtmsg', $this->l('Invalid account activation link')); $this->context->smarty->assign('alert_type', 'danger'); return $this->display(__file__, 'views/displayHeader.tpl'); } } } public function hookactionCustomerAccountAdd($params) { if (Tools::getValue('provider') == 'Facebook' || Tools::getValue('provider') == 'Google' || Tools::getValue('provider') == 'Twitter') { return; } if (isset($params['fblogin'])) { if ($params['fblogin'] == true) { return; } } if (isset($params['glogin'])) { if ($params['glogin'] == true) { return; } } if (isset($params['plogin'])) { if ($params['plogin'] == true) { return; } } if (Tools::getValue('submitCreate') == 1 && Tools::getValue('continue', 'false') == 1 && Tools::getValue('password') == "") { return; } $id_lang = Context::getContext()->language->id; $id_shop = Context::getContext()->shop->id; $newuser = new Customer($params['newCustomer']->id); if ($newuser->is_guest != 1) { $newuser->active = 0; $newuser->save(); if (!isset($params['executed_from_webservice'])) { $this->context->customer->logout(); } else { $_GET['email'] = (string)$newuser->email; } $templatevars = array(); $templatevars['{customer_firstname}'] = $newuser->firstname; $templatevars['{customer_lastname}'] = $newuser->lastname; $templatevars['{link}'] = Context::getContext()->link->getPageLink('index', true, Context::getContext()->language->id, array('activation' => 1, 'u' => $newuser->id, 'h' => md5($newuser->id . $newuser->passwd))); $id_lang = Context::getContext()->language->id; $id_shop = Context::getContext()->shop->id; $customer = new Customer(); $customer = $customer->getByEmail((string)$newuser->email); $address = new Address( null, Context::getContext()->language->id ); $address->id_country = (int) Tools::getCountry(); $address->address1 = Tools::getValue('address1'); $address->postcode = Tools::getValue('postcode'); $address->city = Tools::getValue('city'); $address->firstname = $customer->firstname; $address->lastname = $customer->lastname; $address->id_customer = (int) $customer->id; $address->phone = Tools::getValue('phone'); $address->id_state = 0; $address->alias = $this->trans('My Address', [], 'Shop.Theme.Checkout'); $address->save(); Mail::Send($id_lang, 'acactiv', Configuration::get('ACACTIV_CTITLE', Context::getContext()->language->id), $templatevars, (string)(Configuration::get('ACACTIV_SENDTOME') ? (string)Configuration::get('PS_SHOP_EMAIL', null, null, $id_shop) : Tools::getValue('email')), null, (string)Configuration::get('PS_SHOP_EMAIL', null, null, $id_shop), (string)Configuration::get('PS_SHOP_NAME', null, null, $id_shop), null, null, dirname(__file__) . '/mails/', false, $id_shop); if (!isset($params['executed_from_webservice'])) { Tools::redirect(Context::getContext()->link->getPageLink('index', true, Context::getContext()->language->id, array('act' => 1))); } } } public function getContent() { return $this->displayFormMailTitle() . $this->checkforupdates(0, 1); } public function displayFormMailTitle() { if (Tools::isSubmit('submitdisplayFormMailTitle')) { $title = array(); foreach (Language::getLanguages(true) AS $value) { $title[$value['id_lang']] = Tools::getValue('ACACTIV_CTITLE_' . $value['id_lang']); $atitle[$value['id_lang']] = Tools::getValue('ACACTIV_ATITLE_' . $value['id_lang']); } Configuration::updateValue('ACACTIV_CTITLE', $title); Configuration::updateValue('ACACTIV_ATITLE', $atitle); Configuration::updateValue('ACACTIV_SENDTOME', Tools::getValue('ACACTIV_SENDTOME')); Configuration::updateValue('ACACTIV_AUTOLOGIN', Tools::getValue('ACACTIV_AUTOLOGIN')); } $fields_form = array( 'form' => array( 'legend' => array( 'title' => $this->l('Email Settings'), 'icon' => 'icon-cogs' ), 'description' => $this->l('Settings of email messages'), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Title of email to customer'), 'name' => 'ACACTIV_CTITLE', 'lang' => true, 'desc' => $this->l('Define the title of the email that module will send to customer with account activation link'), ), array( 'type' => 'switch', 'label' => $this->l('Send email with account activation link to admin'), 'name' => 'ACACTIV_SENDTOME', 'desc' => $this->l('You can disable double opt-in and moderate user accounts manually (email with account activation link will be delivered to shop admin)'), 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('On') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Off') ) ), ), array( 'type' => 'text', 'label' => $this->l('Title of email to admin'), 'name' => 'ACACTIV_ATITLE', 'lang' => true, 'desc' => $this->l('Set the title of the email that will be delivered to customer when shop admin will activate user account with special link'), ), array( 'type' => 'switch', 'label' => $this->l('Auto log-in customer after activation'), 'name' => 'ACACTIV_AUTOLOGIN', 'desc' => $this->l('Decide if you want to automatically log in customer after account activation (once customer will press the link in email)'), 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('On') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Off') ) ), ), ), 'submit' => array('title' => $this->l('Save settings'),) ), ); $helper = new HelperForm(); $helper->show_toolbar = false; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->identifier = 'displayFormMailTitleIdentifier'; $helper->submit_action = 'submitdisplayFormMailTitle'; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getConfigFieldsValuesMails(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $helper->generateForm(array($fields_form)); } public function getConfigFieldsValuesMails() { $title = array(); $atitle = array(); foreach (Language::getLanguages(true) AS $value) { $title[$value['id_lang']] = Configuration::get('ACACTIV_CTITLE', $value['id_lang']); $atitle[$value['id_lang']] = Configuration::get('ACACTIV_ATITLE', $value['id_lang']); } return array( 'ACACTIV_CTITLE' => Tools::getValue('ACACTIV_CTITLE', $title), 'ACACTIV_ATITLE' => Tools::getValue('ACACTIV_ATITLE', $atitle), 'ACACTIV_SENDTOME' => Tools::getValue('ACACTIV_SENDTOME', Configuration::get('ACACTIV_SENDTOME')), 'ACACTIV_AUTOLOGIN' => Tools::getValue('ACACTIV_AUTOLOGIN', Configuration::get('ACACTIV_AUTOLOGIN')), ); } public function AutoLogIn($id_customer, $id_cart = false) { $customer = new Customer(); $customer->logout(); $customer = new Customer($id_customer); //$this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare : CompareProduct::getIdCompareByIdCustomer($customer->id); $this->context->cookie->id_customer = (int)($customer->id); $this->context->cookie->customer_lastname = $customer->lastname; $this->context->cookie->customer_firstname = $customer->firstname; $this->context->cookie->logged = 1; $customer->logged = 1; $this->context->cookie->is_guest = $customer->isGuest(); $this->context->cookie->passwd = $customer->passwd; $this->context->cookie->email = $customer->email; // Add customer to the context $this->context->customer = $customer; if ($id_cart != 0 && $id_cart != false) { $this->context->cart = new Cart($id_cart); $this->context->cookie->id_cart = $id_cart; } else { $id_cart_current = isset($this->context->cookie->id_cart) ? (int)$this->context->cookie->id_cart : 0; if ($id_cart_current > 0) { $id_customer_cart = Db::getInstance()->getValue("select id_customer from cart where id_cart = $id_cart_current"); if ($id_customer_cart > 0 && $id_customer_cart != $id_customer) { $this->context->cookie->id_cart = 0; $this->context->cart = null; } } if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0) && $id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id)) { $this->context->cart = new Cart($id_cart); } else { $this->context->cart->id_carrier = 0; $this->context->cart->setDeliveryOption(null); $this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); $this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); } } $this->context->cart->id_customer = (int)$customer->id; $this->context->cart->secure_key = $customer->secure_key; $this->context->cart->save(); $this->context->cookie->id_cart = (int)$this->context->cart->id; $this->context->cookie->write(); $this->context->cart->autosetProductAddress(); Hook::exec('actionAuthentication'); CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); } } class acactivUpdate extends acactiv { public static function version($version) { $version = (int)str_replace(".", "", $version); if (strlen($version) == 3) { $version = (int)$version . "0"; } if (strlen($version) == 2) { $version = (int)$version . "00"; } if (strlen($version) == 1) { $version = (int)$version . "000"; } if (strlen($version) == 0) { $version = (int)$version . "0000"; } return (int)$version; } public static function encrypt($string) { return base64_encode($string); } public static function verify($module, $key, $version) { if (ini_get("allow_url_fopen")) { if (function_exists("file_get_contents")) { $actual_version = @file_get_contents('http://dev.mypresta.eu/update/get.php?module=' . $module . "&version=" . self::encrypt($version) . "&lic=$key&u=" . self::encrypt(_PS_BASE_URL_ . __PS_BASE_URI__)); } } Configuration::updateValue("update_" . $module, date("U")); Configuration::updateValue("updatev_" . $module, $actual_version); return $actual_version; } } ?>