MAMS dynamic return URL with query variables

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm
Location: Nimbin, Australia

MAMS dynamic return URL with query variables

Post by rotezecke »

I have some private pages that test if a user is logged in, and if not, redirects to the login page.

I just forked the {redirect_page} plugin and added a goback=true parameter which grabs the current page alias and adds it as query variable to the redirect URL.

Code: Select all

		$query_vars = '';
		if( !empty($params['goback']) )
		{
			$contentops = cmsms()->GetContentOperations();
			$content_obj = $contentops->getContentObject();
			$thisPageAlias = $content_obj->Alias();
			$query_vars = '?redirect='.urlencode($thisPageAlias);
		}
		if ($content->GetURL() != '') redirect($content->GetURL().$query_vars);
and on the MAMS login page, I test for the redirect and overwrite MAMS' default return URL:

Code: Select all

{if !empty($smarty.get.redirect)}
  {cms_module_hint module=MAMS returnto={$smarty.get.redirect|urldecode}}
{/if}
This works OK.

However, on the original page (before login), I already have some query variables which I'd like to pass along. The passing to login page is easy but I don't know how to overwrite the MAMS return URL and set/keep the query variable as well. Is this possible or would this be a feature request?
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm
Location: Nimbin, Australia

Re: MAMS dynamic return URL with query variables

Post by rotezecke »

After reading in the source code I discovered a public method named SetPostLoginURL() (writing a Session variable) which is used if returnto is not set.
So, before the redirect, I need to call this (via separated UDT or inside my forked plugin)

Code: Select all

$url =  "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$mod = \cms_utils::get_module('MAMS');
$mod->SetPostLoginURL($url);
and I get redirected with all query variables intact.
Post Reply

Return to “Modules/Add-Ons”