Login Redirect

Permalink
Concrete Version 5.7.5.13

I searched the forum for this and cannot find the answer.

I am trying to do a redirect back to the page the user logs in from. I have the Community Store installed and would love the user to be about the login in and not be redirected back to the Home Page, instead the page they clicked login from.

mdius
 
Gondwana replied on at Permalink Reply
Gondwana
Unfortunately, I think this would make a good feature request. I could have used it too.

As it is, I think you'd need to customise the login page. Hopefully the redirect URL would be in $_SERVER['HTTP_REFERER'], although you probably shouldn't get at it that way.
Steevb replied on at Permalink Reply
Steevb
I want the exact same thing for customers. Used to work with 8.3.1, but will NOT work with 8.3.2?

Try:
<a href="<?php echo $view->url('/login','forward', $c->getCollectionID())?>"> <?php echo t('Sign in')?></a>


Or:
<a href="<?=$this->url('/login', 'forward', $c->getCollectionID())?>"> <?php echo t('Sign in')?></a>
mnakalay replied on at Permalink Reply
mnakalay
In all version of Concrete5 including 5.7.5.13 and 8.3.1 (not tested in 8.3.2) this works for me:
<?php
$page = Page::getCurrentPage();
$loginurl = URL::to('/login', 'forward', $page->getCollectionID());
?>
<a href="<?php echo $loginurl; ?>" >Click here to login</a>

For this to work you have to make sure in your dashboard under dashboard/system/registration/postlogin, you set yur redirection option to "homepage"
Of course there is no way to redirect someone who goes directly to the login page instead of clicking on the link
Steevb replied on at Permalink Reply
Steevb
None of the above options work with 8.3.2?
mnakalay replied on at Permalink Reply
mnakalay
@Steevb I just checked and it doesn't work in 8.3.2 because there is a typo. If yu want it to work modify the file concrete\src\User\PostLoginLocation.php line 118.
There is an error where $$normalized should be $normalized (notice the extra $)

This has already been corrected in the next version by the way
Steevb replied on at Permalink Reply
Steevb
Bloody brilliant, thanks.
mdius replied on at Permalink Reply
mdius
That is awesome!

Now though, I tried to use your code with a small change:
<?php
$page = Page::getCurrentPage();
$regurl = URL::to('/register', 'forward', $page->getCollectionID());
?>
<a href="<?php echo $regurl; ?>" >Click here to login</a>


Then discovered that the register.php has an extra page, so it doesn't quite work. If I place it in the register.php page it puts me back on the registration form. My test site is broken, so I don't want to experiment with trying to get it working on the live site.
mnakalay replied on at Permalink Reply
mnakalay
this should not be on the register page. This is a link that should be on any other page where the user might be. They would then click on the link to go to the registration page that will be informed to redirect them to the original page after registration.

Putting it on the register page serves no purpose since they're already there.

Or maybe I misunderstood you?
mdius replied on at Permalink Reply
mdius
I am using Community Store and on the checkout page there is a Register link, if the user goes to check out and decided to register it would be nice if they could end up at the checkout page then.

https://www.mdius.com/switches/clamps-clips...

Add that to the cart and click checkout to see what I mean, if you'd like.
mdius replied on at Permalink Reply
mdius
You know, I could put a link to the cart at the bottom of the page I suppose. Then it would be a simple way to either go the the home page or cart.
Unless you got a better, more clever idea.
mnakalay replied on at Permalink Best Answer Reply
mnakalay
from what i can see you have a customized registration page.

try this:
In your register.php single page, where you have
<?php   switch ($registerSuccess) {
        case "registered":
            ?>
   <p><strong><?php echo $successMsg ?></strong><br/><br/>
   <a href="<?php echo $view->url('/')?>"><?php echo t('Return to Home')?></a></p>
   <?php
        break;

modify like this:
<?php   switch ($registerSuccess) {
        case "registered":
            if (!empty($rcID)) {
                $rc = Page::getByID($rcID);
                if ($rc instanceof Page && !$rc->isError()) {
                    $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
                    $navigation = $app->make('helper/navigation');
                    $rUrl = $navigation->getLinkToCollection($rc);
                    $r = new RedirectResponse($rUrl);
                    $r->send();
                    exit;
                }
            }
            ?>
   <p><strong><?php echo $successMsg ?></strong><br/><br/>

it will redirect you to the page where you were before clicking that register link

Reminder: For this to work you have to make sure in your dashboard under dashboard/system/registration/postlogin, you set your redirection option to "homepage"
mdius replied on at Permalink Reply
mdius
You are amazing!

Worked perfectly!

Thank you so very much!
mnakalay replied on at Permalink Reply
mnakalay
You are very welcome :)
Ta2Ta2 replied on at Permalink Reply
Life saver! thanks for this one..
michaelfm replied on at Permalink Reply
michaelfm
This used to work for me, too. However, the redirect does not work in 8.4 anymore. The forward link is generated including the correct page id: /login/forward/220, yet the user is still being redirect to the homepage.

Did I overlook any changes to the forward behavior? Anyone experiencing the same?
Steevb replied on at Permalink Reply
Steevb
Working 4 me, which code snippet r u using?
michaelfm replied on at Permalink Reply
michaelfm
Hi Steevb,
I used the following code provided by mnakalay (thank you!) and I can confirm it works just fine with a clean install of concrete5 8.4.1:
<?php
$page = Page::getCurrentPage();
$loginurl = URL::to('/login', 'forward', $page->getCollectionID());
?>
<a href="<?php echo $loginurl; ?>" >Click here to login</a>


I am now investigating the particular server setup and customized theme that has been used. Redirect to "homepage" has been set.
mnakalay replied on at Permalink Reply
mnakalay
For this to work you have to make sure in your dashboard under dashboard/system/registration/postlogin, you set your redirection option to "homepage"