Jump to content

[Solved] Update database by submitting login


leeloo

Recommended Posts

Hi,
I created a field date_lastvisit in table customer.
I want to update automatically this field when customer submit his login.

In authentification.php (for PS 1.2/1.3) or AuthController.php (for PS 1.4)

if (Tools::isSubmit('SubmitLogin'))
{
   $passwd = trim(Tools::getValue('passwd'));
   $email = trim(Tools::getValue('email'));
   if (empty($email))
       $errors[] = Tools::displayError('e-mail address is required');
   elseif (!Validate::isEmail($email))
       $errors[] = Tools::displayError('invalid e-mail address');
   elseif (empty($passwd))
       $errors[] = Tools::displayError('password is required');
   elseif (Tools::strlen($passwd) > 32)
       $errors[] = Tools::displayError('password is too long');
   elseif (!Validate::isPasswd($passwd))
       $errors[] = Tools::displayError('invalid password');
   else
   {
       $customer = new Customer();
       $authentication = $customer->getByemail(trim($email), trim($passwd));
       /* Handle brute force attacks */
       sleep(1);
       if (!$authentication OR !$customer->id)
           $errors[] = Tools::displayError('authentication failed');
       else
       {
           $cookie->id_customer = intval($customer->id);
           $cookie->customer_lastname = $customer->lastname;
           $cookie->customer_firstname = $customer->firstname;
           $cookie->logged = 1;
           $cookie->passwd = $customer->passwd;
           $cookie->email = $customer->email;
           if (Configuration::get('PS_CART_FOLLOWING') AND (empty($cookie->id_cart) OR Cart::getNbProducts($cookie->id_cart) == 0))
               $cookie->id_cart = intval(Cart::lastNoneOrderedCart(intval($customer->id)));
           $id_address = intval(Address::getFirstCustomerAddressId(intval($customer->id)));
           $cookie->id_address_delivery = $id_address;
           $cookie->id_address_invoice = $id_address;
           Module::hookExec('authentication');

           if ($back = Tools::getValue('back'))
               Tools::redirect($back);
           Tools::redirect('my-account.php');

       }
   }
}



i added

Db::getInstance()->AutoExecute('UPDATE date_lastvisit FROM `'._DB_PREFIX_.'customer` SET date_lastvisit=NOW() ');



after


Module::hookExec('authentication');

But this doesn't work.
How to do that?
Can anyone help me?
Thank you very much.

Solved by myself
           Db::getInstance()->Execute('
           UPDATE `'._DB_PREFIX_.'customer`
           SET date_lastvisit=NOW()
           WHERE id_customer="'.intval($customer->id).'"
           ');    

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