[SOLVED] logoutAction to last page being viewed

Ask for help or provide support to other members.
Post Reply
grimblefritz
Posts: 16
Joined: Tue Apr 25, 2023 1:21 pm

[SOLVED] logoutAction to last page being viewed

Post by grimblefritz »

Logout takes one to the login screen.

I would prefer to go to the last page being view when logout was initiated.

Going to the 'home' page is easy enough:

Code: Select all

$this->redirect($this->get('config', 'defaultPage'));
Specifying 'defaultPage' instead of 'login'.

But how, let's say if I was viewing 'About' and initiate logout, do I get it to redirect to that page? ('About' is just an example - it could be any page.)
grimblefritz
Posts: 16
Joined: Tue Apr 25, 2023 1:21 pm

[SOLVED] logoutAction to last page being viewed

Post by grimblefritz »

I fiddled with this a bit more and found a not too difficult solution, but it does require fiddling in the main index.php

Find function logoutAction().

Change:

Code: Select all

$this->redirect('login');
To this:

Code: Select all

                       if (! empty($_GET['to'])) {
                                // logout to the page you were viewing
                                $this->redirect($_GET['to']);
                        } else if (! empty($this->defaultPage)) {
                                // logout to the default (ie, home) page
                                $this->redirect($this->get('config', 'defaultPage'));
                        } else {
                                // otherwise, default behavior of logout to login
                                $this->redirect('login');
                        }
Then, find function settings().

Change this:

Code: Select all

'logout?token=
To this:

Code: Select all

'logout?to=' . $this->currentPage . '&token=
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: logoutAction to last page being viewed

Post by wiz »

Hello grimblefritz.

We recently implemented this feature but decided not to implement it, since the UX research shows a preference for users to go to the login page, instead of the last visited page.

However, we've implemented a ON/OFF value with the latest releas 3.4.2, which should be released today.
Thanks for bringing this up.
User avatar
wiz
Posts: 749
Joined: Sat Oct 30, 2010 12:23 am

Re: [SOLVED] logoutAction to last page being viewed

Post by wiz »

Fixed with latest WonderCMS 3.4.2 version. :) Now released.
https://www.wondercms.com/news
Post Reply