Jump to content

[resolved]how to connect automaticcaly a customer?

Laetitia Bordon

Recommended Posts


I would like to do an automatic connection of a customer with his mail without having to click on login.

I've done that in admin part and that works fine but, in front part, I can't do it.

I don't find where and how the customer's data is retrieved after clicking on login

Is someone can help me?


Edited by Laetitia Bordon
resolved (see edit history)
Link to comment
Share on other sites

Hook: displayCustomerAccount

Otherwise, an email message is visible for each order.
In the administration of the order detail in the messages block there is a button "Display to customer?"
If you want to display all messages on the page of my account, you need to create a module and a hook as I wrote.

You can look at the psgdpr module, there you will see how it works.


Link to comment
Share on other sites


Thanks but I think that's not that I want to do.

When the user click on the link to access to the shop, I want log in him automatically. For the moment, He arrives in the shop and he must click on "login" link to log in.

I want to log him in when he clicks on the link of our intranet so that when he arrives in the shop he is logged in and no longer has to click on the login link.

I know how to get his email from our ldap but I don't know how to make the automatic login.

Link to comment
Share on other sites

I found

In controllers/front/FrontController.php, set $auth and $authRedirection at true (public $auth = true; public $authRedirection = true;)

In controllers/front/AuthController.php, in function initContent(), I do this (don't forget to add "use Symfony\Component\Ldap\Ldap;" before "class AuthControllerCore extends FrontController"

if (Tools::isSubmit('submitCreate') || Tools::isSubmit('create_account')) 
	$register_form = $this 
	if (Tools::isSubmit('submitCreate')) 
		$hookResult = array_reduce(Hook::exec('actionSubmitAccountBefore', array(), null, true), function ($carry, $item) { return $carry && $item; }, true ); 
		if ($hookResult && $register_form->submit()) { $should_redirect = true; } 
		[ 'register_form' => $register_form->getProxy(), 
		'hook_create_account_top' => Hook::exec('displayCustomerAccountFormTop'), ]); 
	$login_form = $this->makeLoginForm()->fillWith( Tools::getAllValues() ); 
	//l'HTTP_USER_AGENT est de la forme "FedPol-Portal/2.0 44123456F" 
    //search mail in ldap
	$ssoPart = array_pop(explode(' ', $sso)); 
	$uid = substr($ssoPart, 0, 9); 
	$container = $this->buildContainer(); 
	$host = $container->getParameter('ldap_host'); 
	$port = intval($container->getParameter('ldap_port')); 
	$base = $container->getParameter('ldap_base'); 
	$classeObject = $container->getParameter('ldap_classe'); 
	$ldap = Ldap::create('ext_ldap', [ 'host' => $host, 'port' => $port ]); 
	$query = $ldap->query($base, '(&(uid='.$uid.')(objectclass='.$classeObject.'))'); 
	$results = $query->execute()->toArray(); 
	$mail = $results[0]->getAttribute("mail")[0]; 
    //call to the function to login customer
		{ $should_redirect = true; } 

	/* old code
	if ($login_form->submit()) 
		{ $should_redirect = true; } 
	if (Tools::isSubmit('submitLogin')) 
		if ($login_form->submit()) { $should_redirect = true; } 
	$this->context->smarty->assign([ 'login_form' => $login_form->getProxy(), ]); 
//rest of function

And, in file classes/form/CustomerLoginForm.php, I added this function

public function test($mail) 
  $customer = new Customer(); 
  $authentication = $customer->getByEmail($mail); 
  if (isset($authentication->active) && !$authentication->active) 
  	{ $this->errors[''][] = $this->translator->trans('Your account isn\'t available at this time, please contact us', [], 'Shop.Notifications.Error'); } 
  elseif (!$authentication || !$customer->id || $customer->is_guest) 
  	{ $this->errors[''][] = $this->translator->trans('Authentication failed.', [], 'Shop.Notifications.Error'); } 
    Hook::exec('actionAuthentication', ['customer' => $this->context->customer]); 
    // Login information have changed, so we check if the cart rules still apply 
  return !$this->hasErrors(); 


In classes/Customer.php files, in array fields of the $definition array, required option of passwd is at false.

I still have to find out how to remove the "Sign out" link.

Link to comment
Share on other sites

To remove the "Sign out" link, I do :

In /themes/classic/modules/ps_customersignin/, create a copy of the file ps_customersignin.tpl and after, remove this in ps_customersignin.tpl

   class="logout hidden-sm-down"
  <i class="material-icons">&#xE7FF;</i>
  {l s='Sign out' d='Shop.Theme.Actions'}

In themes/classic/templates/customer/, create a copy of the file my-account.tpl and after , remove from the file my-account.tpl

In block page_content (the customer can't modify his name, mail,...):

<a class="col-lg-4 col-md-6 col-sm-6 col-xs-12" id="identity-link" href="{$urls.pages.identity}">
  <span class="link-item">
    <i class="material-icons">&#xE853;</i>
    {l s='Information' d='Shop.Theme.Customeraccount'}

And in block footer :

{block name='my_account_links'}
    <div class="text-sm-center">
      <a href="{$logout_url}" >
        {l s='Sign out' d='Shop.Theme.Actions'}

And that's work.

Thank for your help

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