guadamuz Posted March 16, 2013 Share Posted March 16, 2013 (edited) Saludos ¿Quería preguntarles si existe algún método para poder usar un código digamos 225841236 en vez del email para hacer login? ¿Alguna idea? Se que me estoy saltando una gran parte de la lógica del prestashop pero me lo pidieron de esta manera. Edited May 17, 2013 by guadamuz (see edit history) Link to comment Share on other sites More sharing options...
guadamuz Posted March 18, 2013 Author Share Posted March 18, 2013 ¿Alguna idea? Estaba pensando que quizás podría engañar al prestashop recibiendo el código numérico y agregándole una terminación de correo: 232323 -> se convierte en [email protected]. Para el usuario sería invisible y al sistema no le afectaría pues seguiría trabajando como con un email. El problema es como lo hago ?_? Link to comment Share on other sites More sharing options...
Sergio Ruiz Posted March 20, 2013 Share Posted March 20, 2013 ¿Alguna idea? Estaba pensando que quizás podría engañar al prestashop recibiendo el código numérico y agregándole una terminación de correo: 232323 -> se convierte en [email protected]. Para el usuario sería invisible y al sistema no le afectaría pues seguiría trabajando como con un email. El problema es como lo hago ?_? ¿Alguna novedad? Link to comment Share on other sites More sharing options...
rperales Posted March 21, 2013 Share Posted March 21, 2013 Yo lo que hice fue, en lugar de utilizar el campo email, utilizar el campo DNI para autenticarse, de esta forma no tienes que cambiar nada en la base de datos solamente cambias los controles de logueo. Link to comment Share on other sites More sharing options...
Sergio Ruiz Posted March 21, 2013 Share Posted March 21, 2013 Yo lo que hice fue, en lugar de utilizar el campo email, utilizar el campo DNI para autenticarse, de esta forma no tienes que cambiar nada en la base de datos solamente cambias los controles de logueo. Expon tu solucion de forma completa, y no solo con palabras. Link to comment Share on other sites More sharing options...
guadamuz Posted March 21, 2013 Author Share Posted March 21, 2013 Pues yo le hice un override a la función que toma el email en tools.php, para que le agregará los datos que necesitaba Link to comment Share on other sites More sharing options...
Sergio Ruiz Posted March 21, 2013 Share Posted March 21, 2013 Pues yo le hice un override a la función que toma el email en tools.php, para que le agregará los datos que necesitaba ¿Y por que no lo compartes? Link to comment Share on other sites More sharing options...
guadamuz Posted May 16, 2013 Author Share Posted May 16, 2013 Con la ayuda de Rperales me salió este código que quiero compartir con todos: 1- Tuve que crear un campo nuevo en la tabla 'ps_customer' llamado "cod_customer". Acá van a ir los códigos numéricos que va a asignarse a cada cliente, pues la idea es no usar el email sino este código. 2- En el archivo AuthController.php en \controllers\front, cambie el siguiente código: /** * Process login */ protected function processSubmitLogin() { Hook::exec('actionBeforeAuthentication'); $passwd = trim(Tools::getValue('passwd')); /****** ESTA PARTE SE CAMBIAR EL EMAIL POR cod_customer *******/ /** AUNQUE SE PREGUNTA POR EL CAMPO 'email' en la pagina**/ $cod_customer = trim(Tools::getValue('email')); if (empty($cod_customer)) $this->errors[] = Tools::displayError('An email address required.'); /****** AQUI CAMBIAMOS EL 'IsEmail' por 'IsInt' *******/ elseif (!Validate::isInt($cod_customer)) //Este mensaje tendríamos que cambiarlo en los archivos de la traducción. $this->errors[] = Tools::displayError('Invalid email address.'); elseif (empty($passwd)) $this->errors[] = Tools::displayError('Password is required.'); elseif (!Validate::isPasswd($passwd)) $this->errors[] = Tools::displayError('Invalid password.'); else { /****** EN ESTA PARTE CAMBIAMOS LOS EMAIL POR COD_CUSTOMER *******/ $customer = new Customer(); //MUY IMPORTANTE, CAMBIAR getByEmail a getByCode $authentication = $customer->getByCode(trim($cod_customer), trim($passwd)); if (!$authentication || !$customer->id) $this->errors[] = Tools::displayError('Authentication failed.'); else { $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->cod_customer = $customer->cod_customer; // Add customer to the context $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 { $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'); // Login information have changed, so we check if the cart rules still apply CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); if (!$this->ajax) { if ($back = Tools::getValue('back')) Tools::redirect(html_entity_decode($back)); Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? url_encode($this->authRedirection) : 'my-account')); } } } if ($this->ajax) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); } else $this->context->smarty->assign('authentification_error', $this->errors); } Eso sería todo en ese archivo. 3- Tenemos que agregar otra función para validar el código del cliente en lugar de validar por email. Vamos a /classes/ y le agregamos está función al final del archivo 'Customer.php': //esta función usa el código en vez del email para hacer login public function getByCode($cod_customer, $passwd = null, $ignore_guest = true) { //usamos IsInt en vez de IsEmail if (!Validate::isInt($cod_customer) || ($passwd && !Validate::isPasswd($passwd))) die (Tools::displayError()); $sql = 'SELECT * FROM `'._DB_PREFIX_.'customer` WHERE `cod_customer` = \''.pSQL($cod_customer).'\' '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).' '.(isset($passwd) ? 'AND `passwd` = \''.Tools::encrypt($passwd).'\'' : '').' AND `deleted` = 0'. ($ignore_guest ? ' AND `is_guest` = 0' : ''); $result = Db::getInstance()->getRow($sql); if (!$result) return false; $this->id = $result['id_customer']; foreach ($result as $key => $value) if (key_exists($key, $this)) $this->{$key} = $value; return $this; } No olviden NO borrar el último '}' del archivo al agregar esto. Saludos a todos Si tienen alguna sugerencia, principalmente para no tener que cambiar los archivos del prestashop sino agregarlo aparte, se agradecería PD: Esto lo hice trabajando en la versión 1.5.4.1 Link to comment Share on other sites More sharing options...
nadie Posted May 16, 2013 Share Posted May 16, 2013 Con la ayuda de Rperales me salió este código que quiero compartir con todos: 1- Tuve que crear un campo nuevo en la tabla 'ps_customer' llamado "cod_customer". Acá van a ir los códigos numéricos que va a asignarse a cada cliente, pues la idea es no usar el email sino este código. 2- En el archivo AuthController.php en \controllers\front, cambie el siguiente código: /** * Process login */ protected function processSubmitLogin() { Hook::exec('actionBeforeAuthentication'); $passwd = trim(Tools::getValue('passwd')); /****** ESTA PARTE SE CAMBIAR EL EMAIL POR cod_customer *******/ /** AUNQUE SE PREGUNTA POR EL CAMPO 'email' en la pagina**/ $cod_customer = trim(Tools::getValue('email')); if (empty($cod_customer)) $this->errors[] = Tools::displayError('An email address required.'); /****** AQUI CAMBIAMOS EL 'IsEmail' por 'IsInt' *******/ elseif (!Validate::isInt($cod_customer)) //Este mensaje tendríamos que cambiarlo en los archivos de la traducción. $this->errors[] = Tools::displayError('Invalid email address.'); elseif (empty($passwd)) $this->errors[] = Tools::displayError('Password is required.'); elseif (!Validate::isPasswd($passwd)) $this->errors[] = Tools::displayError('Invalid password.'); else { /****** EN ESTA PARTE CAMBIAMOS LOS EMAIL POR COD_CUSTOMER *******/ $customer = new Customer(); //MUY IMPORTANTE, CAMBIAR getByEmail a getByCode $authentication = $customer->getByCode(trim($cod_customer), trim($passwd)); if (!$authentication || !$customer->id) $this->errors[] = Tools::displayError('Authentication failed.'); else { $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->cod_customer = $customer->cod_customer; // Add customer to the context $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 { $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'); // Login information have changed, so we check if the cart rules still apply CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); if (!$this->ajax) { if ($back = Tools::getValue('back')) Tools::redirect(html_entity_decode($back)); Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? url_encode($this->authRedirection) : 'my-account')); } } } if ($this->ajax) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); } else $this->context->smarty->assign('authentification_error', $this->errors); } Eso sería todo en ese archivo. 3- Tenemos que agregar otra función para validar el código del cliente en lugar de validar por email. Vamos a /classes/ y le agregamos está función al final del archivo 'Customer.php': //esta función usa el código en vez del email para hacer login public function getByCode($cod_customer, $passwd = null, $ignore_guest = true) { //usamos IsInt en vez de IsEmail if (!Validate::isInt($cod_customer) || ($passwd && !Validate::isPasswd($passwd))) die (Tools::displayError()); $sql = 'SELECT * FROM `'._DB_PREFIX_.'customer` WHERE `cod_customer` = \''.pSQL($cod_customer).'\' '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).' '.(isset($passwd) ? 'AND `passwd` = \''.Tools::encrypt($passwd).'\'' : '').' AND `deleted` = 0'. ($ignore_guest ? ' AND `is_guest` = 0' : ''); $result = Db::getInstance()->getRow($sql); if (!$result) return false; $this->id = $result['id_customer']; foreach ($result as $key => $value) if (key_exists($key, $this)) $this->{$key} = $value; return $this; } No olviden NO borrar el último '}' del archivo al agregar esto. Saludos a todos Si tienen alguna sugerencia, principalmente para no tener que cambiar los archivos del prestashop sino agregarlo aparte, se agradecería PD: Esto lo hice trabajando en la versión 1.5.4.1 Estas invitado a compartir tu aporte en la sección de aportes gratuitos del foro: http://www.prestasho...ambian-la-vida/ Referente a este tema, si puedes añade la palabra "Solucionado" al titulo del tema, esto ayudara a mantener una mayor organización del foro. Link to comment Share on other sites More sharing options...
Recommended Posts