TinyPortal

Development => Support => Topic started by: dbtees on October 11, 2012, 06:15:37 PM

Title: Per membergroup login redirect?
Post by: dbtees on October 11, 2012, 06:15:37 PM
Is there a way I can redirect certain membergroups to a different page on login? I have TP set up to go to a custom homepage, but I want some membergroups (at this point only one) to be sent directly to the forum as they don't have permission to see the articles on the homepage. I've been looking for a place to stick the code, but have yet to find it. Searching here didn't turn up an answer so figured I'd ask. Sorry if it's been asked before.
Title: Re: Per membergroup login redirect?
Post by: dbtees on October 11, 2012, 07:26:46 PM
Found a way. Perhaps not the "best" way, but it seems to work. If someone smarter than me can confirm it's not a silly way of doing it...

In subs.php under the redirectexit function, added $user_info to the global declarations:

global $scripturl, $context, $modSettings, $db_show_debug, $db_cache, $user_info;

Then changed this:

if ($setLocation == $scripturl && !$tp_not && !empty($context['TPortal']['redirectforum']))

To this:

if ($setLocation == $scripturl && !$tp_not && (!empty($context['TPortal']['redirectforum']) || in_array('19',$user_info['groups'])))

So anyone in membergroup 19 gets sent to the forums while everyone else goes to the frontpage.
Title: Re: Per membergroup login redirect?
Post by: IchBin on October 11, 2012, 08:44:08 PM
Perfectly fine hack IMO. Just remember you lose these changes in an upgrade.
Title: Re: Per membergroup login redirect?
Post by: dbtees on October 11, 2012, 08:47:34 PM
Thanks. Actually this hack was giving me a problem where, after logging in with a user I wanted to be redirected to the forum, if I would then manually type in the base URL of my site it would go to a blank front page with no blocks. I had to add a PHP block to the front page that checks the membergroup of the logged in user and does a javascript redirect to the forums if they match. Inelegant, but it works!
Title: Re: Per membergroup login redirect?
Post by: ZarPrime on October 12, 2012, 02:08:22 PM
Hmmm, very nice. ;) I'll have to make a note to remember this one in the future. O0

ZarPrime
Title: Re: Per membergroup login redirect?
Post by: dbtees on October 12, 2012, 02:15:29 PM
Here's what the "Membergroup Test" frontpage block looks like:

global $user_info;

if (in_array('19',$user_info['groups'])) {

echo '<script type="text/javascript">' . "\r\n" .
'window.location += "?action=forum"' . "\r\n" .
'</script>';

}


Not sure that I needed to do the global $user_info at the top. Didn't try it without. This block has permissions that only membergroup 19 can see it and of course admins see it too, but it doesn't affect them.