- Created restricted.tpl for displaying restricted access messages with customizable background options. - Added index.php files in hook and main template directories to prevent direct access and ensure proper redirection. - Implemented info.tpl to provide module information and support links, enhancing user experience with promotional content. - Included necessary CSS styles for the new templates to ensure proper layout and responsiveness.
366 lines
16 KiB
PHP
366 lines
16 KiB
PHP
<?php
|
|
/**
|
|
* PrivateShop.
|
|
*
|
|
* Do not edit or add to this file.
|
|
* You are not authorized to modify, copy or redistribute this file.
|
|
* Permissions are reserved by FME Modules.
|
|
*
|
|
* @author FME Modules
|
|
* @copyright 2021 FME Modules All right reserved
|
|
* @license Copyrights FME Modules
|
|
*
|
|
* @category FMM Modules
|
|
*/
|
|
|
|
// header('Content-type: text/javascript');
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
class PrivateShopLiteThejaxModuleFrontController extends ModuleFrontController
|
|
{
|
|
protected $guest_allowed;
|
|
|
|
public function init()
|
|
{
|
|
parent::init();
|
|
$this->context = Context::getContext();
|
|
}
|
|
|
|
public function initContent()
|
|
{
|
|
parent::initContent();
|
|
|
|
$action = (string) Tools::getValue('action');
|
|
$this->ajax = (bool) Tools::getValue('ajax', false);
|
|
if (empty($action) || $action != 'privateLogin') {
|
|
$restrict_message = Configuration::get(
|
|
'PRIVATE_RESTRICT_MESSAGE',
|
|
(int) $this->context->language->id,
|
|
$this->context->shop->id_shop_group,
|
|
$this->context->shop->id
|
|
);
|
|
$result = [
|
|
'errors' => 0,
|
|
'message' => $restrict_message,
|
|
'html' => '',
|
|
'redirect' => false,
|
|
'redirect_url' => $this->context->link->getPageLink('my-account'),
|
|
];
|
|
$this->errors = [];
|
|
Hook::exec('actionBeforeSubmitAccount');
|
|
$passwd = trim(Tools::getValue('password'));
|
|
$email = trim(Tools::getValue('email_account'));
|
|
$firstname = Tools::getValue('firstname');
|
|
$lastname = Tools::getValue('lastname');
|
|
$gender = Tools::getValue('id_gender');
|
|
$birthday = (empty(Tools::getValue('years')) ? '' : (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days'));
|
|
$optin = Tools::getValue('optin');
|
|
$newsletter = Tools::getValue('newsletter');
|
|
$clearTextPassword = $passwd;
|
|
if (empty($email)) {
|
|
$this->errors[] = $this->module->translations['email_required'];
|
|
$result['errors'] = 1;
|
|
$result['html'] = $this->errors;
|
|
} elseif (!Validate::isEmail($email)) {
|
|
$this->errors[] = $this->module->translations['invalid_email'];
|
|
$result['errors'] = 1;
|
|
$result['html'] = $this->errors;
|
|
} elseif (empty($passwd)) {
|
|
$this->errors[] = $this->module->translations['passwd_required'];
|
|
$result['errors'] = 1;
|
|
$result['html'] = $this->errors;
|
|
} elseif (!Validate::isPlaintextPassword($passwd)) {
|
|
$this->errors[] = $this->module->translations['invalid_password'];
|
|
$result['errors'] = 1;
|
|
$result['html'] = $this->errors;
|
|
} elseif (empty($firstname)) {
|
|
$this->errors[] = $this->module->translations['required_firstname'];
|
|
$result['errors'] = 1;
|
|
$result['html'] = $this->errors;
|
|
} elseif (!Validate::isName($firstname)) {
|
|
$this->errors[] = $this->module->translations['invalid_firstname'];
|
|
$result['errors'] = 1;
|
|
$result['html'] = $this->errors;
|
|
} elseif (empty($lastname)) {
|
|
$this->errors[] = $this->module->translations['required_lastname'];
|
|
$result['errors'] = 1;
|
|
$result['html'] = $this->errors;
|
|
} elseif (!Validate::isName($lastname)) {
|
|
$this->errors[] = $this->module->translations['invalid_lastname'];
|
|
$result['errors'] = 1;
|
|
$result['html'] = $this->errors;
|
|
} elseif (!Validate::isBirthDate($birthday)) {
|
|
$this->errors[] = $this->module->translations['invalid_birthday'];
|
|
$result['errors'] = 1;
|
|
$result['html'] = $this->errors;
|
|
} elseif (!empty($this->errors)) {
|
|
$result['errors'] = 1;
|
|
$result['success'] = false;
|
|
$result['html'] = $this->errors;
|
|
} else {
|
|
$extraFields = Tools::getValue('fields');
|
|
if (isset($extraFields) && $extraFields) {
|
|
$this->checkFields();
|
|
}
|
|
|
|
$customer = new Customer();
|
|
$customer->email = $email;
|
|
$customer->firstname = $firstname;
|
|
$customer->lastname = $lastname;
|
|
$customer->id_gender = $gender;
|
|
$customer->birthday = $birthday;
|
|
$customer->optin = $optin;
|
|
$customer->newsletter = $newsletter;
|
|
if (!$clearTextPassword) {
|
|
if (!$this->guest_allowed) {
|
|
$this->errors['password'][] = $this->module->translations['password_required'];
|
|
|
|
return false;
|
|
}
|
|
$clearTextPassword = $this->crypto->hash( // for compatibility with older versions
|
|
microtime(),
|
|
_COOKIE_KEY_
|
|
);
|
|
$customer->is_guest = true;
|
|
}
|
|
$customer->passwd = md5(_COOKIE_KEY_ . $clearTextPassword);
|
|
|
|
if (Customer::customerExists($customer->email, false, true)) {
|
|
$this->errors[] = $this->module->translations['duplicate_email_error'];
|
|
$result['errors'] = 1;
|
|
$result['html'] = $this->errors;
|
|
} else {
|
|
if ($customer->save()) {
|
|
$restrict_state = (int) Configuration::get('PRIVATE_SIGNUP_RESTRICT', false, $this->context->shop->id_shop_group, $this->context->shop->id);
|
|
$this->module->updateCustomer($customer);
|
|
$this->context->cart->update();
|
|
$this->context->cookie->__set('access_granted', 1);
|
|
if ($restrict_state < 1) {
|
|
$this->sendConfirmationMail($customer);
|
|
}
|
|
if ($restrict_state > 0) {
|
|
$customer->active = 0;
|
|
$customer->update();
|
|
$this->sendMailsUserPending($customer);
|
|
$result['errors'] = 0;
|
|
} else {
|
|
$result['errors'] = 0;
|
|
$result['redirect'] = true;
|
|
}
|
|
|
|
Hook::exec(
|
|
'actionCustomerAccountAdd',
|
|
['newCustomer' => $customer]
|
|
);
|
|
$result = json_encode($result);
|
|
$this->ajaxDie($result);
|
|
} else {
|
|
$result = json_encode($result);
|
|
$this->ajaxDie($result);
|
|
}
|
|
}
|
|
}
|
|
$result = json_encode($result);
|
|
$this->ajaxDie($result);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
private function sendMailsUserPending($customer)
|
|
{
|
|
// Send email to pending customer
|
|
$module = new PrivateShopLite();
|
|
$id_lang = (int) $this->context->language->id;
|
|
$employee = new Employee(1);
|
|
$admin_email = Configuration::get('PS_SHOP_EMAIL');
|
|
$admin_email = (empty($admin_email)) ? $employee->email : $admin_email;
|
|
$module->l('Account Pending Validation');
|
|
$template_pending_customer = 'messageforpendingcustomer';
|
|
$template_pending_customer_bo = 'messageforpendingcustomeradmin';
|
|
$heading_pending_customer = $this->module->translations['pending_validation'];
|
|
Mail::Send(
|
|
(int) $id_lang,
|
|
$template_pending_customer,
|
|
$heading_pending_customer,
|
|
['{name}' => $customer->firstname . ' ' . $customer->lastname],
|
|
$customer->email,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
_PS_MODULE_DIR_ . 'privateshoplite/mails/',
|
|
false,
|
|
$this->context->shop->id
|
|
);
|
|
// Send email to store Administrator
|
|
Mail::Send(
|
|
(int) $id_lang,
|
|
$template_pending_customer_bo,
|
|
$heading_pending_customer,
|
|
['{name}' => $customer->firstname . ' ' . $customer->lastname, '{email}' => $customer->email, '{id}' => $customer->id],
|
|
$admin_email,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
_PS_MODULE_DIR_ . 'privateshoplite/mails/',
|
|
false,
|
|
$this->context->shop->id
|
|
);
|
|
}
|
|
|
|
private function sendConfirmationMail(Customer $customer)
|
|
{
|
|
if ($customer->is_guest || !Configuration::get('PS_CUSTOMER_CREATION_EMAIL')) {
|
|
return true;
|
|
}
|
|
|
|
return Mail::Send(
|
|
$this->context->language->id,
|
|
'account',
|
|
$this->translator->trans(
|
|
'Welcome!',
|
|
[],
|
|
'Emails.Subject'
|
|
),
|
|
[
|
|
'{firstname}' => $customer->firstname,
|
|
'{lastname}' => $customer->lastname,
|
|
'{email}' => $customer->email,
|
|
],
|
|
$customer->email,
|
|
$customer->firstname . ' ' . $customer->lastname,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
_PS_MAIL_DIR_,
|
|
false,
|
|
$this->context->shop->id
|
|
);
|
|
}
|
|
|
|
public function displayAjaxPrivateLogin()
|
|
{
|
|
$email = trim(Tools::getValue('email'));
|
|
$passwd = trim(Tools::getValue('passwd'));
|
|
$result = [];
|
|
if (empty($email)) {
|
|
$this->errors[] = $this->module->translations['email_required'];
|
|
$result['errors'] = 1;
|
|
$result['success'] = false;
|
|
$result['html'] = $this->errors;
|
|
} elseif (!Validate::isEmail($email)) {
|
|
$this->errors[] = $this->module->translations['invalid_email'];
|
|
$result['errors'] = 1;
|
|
$result['success'] = false;
|
|
$result['html'] = $this->errors;
|
|
} elseif (empty($passwd)) {
|
|
$this->errors[] = $this->module->translations['passwd_required'];
|
|
$result['errors'] = 1;
|
|
$result['success'] = false;
|
|
$result['html'] = $this->errors;
|
|
} elseif (!Validate::isPlaintextPassword($passwd)) {
|
|
$this->errors[] = $this->module->translations['invalid_password'];
|
|
$result['errors'] = 1;
|
|
$result['success'] = false;
|
|
$result['html'] = $this->errors;
|
|
} else {
|
|
$result['success'] = false;
|
|
Hook::exec('actionAuthenticationBefore');
|
|
|
|
$customer = new Customer();
|
|
$authentication = $customer->getByEmail($email, $passwd);
|
|
|
|
if (isset($authentication->active) && !$authentication->active) {
|
|
$this->errors[] = $this->module->translations['account_deactive'];
|
|
$result['success'] = false;
|
|
} elseif (!$authentication || !$customer->id || $customer->is_guest) {
|
|
$this->errors[] = $this->module->translations['auth_error'];
|
|
$result['success'] = false;
|
|
} else {
|
|
if (true === Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
|
|
$this->context->updateCustomer($customer);
|
|
|
|
Hook::exec('actionAuthentication', ['customer' => $customer]);
|
|
} else {
|
|
$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;
|
|
$this->context->customer = $customer;
|
|
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 {
|
|
$id_carrier = (int) $this->context->cart->id_carrier;
|
|
$this->context->cart->id_carrier = 0;
|
|
$this->context->cart->setDeliveryOption(null);
|
|
$this->context->cart->id_address_delivery = (int) Address::getFirstCustomerAddressId((int) $customer->id);
|
|
$this->context->cart->id_address_invoice = (int) Address::getFirstCustomerAddressId((int) $customer->id);
|
|
}
|
|
$this->context->cart->id_customer = (int) $customer->id;
|
|
$this->context->cart->secure_key = $customer->secure_key;
|
|
if ($this->ajax && isset($id_carrier) && $id_carrier && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
|
|
$delivery_option = [$this->context->cart->id_address_delivery => $id_carrier . ','];
|
|
$this->context->cart->setDeliveryOption($delivery_option);
|
|
}
|
|
$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');
|
|
}
|
|
// Login information have changed, so we check if the cart rules still apply
|
|
CartRule::autoRemoveFromCart($this->context);
|
|
CartRule::autoAddToCart($this->context);
|
|
$result['success'] = true;
|
|
$this->context->cookie->__set('access_granted', 1);
|
|
}
|
|
$result['html'] = $this->errors;
|
|
$result['errors'] = count($this->errors);
|
|
}
|
|
$result = json_encode($result);
|
|
$this->ajaxDie($result);
|
|
exit;
|
|
}
|
|
|
|
public function checkFields()
|
|
{
|
|
$response = [
|
|
'hasError' => false,
|
|
'errors' => 0,
|
|
'html' => '',
|
|
];
|
|
|
|
$id_customer = (int) (isset($this->context->customer)) ? $this->context->customer->id : (isset($this->context->cookie->id_customer) ? $this->context->cookie->id_customer : 0);
|
|
$id_guest = (int) (isset($this->context->cookie->id_guest)) ? $this->context->cookie->id_guest : (($id_customer) ? $this->context->customer->id_guest : 0);
|
|
|
|
if (!$id_guest) {
|
|
Guest::setNewGuest($this->context->cookie);
|
|
$id_guest = (int) $this->context->cookie->id_guest;
|
|
}
|
|
|
|
if ($id_customer) {
|
|
$type = 'customer';
|
|
} else {
|
|
$type = 'guest';
|
|
$id_customer = $id_guest;
|
|
}
|
|
|
|
if (false === (bool) $this->module->hookActionBeforeSubmitAccount()) {
|
|
$this->context->smarty->assign('errors', $this->errors);
|
|
$response['hasError'] = true;
|
|
$response['errors'] = 1;
|
|
$response['html'] = $this->errors;
|
|
exit(json_encode($response));
|
|
}
|
|
}
|
|
}
|