Jump to content

Recommended Posts

I want to create a oauth client module for the prestashop.

Here I can see in prestashop 'ps_customer' table, the password field (passwd) is a not null.

 

If I want to implement oauth client, I will not get any password from the oauth provider, where I can get only the customer details. In that case how to create a session in prestashop without the password.

 

I have seen in some existing modules where they have used facebook login. But I couldn't get clear details on creating sessions in prestashop.

 

Kindly share your comments.

Link to comment
Share on other sites

  • 1 year later...
It is not possible to create a session without password, you can create a dummy password using the following code.

 



$passd = Tools::encrypt($temp_pass);


 

After that use the following code to create a login session in PrestaShop.

 




$customer = new Customer();
$customer->id = $id_customer;
$customer->firstname = ucwords($user_data['first_name']);
$customer->lastname = ucwords($user_data['last_name']);
$customer->passwd = $passd;
$customer->email = $user_data['email'];
$customer->secure_key = $secure_key;
$customer->birthday = '';
$customer->is_guest = 0;
$customer->active = 1;
$customer->logged = 1;


$customer->cleanGroups();
$customer->addGroups(array((int)Configuration::get('PS_CUSTOMER_GROUP')));


$this->sendConfirmationMail($customer, $original_passd);


//Update Context
$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;
$this->context->cookie->email = $customer->email;
$this->context->cookie->is_guest = $customer->is_guest;


//Cart
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->secure_key = $customer->secure_key;


if (isset($id_carrier) && $id_carrier && Configuration::get('PS_ORDER_PROCESS_TYPE'))
{
$delivery_option = array($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();


 

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...