Jump to content

specify redirect URL after redirecting user to login page?


wes
 Share

Recommended Posts

I'm trying to enable temporary site-wide password-only access, and I have this small snippet in my header include:

if(!$user->isLoggedIn()){
	$session->redirect('/cms/login/',false);
}

Works fine for forcing logins on all pages across the site, but my end goal is to actually redirect them back to the page they came from. Currently they just end up in /cms/. Is there a GET var I can pass /cms/login/ which will specify where to send them next?

Something like this I was thinking:

$session->redirect("/cms/login/?next_url=" . $page->path, false)

Worse case I could put together a custom login template, but was curious if there was a simple solution.

Link to comment
Share on other sites

So you're using ProcessWire Admin login for frontend login?

ProcessLogin is only meant for backend login, and it has only a GET id for editing pages. So the id (if set with ?id=1231) will get appended to the form action url. This will be looked for and redirect to the edit screen after login.

ProcessLogin::afterLoginRedirect is hookable, so you could replace it depending on what user logs in. 

After all since it looks like a front end login you should consider creating your own login form, where you have full control and don't let everybody see where your backend login is.

  • Like 1
Link to comment
Share on other sites

After all since it looks like a front end login you should consider creating your own login form, where you have full control and don't let everybody see where your backend login is.

Yes good point. It's better in this situation to just put together a quick front-end login template. Thanks Soma

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...