Post by rliston » Sat Sep 21, 2019 3:32 am

I have OpenCart 3.0.3.2 using OCMOD. I'd like the logged in customer session to end after 30 minutes of inactivity and redirect to the account login page, index.php?route=account/login. How do I do this?

Newbie

Posts

Joined
Fri Feb 22, 2013 7:21 pm

Post by opencartmart » Sat Sep 21, 2019 2:33 pm

File name: catalog/controller/common/header.php
Find the following line:

Code: Select all

if ($this->customer->isLogged()) {
Now add following lines of code after that.

Code: Select all

if (isset($this->session->data['last']) && (time() - $this->session->data['last'] > 30 * 60)) {
           $this->customer->logout();
            unset($this->session->data['last']);
           $this->response->redirect($this->url->link('account/login', '', true));
 }
$this->session->data['last'] = time();
P.S:
1. It will logout the users at their next activity attempt after 30 minutes
2. It is recommended to use ocmod instead of modifying file directly
3. There is no ajax involvement here therefore it will not redirect automatically

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by rliston » Sun Sep 22, 2019 1:13 pm

That worked, thanks! :)

Newbie

Posts

Joined
Fri Feb 22, 2013 7:21 pm

Post by opencartmart » Mon Sep 23, 2019 3:05 pm

Glad to hear. Thanks

XForm - Opencart Form Builder
Xshippingpro - An advanced Shipping Module
Need Professional support? Skype: opencartmart


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am

Post by ajadco » Tue Sep 01, 2020 3:09 pm

Hi, I am new to OpenCart, I tried the code you mentioned earlier for OC 3.0.3.2 but didn't work, can anybody help ???
I want customers who already logged in to their account to be logged out after 30 minutes of inactivity, if the site is still open or closed.
Thanks

Newbie

Posts

Joined
Thu Jul 13, 2017 7:46 pm

Post by letxobnav » Tue Sep 01, 2020 3:57 pm

I would use:

Code: Select all

$this->response->redirect($this->url->link('account/login', 'inactive', true));
so you can check the get variable "inactive" on the sign-in page and set a message that the user was signed-out because of inactivity.
otherwise set a message about the 30min inactivity limit on the sign-in page like:

Code: Select all

if (isset($this->request->get['inactive'])) {
  sign out message
} else {
  limit message
}

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by ajadco » Tue Sep 01, 2020 4:44 pm

letxobnav wrote:
Tue Sep 01, 2020 3:57 pm
I would use:

Code: Select all

$this->response->redirect($this->url->link('account/login', 'inactive', true));
so you can check the get variable "inactive" on the sign-in page and set a message that the user was signed-out because of inactivity.
otherwise set a message about the 30min inactivity limit on the sign-in page like:

Code: Select all

if (isset($this->request->get['inactive'])) {
  sign out message
} else {
  limit message
}
I am not sure exactly where to put the code you advised.

Newbie

Posts

Joined
Thu Jul 13, 2017 7:46 pm

Post by letxobnav » Tue Sep 01, 2020 5:25 pm

in the file catalog/controller/common/header.php
you have:

Code: Select all

		// Wishlist
		if ($this->customer->isLogged()) {
you can add after that:

Code: Select all

			// automatic sign out after 20 min inactivity
			if (isset($this->session->data['last']) && (time() - $this->session->data['last'] > 20 * 60)) {
				$this->customer->logout();
				unset($this->session->data['last']);
				$this->response->redirect($this->url->link('account/login', 'inactive', true));
			}
			$this->session->data['last'] = time();
in the file catalog/controller/account/login.php
just before:

Code: Select all

		$this->response->setOutput($this->load->view('account/login', $data));
you can add:

Code: Select all

		if (isset($this->request->get['inactive'])) {
			$data['message'] = '<p><i>For your security, you have been Signed Out due to 20 min of inactivity</i></p>';
		} else {
			$data['message'] = '<p><i>For your security, you will be Signed Out after 20 min of inactivity</i></p>';
		}
you can later refer those messages to your language files.

in file catalog/view/theme/default/template/account/login.twig
you add wherever you want the message to show:

Code: Select all

{{ message }}

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by ajadco » Wed Sep 02, 2020 3:53 pm

My friend,
I tried the code exactly as you said but no luck, I forgot to tell you that I use Journal 3 on OpenCart 3.0.3.2. I added the last code in:
catalog/view/theme/journal/template/account/login.twig
What do you think the problem is ???

Newbie

Posts

Joined
Thu Jul 13, 2017 7:46 pm

Post by letxobnav » Wed Sep 02, 2020 5:46 pm

you cleared the theme cache and any other cache journal might have?

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by ajadco » Thu Sep 03, 2020 1:42 pm

Yes I did but also no luck

Newbie

Posts

Joined
Thu Jul 13, 2017 7:46 pm

Post by letxobnav » Thu Sep 03, 2020 3:36 pm

the automatic logout works right?
just the message does not work?

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by ajadco » Thu Sep 03, 2020 4:02 pm

No the automatic logout doesn't work
The most important thing for me is to logout customers automatically after 30 min or 60 min of inactivity in the website
again I use OpenCart 3.0.3.2 with Journal 3 Theme, I also use an extention called: Page after login - strict login (cartbinder@gmail.com)

Newbie

Posts

Joined
Thu Jul 13, 2017 7:46 pm

Post by letxobnav » Thu Sep 03, 2020 4:34 pm

then you probably already have a modification running on the header controller and on your login controller.
check in your modification directory if there is a catalog/controller/common/header.php and/or catalog/controller/account/login.php in there.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by nightwing » Fri Nov 13, 2020 10:43 am

Hey letxobnav, thanks, this worked for my 3.0.3.2 install. How can we force a refresh at this point to redirect to logout page automatically?
Thanks
letxobnav wrote:
Tue Sep 01, 2020 5:25 pm
in the file catalog/controller/common/header.php
you have:

Code: Select all

		// Wishlist
		if ($this->customer->isLogged()) {
you can add after that:

Code: Select all

			// automatic sign out after 20 min inactivity
			if (isset($this->session->data['last']) && (time() - $this->session->data['last'] > 20 * 60)) {
				$this->customer->logout();
				unset($this->session->data['last']);
				$this->response->redirect($this->url->link('account/login', 'inactive', true));
			}
			$this->session->data['last'] = time();
in the file catalog/controller/account/login.php
just before:

Code: Select all

		$this->response->setOutput($this->load->view('account/login', $data));
you can add:

Code: Select all

		if (isset($this->request->get['inactive'])) {
			$data['message'] = '<p><i>For your security, you have been Signed Out due to 20 min of inactivity</i></p>';
		} else {
			$data['message'] = '<p><i>For your security, you will be Signed Out after 20 min of inactivity</i></p>';
		}
you can later refer those messages to your language files.

in file catalog/view/theme/default/template/account/login.twig
you add wherever you want the message to show:

Code: Select all

{{ message }}

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by sw!tch » Fri Nov 13, 2020 11:49 am

nightwing wrote:
Fri Nov 13, 2020 10:43 am
How can we force a refresh at this point to redirect to logout page automatically?
Thanks
You handle a check via an event listener and Ajax .

FWIW - The header shouldn't really be responsible for handling this type of logic.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by nightwing » Fri Nov 13, 2020 12:17 pm

Ok noted... I will do some research and implement.
sw!tch wrote:
Fri Nov 13, 2020 11:49 am
nightwing wrote:
Fri Nov 13, 2020 10:43 am
How can we force a refresh at this point to redirect to logout page automatically?
Thanks
You handle a check via an event listener and Ajax .

FWIW - The header shouldn't really be responsible for handling this type of logic.

Regards,
Nightwing
Access to my Free Extensions: https://www.opencart.com/index.php?rout ... =nightwing


Active Member

Posts

Joined
Tue Nov 05, 2019 11:08 pm


Post by straightlight » Fri Nov 13, 2020 12:32 pm

sw!tch wrote:
Fri Nov 13, 2020 11:49 am
nightwing wrote:
Fri Nov 13, 2020 10:43 am
How can we force a refresh at this point to redirect to logout page automatically?
Thanks
You handle a check via an event listener and Ajax .

FWIW - The header shouldn't really be responsible for handling this type of logic.
+ 1

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by gitbro » Fri Oct 28, 2022 6:56 am

Anyone know how to to make this refresh the page auto in stead of waiting for the customer to return and refresh before it logs them out.

Thanks.

New member

Posts

Joined
Sat Oct 31, 2015 6:58 am

Post by straightlight » Fri Oct 28, 2022 8:59 pm

gitbro wrote:
Fri Oct 28, 2022 6:56 am
Anyone know how to to make this refresh the page auto in stead of waiting for the customer to return and refresh before it logs them out.

Thanks.
With jQuery, this can be done. Look it up on Google.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 46 guests