Page 1 of 1

[SOLVED] logoutAction to last page being viewed

Posted: Wed Apr 26, 2023 12:34 am
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.)

[SOLVED] logoutAction to last page being viewed

Posted: Wed Apr 26, 2023 3:18 am
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=

Re: logoutAction to last page being viewed

Posted: Tue May 02, 2023 5:56 pm
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.

Re: [SOLVED] logoutAction to last page being viewed

Posted: Tue May 02, 2023 7:08 pm
by wiz
Fixed with latest WonderCMS 3.4.2 version. :) Now released.
https://www.wondercms.com/news