Redirect back to custom action after login

Started by kkmic, January 14, 2017, 04:08:33 PM

Previous topic - Next topic

kkmic

Hi,

I've added a custom action that is intended to be accesible to logged in users only. Basically, if you are logged in it shows you some information, otherwise it informs you that you need to login, and provides a link to the login page.

It works just fine when you're accesing it while logged in.

However, if you are not logged in, after going to the login page and successfully logging in, you are redirected to the board frontpage.

How can I redirect the user back to my action?
I've... seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched c-beams glitter in the dark near the Tannhäuser Gate. All those... moments... will be lost in time, like tears... in... rain. Time... to die...

kkmic

I did some digging in the LogInOut.php file - there are some statements there noting that the Login() function "caches the referring URL in $_SESSION['login_url']" and that the Login2() function "after successful login, redirects you to $_SESSION['login_url']".

However, after some more code and forum digging, I have found out the the Login() function redirects back only to some URLs, namely those matching this regexp: (board|topic)[=,]

Obviously, my custom action does not match. Apparently, the reason for this picky redirection is that some time ago the board redirected back to things people did not want - like attachments - and this protection was put there.

My question: besides the obvious action of adapting that regexp (which happens to be present once for each of the two login functions), is there a better way? I'd rather not modify the board code unless absolutely necessary.
I've... seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched c-beams glitter in the dark near the Tannhäuser Gate. All those... moments... will be lost in time, like tears... in... rain. Time... to die...

Bob Perry of Web Presence Consulting

There is a very old module that does this and if you can find it, may require a custom install to function correctly, I use it on my system and I think the name of it is http://custom.simplemachines.org/mods/index.php?mod=1443
Best Regards,
Bob Perry



"The world is moving so fast these days that the man who says it can't be done is generally interrupted by someone doing it." Elbert Hubbard

kkmic

Thanks, but no, it does not do what I want. It simply stores two URLs (for after login/logout) and sends you there.

I'm just looking to allow my custom action to be redirected back to after login by the default login mechanism.
I've... seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched c-beams glitter in the dark near the Tannhäuser Gate. All those... moments... will be lost in time, like tears... in... rain. Time... to die...

kkmic

#4
Found a workaround that does not require modifying the SMF core files

As noted before, SMF uses the (board|topic)[=,] regexp to determine if the page that the user came from to the login page should be redirected back to.

Solution:
My custom action does not match the regexp as is:
example.com/index.php?action=customaction [nofollow]

However, due to how SMF (and web servers in general) handle GET parameters, I have realized that URL to the action can be appended with some extra parameters that will make it match, without changing its meaning:
example.com/index.php?action=customaction;board [nofollow],

The ";board," termination will trigger the regexp, and make SMF to happily redirect back to my action.


This is still a hack, however I am more content on using this harmless addition to the URL than to actually having to modify the SMF files.

As an added bonus, it "redirects" back even when using the quick login box.
I've... seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched c-beams glitter in the dark near the Tannhäuser Gate. All those... moments... will be lost in time, like tears... in... rain. Time... to die...

Advertisement: