Jump to content

Se Logguer Apres Création De Compte


Recommended Posts

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

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

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" ? :P

  • Like 1
Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...