Login redirect / returnto

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
sta777
New Member
New Member
Posts: 8
Joined: Thu Jan 14, 2010 9:52 am

Login redirect / returnto

Post by sta777 »

Hi,

I'm using this piece of code

Code: Select all

{cms_module module=FrontEndUsers form="login" returnto="forum" nocaptcha="1"}
in a Global Content Block called 'Login' to forward users to the forum once logged in, which all works great.

After adding a seperate page/section that also requires login called Articles, I would like to be able to forward the user to the relevant page depending on where they have logged in.

ie. If user logs in on forum page, they get forwarded to the forum.
If they login on the article page, they will get forwarded to the articles page.

I understand i can assign different returnto's depending on user groups, but I only have/want one user group.

I'm guessing it would be something like:

Code: Select all

{if page='articles'}
{cms_module module=FrontEndUsers form="login" returnto="articles" nocaptcha="1"}
{else}
{cms_module module=FrontEndUsers form="login" returnto="forum" nocaptcha="1"}
Any help would be greatly appreciated as I have spent hours trawling the forums and documentation.

Note: Guess I could forward to page where articles, forum etc are listed as links? hmmmm
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Login redirect / returnto

Post by jmcgin51 »

not sure you can do it exactly like you're trying to do it

but maybe you could insert an intermediate page that just handles the redirect based on the referring page

so the FEU call would returnto this intermediate page, and this page would simply include Smarty code to redirect the user as appropriate based on where they came from:

{if the referring page alias = 'page1'}
{redirect to page x}
{elseif the referring page alias = 'page2'}
{redirect to page y}
{elseif the referring page alias = 'page3'}
{redirect to page z}
{/if}
sta777
New Member
New Member
Posts: 8
Joined: Thu Jan 14, 2010 9:52 am

Re: Login redirect / returnto

Post by sta777 »

Thanks for that but I really don't understand.

There must be a simpler way of doing this?
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: Login redirect / returnto

Post by Jeff »

Why don't you just do this?
{cms_module module=FrontEndUsers form="login" returnto=$page_alias nocaptcha="1"}
sta777
New Member
New Member
Posts: 8
Joined: Thu Jan 14, 2010 9:52 am

Re: Login redirect / returnto

Post by sta777 »

Thanks ajprog, but using returnto=$page_alias returns the user to the login screen. arrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: Login redirect / returnto

Post by Jeff »

Then you don't have the template and page structure as you explained.
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Login redirect / returnto

Post by jmcgin51 »

ajprog wrote: Why don't you just do this?
{cms_module module=FrontEndUsers form="login" returnto=$page_alias nocaptcha="1"}
Yep - that would surely be a lot simpler than what I suggested!

I misread what he was trying to do...
sta777
New Member
New Member
Posts: 8
Joined: Thu Jan 14, 2010 9:52 am

Re: Login redirect / returnto

Post by sta777 »

It all sounds great but I still can't get it to work!

my url with the login form:
http://www.xxxxxxxxxxxxxxxxxxxxxxxxxx.o ... page=Login

when I add the returnto=$page_alias it ends up at the login form again but at this address:
http://www.xxxxxxxxxxxxxxxxxxxxxxxxxx.org/login/

wtf?
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: Login redirect / returnto

Post by Jeff »

You said you had the login on each page, and you wanted it to return to the page they logged in from. If that is how your template is setup then my suggest will do as you ask.

From your later post I would have to say your templates are messed up and your config.php or .htaccess is setup wrong.
sta777
New Member
New Member
Posts: 8
Joined: Thu Jan 14, 2010 9:52 am

Re: Login redirect / returnto

Post by sta777 »

There is a page called login, which is hidden. All this does is call a global content block called login with the code:

Code: Select all

{cms_module module=FrontEndUsers form="login" returnto="forum" nocaptcha="1"}
Now within my layout template I have this code:

Code: Select all

<!-- start content -->
             <h1>{title}</h1>
{if $ccuser->loggedin() && $ccuser->memberof('Members')}
            {content}
 {else}
      {redirect_url to='index.php?page=Login'}
        {/if}
<!-- start content -->
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: Login redirect / returnto

Post by Jeff »

replace the redirect with your module or GCB call
sta777
New Member
New Member
Posts: 8
Joined: Thu Jan 14, 2010 9:52 am

Re: Login redirect / returnto

Post by sta777 »

Ok, so something like this?

Code: Select all


<!-- start content -->
             <h1>{title}</h1>
{if $ccuser->loggedin() && $ccuser->memberof('Members')}
            {content}
 {else}
      {module=FrontEndUsers}
        {/if}
<!-- start content -->

Post Reply

Return to “Developers Discussion”