Redirect if logged in?

Permalink 2 users found helpful
Hi
I wonder if it's possible to have a redirect on a link (page) in a autonav, but only if the user is logged in?

I have one page in my navigation setup as a login page with the login addon.

Now when a user logs in they are automatically redirected to a subpage of the loginpage. That is set in User & Groups login setting in the dashboard.

I have also set up so that the login form is invisible when logged in.

But since that page now is empty when I'm logged in, I want to have the same redirect if I click on the link in the main auto nav, as when I first login.

Sortof, if user is logged in -> click on Members page link -> redirect to News page in side bar.

Does this make sense? I hope so ;)

Can this be done?

Regards
Olle

 
Mnkras replied on at Permalink Reply
Mnkras
you can use page events,

or hard code it into the block controller
SVijay replied on at Permalink Reply
SVijay
Hi,

If you have checked whether a user is logged in or not, then insert a redirection code in view.php
$this->redirect('yourpage');

or



to redirect to another page if a user is logged in.

For checking whether a user is logged in or not, visit the given links

http://www.concrete5.org/community/forums/customizing_c5/determine_...


https://www.concrete5.org/community/forums/customizing_c5/discrimina...


http://wiki.razrlight.com/concrete5_cheatsheet...
- section: Check if user is logged in
Ale replied on at Permalink Reply
To OpenJuiceVijay:

Have you tested your method if the full page cache is enabled? Does it fire the redirect event even then?
jbx replied on at Permalink Reply
jbx
Haven't tested - but I would assume Vijay meant to put the calls into the controller. I reckon it will be too late by the time you hit the view. Put the code into your page controller.

Another possible approach that wouldn't even involve code...
If you set the permissions of the login page, so that it's only viewable by guests, not registered users, and if you're autonav is set to hide pages that users don't have permission to view, then once logged in, that link automagically vanishes from the autonav.

Would that work for you??

Jon
SVijay replied on at Permalink Reply
SVijay
Hi Ale,

We are just redirecting the page to some other page if a user is logged in.
Ale replied on at Permalink Reply
Thanks for your replies.

Just to clarify, I'm not actually having the same problem as the thread starter but I'm looking for an elegant solution to redirect users automatically for first childpage, for example.

I know how the "replace link with first in nav" works with autonav block, but it doesn't redirect user if someone comes to page with direct url instead of clicking on nav item.

So far I've been using a custom attribute that header.php checks and if necessary, gets the url of first childpage and triggers header(location: ). That however, doesn't work if the page has been cached in full page cache.
jbx replied on at Permalink Reply
jbx
Ahh, I have an addon in development that will do just that. It adds a page attribute that you add to these pages and enter the collection ID nof the page you want to redirect to. Anytime that page is hit, it will then perform a 301 redirect. When the addon is finished, it will have a nice button to click, so that you can select the page from the sitemap, but currently, you have to lookup the CollectionID and enter it manually.

If that is ok for you, I can let you have the beta version of the block. It is stable and running on a production site already. Got some other neat redirect options in there too.

PM me your email if you're interested.

Jon
Ale replied on at Permalink Reply
Hey thanks! I've been thinking of developing such add-on but so far haven't just started...

Check your PM :)
SVijay replied on at Permalink Reply
SVijay
Hi Ale,

I am not sure with your problem, but visit the given links it may help you


http://www.concrete5.org/documentation/developers/system/caching...


https://www.concrete5.org/community/forums/chat/cacheand039ing-andam...

Good luck !!!
Ale replied on at Permalink Reply
Ok I'll try to clarify some more.

Lets assume that you have your site at:
http://www.yoursite.com

...but when user types the address in their browser, you would like to have them automatically directed to:
http://www.yoursite.com/en/

In this case, the page /en would be right under the root page in sitemap.

So far I've used a custom page attribute "redirect_to_first_child". The theme's header.php checks if the page has that attribute and if it has, it triggers the header(location) and redirects the user to first child page.

This has worked nicely until the full page cache was introduced in 5.4.1. Now don't get me wrong, the cache is an awesome feature! But if the page is cached as static html, the php scripts in header.php will never be executed.

I know it's possible to disable cache for the page, but I'm looking for a solution that would do the redirects without disabling cache. Also, I think it's not efficient to load all the theme stuff just to redirect to another page and do it all over again. I mean, it would be nice to have such redirect feature in the core and the ability the easily manage redirects in sitemap.

However, it seems that jbx has provided some solution. Now let's see how that works...
SVijay replied on at Permalink Reply
SVijay
Good luck !!!
olleka replied on at Permalink Reply
Hi everyone.
Thanks for all the input! And sorry for the late reply. Been busy all day.

At the moment I use a method described in the thread below. A bit similar like some of the methods above. Works very well for me in this case.

I'll try the permissions trick later. Because in my case it would be nice if the login page actually dissapear when logged in.

I'll also be interested in the beta addon that jbx have. So if you don't mind i can test it for you ...

http://www.concrete5.org/community/forums/documentation_efforts/how...

Thank you again
Olle