Juandbbam Posted May 4, 2013 Share Posted May 4, 2013 Hello, I would need to set up an expiration date for registered users. For example, the acces to the shop for all users from a certain group will expire X days after they registered. Is there any way of getting this please? Thank you in advance Link to comment Share on other sites More sharing options...
vekia Posted May 4, 2013 Share Posted May 4, 2013 by default it isn't possible. In this case you need to create own module or own core modificaitons. If you are interested i can say something more about it. Link to comment Share on other sites More sharing options...
Juandbbam Posted May 5, 2013 Author Share Posted May 5, 2013 Thank you vekia, Yes, I'm really interested Thanks a lot! Link to comment Share on other sites More sharing options...
vekia Posted May 5, 2013 Share Posted May 5, 2013 hello so i must know what prestashop version you use Link to comment Share on other sites More sharing options...
komodityagro Posted May 5, 2013 Share Posted May 5, 2013 Hi Vekia, I have PS 1.5.4.0. How can I make an expiration date for registered users? Link to comment Share on other sites More sharing options...
vekia Posted May 5, 2013 Share Posted May 5, 2013 by default, customer table in database has got information, when the account was created: date_add - we will use it. so, the most important thing in login process is AuthController located in controllers/front/AuthController.php and the function for "login" process is: protected function processSubmitLogin() search for it in the code. $customer = new Customer(); $authentication = $customer->getByEmail(trim($email), trim($passwd)); if (!$authentication || !$customer->id) $this->errors[] = Tools::displayError('Authentication failed.'); else { $this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id); $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->logged = 1; $customer->logged = 1; $this->context->cookie->is_guest = $customer->isGuest(); $this->context->cookie->passwd = $customer->passwd; $this->context->cookie->email = $customer->email; // Add customer to the context $this->context->customer = $customer; 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 { $this->context->cart->id_carrier = 0; $this->context->cart->setDeliveryOption(null); $this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); $this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); } $this->context->cart->id_customer = (int)$customer->id; $this->context->cart->secure_key = $customer->secure_key; $this->context->cart->save(); $this->context->cookie->id_cart = (int)$this->context->cart->id; $this->context->cookie->write(); $this->context->cart->autosetProductAddress(); Hook::exec('actionAuthentication'); // Login information have changed, so we check if the cart rules still apply CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); if (!$this->ajax) { if ($back = Tools::getValue('back')) Tools::redirect(html_entity_decode($back)); Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? url_encode($this->authRedirection) : 'my-account')); } } and change it to: if (!$authentication || !$customer->id) $this->errors[] = Tools::displayError('Authentication failed.'); else { $days=14; if ((strtotime($customer->date_add)+($days*60*60*24))<date("U")){ $this->errors[] = Tools::displayError('Account expired.'); } else { $this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id); $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->logged = 1; $customer->logged = 1; $this->context->cookie->is_guest = $customer->isGuest(); $this->context->cookie->passwd = $customer->passwd; $this->context->cookie->email = $customer->email; // Add customer to the context $this->context->customer = $customer; 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 { $this->context->cart->id_carrier = 0; $this->context->cart->setDeliveryOption(null); $this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); $this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); } $this->context->cart->id_customer = (int)$customer->id; $this->context->cart->secure_key = $customer->secure_key; $this->context->cart->save(); $this->context->cookie->id_cart = (int)$this->context->cart->id; $this->context->cookie->write(); $this->context->cart->autosetProductAddress(); Hook::exec('actionAuthentication'); // Login information have changed, so we check if the cart rules still apply CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); if (!$this->ajax) { if ($back = Tools::getValue('back')) Tools::redirect(html_entity_decode($back)); Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? url_encode($this->authRedirection) : 'my-account')); } } } as you can see - i added this code: $days=14; if ((strtotime($customer->date_add)+($days*60*60*24))<date("U")){ $this->errors[] = Tools::displayError('Account expired.'); } else { .. login code here... } the $days defines number of days, after this time account will be "expired" Link to comment Share on other sites More sharing options...
komodityagro Posted May 5, 2013 Share Posted May 5, 2013 Thanks vekia, and else one question. Is possible for the different registred users the different expiration date? Link to comment Share on other sites More sharing options...
vekia Posted May 5, 2013 Share Posted May 5, 2013 sure, you can use $customer->id also customer group in if condition . for example: customer with id = 4 if ($customer->id == 4){ $days=15; } customer with id = 100 if ($customer->id==100) { $days =9; } Link to comment Share on other sites More sharing options...
komodityagro Posted May 6, 2013 Share Posted May 6, 2013 Hi vekia, but the code $days=14; if ((strtotime($customer->date_add)+($days*60*60*24))<date("U")){ $this->errors[] = Tools::displayError('Account expired.'); } else { in AuthController.php is not working. Link to comment Share on other sites More sharing options...
Juandbbam Posted May 6, 2013 Author Share Posted May 6, 2013 Thank you vekia, I have not tried your code yet as komodityagro, but one question: Once expired how the customer appear in BO, as not activated once expired? It would be great if after expiration the user is not activated in BO so it can be manually activated again from BO. Thanks a lot for your great help and support, vekia!! Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 It's not working as you expect, in this case we need other modifications of prestashop controllers Link to comment Share on other sites More sharing options...
komodityagro Posted May 6, 2013 Share Posted May 6, 2013 My code AuthController.php: ... Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 My code AuthController.php: ... i deleted your code, post was unreadable at all. In this case its better to say what prestashop version you use. Link to comment Share on other sites More sharing options...
komodityagro Posted May 6, 2013 Share Posted May 6, 2013 I use PS 1.5.4.0 Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 thanks you may need to add the: $customer->toggleStatus(); into the if condition which I created several post above: $days=14; if ((strtotime($customer->date_add)+($days*60*60*24))<date("U")){ $this->errors[] = Tools::displayError('Account expired.'); $customer->toggleStatus(); } else { .. login code here... } Link to comment Share on other sites More sharing options...
komodityagro Posted May 6, 2013 Share Posted May 6, 2013 I added the code $days=14; if ((strtotime($customer->date_add)+($days*60*60*24))<date("U")){ $this->errors[] = Tools::displayError('Account expired.'); $customer->toggleStatus(); } else { .. login code here... } to AuthController.php but still is not working. Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 read all of my posts in this thread. i show step by step what code you have to add and where. http://www.prestashop.com/forums/index.php?/topic/244745-expiration-date-for-registered-users/page__view__findpost__p__1213259 Link to comment Share on other sites More sharing options...
komodityagro Posted May 6, 2013 Share Posted May 6, 2013 I understand all, function processSubmitLogin in AuthController.php is bellow. But when I click on Login appears only clear site. protected function processSubmitLogin() { Hook::exec('actionBeforeAuthentication'); $passwd = trim(Tools::getValue('passwd')); $email = trim(Tools::getValue('email')); if (empty($email)) $this->errors[] = Tools::displayError('An email address required.'); elseif (!Validate::isEmail($email)) $this->errors[] = Tools::displayError('Invalid email address.'); elseif (empty($passwd)) $this->errors[] = Tools::displayError('Password is required.'); elseif (!Validate::isPasswd($passwd)) $this->errors[] = Tools::displayError('Invalid password.'); else { $customer = new Customer(); $authentication = $customer->getByEmail(trim($email), trim($passwd)); if (!$authentication || !$customer->id) $this->errors[] = Tools::displayError('Authentication failed.'); else { $days=14; if ((strtotime($customer->date_add)+($days*60*60*24))<date("U")){ $this->errors[] = Tools::displayError('Account expired.'); $customer->toggleStatus(); } else { $this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id); $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->logged = 1; $customer->logged = 1; $this->context->cookie->is_guest = $customer->isGuest(); $this->context->cookie->passwd = $customer->passwd; $this->context->cookie->email = $customer->email; // Add customer to the context $this->context->customer = $customer; 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 { $this->context->cart->id_carrier = 0; $this->context->cart->setDeliveryOption(null); $this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); $this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); } $this->context->cart->id_customer = (int)$customer->id; $this->context->cart->secure_key = $customer->secure_key; $this->context->cart->save(); $this->context->cookie->id_cart = (int)$this->context->cart->id; $this->context->cookie->update(); $this->context->cart->autosetProductAddress(); Hook::exec('actionAuthentication'); // Login information have changed, so we check if the cart rules still apply CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); if (!$this->ajax) { if ($back = Tools::getValue('back')) Tools::redirect(html_entity_decode($back)); Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? url_encode($this->authRedirection) : 'my-account')); } } } if ($this->ajax) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); } else $this->context->smarty->assign('authentification_error', $this->errors); } Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 if you use code you pasted - there is one } close tag missed at the end. Link to comment Share on other sites More sharing options...
komodityagro Posted May 6, 2013 Share Posted May 6, 2013 Thanks, now is it O.K Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 awesome :-) can you check how it works for you? Does it work in back office exactly as you expect? Link to comment Share on other sites More sharing options...
komodityagro Posted May 6, 2013 Share Posted May 6, 2013 Expiration date works but I can´t see it in Back office. Link to comment Share on other sites More sharing options...
vekia Posted May 6, 2013 Share Posted May 6, 2013 Hello, in back office you can active / deactive account. if you want additional information about expiry date - it needs additional modifications of controllers I marked this thread as solved - but if you've got any other questions related to this case - feel free to continue discussion here Link to comment Share on other sites More sharing options...
komodityagro Posted May 6, 2013 Share Posted May 6, 2013 Hello, thanks very much for your helping. Link to comment Share on other sites More sharing options...
Juandbbam Posted May 8, 2013 Author Share Posted May 8, 2013 (edited) Thank you for your help vekia. Just one last question: Once the user is deactivated, if I activate him and the user logins afterwards he cannot and gets deactivated, as the login date remains the same. Is there anyway of activating the account again if needed? Maybe using date_upd instead of date_add? Thank you in advance! Edited May 8, 2013 by Juandbbam (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted May 8, 2013 Share Posted May 8, 2013 Thank you for your help vekia. Just one last question: Once the user is deactivated, if I activate him and the user logins afterwards he cannot and gets deactivated, as the login date remains the same. Is there anyway of activating the account again if needed? Maybe using date_upd instead of date_add? Thank you in advance! yo've got right my friend. Try with date_upd instead date_add! Link to comment Share on other sites More sharing options...
Juandbbam Posted May 8, 2013 Author Share Posted May 8, 2013 Ok, thanks a lot for your help! Link to comment Share on other sites More sharing options...
vekia Posted May 8, 2013 Share Posted May 8, 2013 Ok, thanks a lot for your help! i've got one question for you. Have you got an access to the phpmyadmin or something similar to manage database? Link to comment Share on other sites More sharing options...
komodityagro Posted May 15, 2013 Share Posted May 15, 2013 Hi vekia, can you more explain this below? Where have I add the code? sure, you can use $customer->id also customer group in if condition . for example: customer with id = 4 if ($customer->id == 4){ $days=15; } customer with id = 100 if ($customer->id==100) { $days =9; } Link to comment Share on other sites More sharing options...
vekia Posted May 15, 2013 Share Posted May 15, 2013 right after the: $days=14; Link to comment Share on other sites More sharing options...
komodityagro Posted May 15, 2013 Share Posted May 15, 2013 Thanks... Link to comment Share on other sites More sharing options...
vekia Posted May 15, 2013 Share Posted May 15, 2013 let me know if this will work for you! i tested it in my demo store and it works well Link to comment Share on other sites More sharing options...
komodityagro Posted May 16, 2013 Share Posted May 16, 2013 Well, it works. But how can I cancel expiration and customer could connect again to the account? Link to comment Share on other sites More sharing options...
vekia Posted May 16, 2013 Share Posted May 16, 2013 By this you mean that you want to remove expiration feature ? just remove the code that you pasted and everything will work as work before the changes. Please let me know if I understand you well Link to comment Share on other sites More sharing options...
komodityagro Posted May 17, 2013 Share Posted May 17, 2013 I want to restore customer account after expiration and it will be active for next few days. And what if are many of customers? Is it possible to edit its from BO? Link to comment Share on other sites More sharing options...
vekia Posted May 17, 2013 Share Posted May 17, 2013 Nope, it isn't possible to edit this from BO. Im going to check the code, maybe there is an easiest way to achieve this (and maybe to create feature in back office) Link to comment Share on other sites More sharing options...
komodityagro Posted May 17, 2013 Share Posted May 17, 2013 Thanks... Link to comment Share on other sites More sharing options...
Recommended Posts