TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 195,856
  • Total Topics: 21,292
  • Online today: 1,096
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 720
  • Total: 720

Per membergroup login redirect?

Started by dbtees, October 11, 2012, 06:15:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dbtees

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.

dbtees

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.

IchBin

Perfectly fine hack IMO. Just remember you lose these changes in an upgrade.

dbtees

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!

ZarPrime

Hmmm, very nice. ;) I'll have to make a note to remember this one in the future. O0

ZarPrime

dbtees

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.

This website is proudly hosted on Crocweb Cloud Website Hosting.