public function processSubmitLogin($provider) { $social_customer = $this->socialNetworkList[$provider]->processSubmitLogin(); if (!$social_customer || !$social_customer->id_user) { FSLTools::returnError(Tools::displayError('Invalid social account')); } $customer = null; if ($social_customer->id_customer) { // If social customer already exist, just login $customer = new Customer($social_customer->id_customer); } else { if (Tools::getValue('createAccount') == 'on' || Tools::getValue('createAccount') == 'true' || Tools::getValue('createAccount') == '1') { if (Customer::customerExists($social_customer->email)) { // Social customer not exist, but customer prestashop already exist. Update it. $customer = new Customer(); $authentication = $customer->getByEmail($social_customer->email); if (isset($authentication->active) && !$authentication->active) { FSLTools::returnError(Tools::displayError('Your account isn\'t available at this time, please contact us')); } else { if (!$authentication || !$customer->id) { FSLTools::returnError(Tools::displayError('Authentication failed.')); } else { if ($this->context->customer->isLogged() && $customer->id != $this->context->customer->id) { FSLTools::returnError(Tools::displayError('Your current Prestashop account not corresponding to your Social account.')); } else { if (!$customer->birthday && $social_customer->birthday) { // Update customer if needed $customer->birthday = $social_customer->birthday; $customer->update(); } } } } } else { // Create both social and prestashop customers. $customer = new Customer(); $customer->id_shop = $this->context->shop->id; $customer->firstname = $social_customer->firstname; $customer->lastname = $social_customer->lastname; $customer->email = $social_customer->email; $customer->id_gender = $social_customer->id_gender; $customer->newsletter = (bool) Configuration::get('FSL_CUSTOMER_NWSL'); $customer->optin = (bool) Configuration::get('FSL_CUSTOMER_OPTIN'); $passwd = Tools::passwdGen(); $customer->passwd = Tools::encrypt($passwd); if ($social_customer->birthday) { $customer->birthday = $social_customer->birthday; } if (!$customer->add()) { FSLTools::returnError(Tools::displayError('Error during account creation.')); } if ($customer->newsletter) { FSLTools::processCustomerNewsletter($customer); } Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer)); if (!FSLTools::sendConfirmationMail($social_customer, $passwd)) { FSLTools::returnError(Tools::displayError('The email cannot be sent.')); } } if ($customer != null && $customer->id) { $social_customer->id_customer = $customer->id; $social_customer->id_shop = $customer->id_shop; $social_customer->add(); // Add social customer } } else { FSLTools::returnAjax(); } } if (!$this->context->customer->isLogged() && $customer != null) { $this->processLogin($customer); } if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) { $redirect_url = html_entity_decode($back); } // redirection: if cart is not empty : redirection to the cart if (isset(Context::getContext()->cart) && count(Context::getContext()->cart->getProducts(true)) > 0) { $redirect_url = Context::getContext()->link->getPageLink('order' . ($multi = (int) Tools::getValue('multi-shipping') ? '&multi-shipping=' . $multi : '')); } else { $redirect_url = Context::getContext()->link->getPageLink('my-account'); } FSLTools::returnAjax($redirect_url, $social_customer); }