Alexandre Carette Posted February 1, 2016 Share Posted February 1, 2016 Bonjour, J'ai une fonction servant a traiter un formulaire de création de compte ultra simple. Une fois le compte créé je redirige vers une page category... J'aimerai que l'utilisateur soit loggué dans la foulé... j ai éplucher authController.php mais je ne trouve pas.... pouvez vous m'aider ? public static function registeraccount($firstname,$lastname,$mail,$password) { $passwd = md5(Tools::passwdGen(8)); $customer = new Customer(); $customer->passwd = $password; $customer->email = $mail; $customer->firstname = $firstname; $customer->lastname = $lastname; $customer->active = 1; $customer->newsletter = 1; $customer->add(); $customer->cleanGroups(); //redirect to user page $id_customer = $customer->id; Tools::redirect('index.php?id_category='.$id_customer.'&controller=category'); } Link to comment Share on other sites More sharing options...
Eolia Posted February 2, 2016 Share Posted February 2, 2016 je vous donne une piste: pour que l'utilisateur soit loggué il faut mettre le cookie à jour Link to comment Share on other sites More sharing options...
Alexandre Carette Posted February 2, 2016 Author Share Posted February 2, 2016 Merci Eolia, oui en cherchant j'ai ce genre de fonction dans authController.php /** * Update context after customer creation * @param Customer $customer Created customer */ protected function updateContext(Customer $customer) { $this->context->customer = $customer; $this->context->smarty->assign('confirmation', 1); $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->passwd = $customer->passwd; $this->context->cookie->logged = 1; // if register process is in two steps, we display a message to confirm account creation if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE')) { $this->context->cookie->account_created = 1; } $customer->logged = 1; $this->context->cookie->email = $customer->email; $this->context->cookie->is_guest = !Tools::getValue('is_new_customer', 1); // Update cart address $this->context->cart->secure_key = $customer->secure_key; } Par contre je ne vois pas comment appeller cette fonction a partir de mon module, en recreant une fonction similaire dans mon module j ai une erreur php dans l utilisation de $this-> Merci de ton aide Link to comment Share on other sites More sharing options...
Eolia Posted February 2, 2016 Share Posted February 2, 2016 C'est un peu normal, le $this se rapporte à l'intance en cours... il faut donc commencer par récupérer ton contexte: $context = Context::getContext(); et remplacer tous les $this->context par $context Vraiment "Expert Prestashop" ? 1 Link to comment Share on other sites More sharing options...
Alexandre Carette Posted February 2, 2016 Author Share Posted February 2, 2016 (edited) c du marketing, je vais essayer merci Eolia Edited February 2, 2016 by Alexandre-KM (see edit history) Link to comment Share on other sites More sharing options...
Alexandre Carette Posted February 7, 2016 Author Share Posted February 7, 2016 Du coup ca marche comme ca, merci Eolia. //on change le context pour ecrire dans le cookie global $cookie; $context = Context::getContext(); $context->customer = $customer; $context->smarty->assign('confirmation', 1); $cookie->id_customer = (int)$customer->id; $cookie->customer_lastname = $customer->lastname; $cookie->customer_firstname = $customer->firstname; $cookie->passwd = $customer->passwd; $cookie->logged = 1; $context->cookie->email = $customer->email; $context->cart->secure_key = $customer->secure_key; $cookie->write(); //redirect to user page Tools::redirect('index.php?id_category='.$id_customer.'&controller=category'); Link to comment Share on other sites More sharing options...
Eolia Posted February 7, 2016 Share Posted February 7, 2016 le global $cookie, depuis la 1.4, on oublie... Celui-ci est présent dans le contexte, d'ailleurs tu l'utilises dans ton code 1 Link to comment Share on other sites More sharing options...
Alexandre Carette Posted February 8, 2016 Author Share Posted February 8, 2016 (edited) Quand j'enleve le global $cookie; j'ai une erreur php: Warning: Creating default object from empty value in /var/www/html etc... Fatal error: Call to undefined method stdClass::write() in /var/www/html avec ca marche.... Edited February 8, 2016 by Alexandre-KM (see edit history) Link to comment Share on other sites More sharing options...
Eolia Posted February 8, 2016 Share Posted February 8, 2016 Ben oui, mais si tu l'enlèves il faut le réaffecter aussi^^ Link to comment Share on other sites More sharing options...
Alexandre Carette Posted February 8, 2016 Author Share Posted February 8, 2016 ok j arrive un peu mieu a comprendre.... //on change le context pour ecrire dans le cookie $context = Context::getContext(); $context->cookie->__set('id_customer' , $customer->id); $context->cookie->__set('customer_lastname' , $customer->lastname); $context->cookie->__set('customer_firstname' , $customer->firstname); $context->cookie->__set('passwd' , $customer->passwd); $context->cookie->__set('logged' , 1); $context->cookie->__set('email' , $customer->email); $context->cart->secure_key = $customer->secure_key; //redirect to user page Tools::redirect('index.php?id_category='.$id_customer.'&controller=category'); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now