Remember last page before login?

Permalink 1 user found helpful
How do I redirect the user back to the page they were first visiting when they log into the site?

elyon
 
Tony replied on at Permalink Reply
Tony
The login page will accept a query string variabled name rcID (stands for redirect collection ID).

So if you forward a user to /login/?rcID=58 after they log in they will be forwarded to index.php?cID=58

This rcID variable also accepts full urls too. Just be sure to run the address through urlencode() first, like

$loginURL=View::url('/login/?rcID='.urlencode($redirectURL));
elyon replied on at Permalink Reply
elyon
That was just what I needed.
elyon replied on at Permalink Reply
elyon
Ah ... having a problem.

I implemented this fix in my login button, and it works great. However, the user still gets kicked back to the homepage if you visit a restricted page and use the login there.

Ideally, I would like for visitors to be able to go towww.www.website.com/restricted_area... and enter their password, then have them returned towww.www.website.com/restricted_area... after logging in. However, I'm not sure if I can change this behavior without editing core files in Concrete, which I would rather not do if I can help it.
Tony replied on at Permalink Reply
Tony
sounds like this would have to be core change. I don't see any reason why what you're wanting shouldn't be the standard behavior though (at least if the user isn't logged in already). It would have to double check that the user could access the restricted page after logging in though, otherwise you could get a nasty page-flow loop thing happening.
Styves replied on at Permalink Reply
Styves
I hope to see one of these days in C5, three options of redirection with the login:

- same page login
- a specific page or directory
- personal page of the user

Cheers.
andrew replied on at Permalink Reply
andrew
we can add this. We added this to concrete5.org, but it's a really simple thing to implement in the core.
elyon replied on at Permalink Reply
elyon
That would be great! If you end up making the fix sometime soon, please feel free to share the changes you made here, so I can patch my client's install and make them happy :)

Thank you!
Styves replied on at Permalink Reply
Styves
... to make it happen.

You make my day!

High 5 Cheers.
elyon replied on at Permalink Reply
elyon
Hey Andrew,

Thanks for the fix!

For anyone who is a developer who isn't using development builds of Concrete5, but wants to make this fix themselves before the next major release, there are only a couple changes to make.


File: /concrete/dispatcher.php

Find:

switch($cp->getError()) {
            case COLLECTION_FORBIDDEN:
               $v = View::getInstance();
               $v->render('/page_forbidden');
               break;
         }


Replace with:

switch($cp->getError()) {
            case COLLECTION_FORBIDDEN:
               $v = View::getInstance();
               $v->setCollectionObject($c);
               $v->render('/page_forbidden');
               break;
         }



File: /concrete/controllers/page_forbidden.php

Replace all with:

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
Loader::controller('/login');
class PageForbiddenController extends LoginController {
   public function view() {
      $v = View::getInstance();
      $c = $v->getCollectionObject();
      if (is_object($c)) {
         $cID = $c->getCollectionID();
         if($cID) { 
            $this->forward($cID); // set the intended url
         }
      }
      parent::view();
      $this->render('/login');