Jump to content
WebFlake
  • 0

If user is already logged in, send him back to main page


BlackShot

Question

Hi folks,

So, my domain's main page is IPB's login one. I chose to do that because it's easier for my user base to sign in. Some are older and have issues finding the login/register button.

But if logged in users access the domain's main page, they'll also be redirected to the login page again. They might not know that they're already logged in and will do so again.

Is there a way to force-redirect logged in users to the forum's main page?

Thanks!

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
{{if \IPS\Member::loggedIn()->member_id}}
	{expression="\IPS\Output::i()->redirect(\IPS\Http\Url::internal('app=forums&module=forums&controller=index'))"}
{{endif}}

Edit the code of the template you want this code to run on, and search loginForm then add the code at the bottom of the page and save. It will redirect users to the forums if they are logged in

  • Love 1
Link to comment
Share on other sites

  • 0
1 hour ago, Gm Prodigy said:



{{if \IPS\Member::loggedIn()->member_id}}
	{expression="\IPS\Output::i()->redirect(\IPS\Http\Url::internal('app=forums&module=forums&controller=index'))"}
{{endif}}

Edit the code of the template you want this code to run on, and search loginForm then add the code at the bottom of the page and save. It will redirect users to the forums if they are logged in

Had I only seen your message before, haha! But I'd like your opinion here.

I actually did some digging myself and edited login.php in applications > core > modules > front > system. There, I changed the following code:

/* Did we just log in? */
        if ( \IPS\Member::loggedIn()->member_id and isset( \IPS\Request::i()->_fromLogin ) )
        {
            \IPS\Output::i()->redirect( \IPS\Http\Url::internal('') );
}

To:

 /* Are we logged in already? */
        if ( \IPS\Member::loggedIn()->member_id )
        {
            \IPS\Output::i()->redirect( \IPS\Http\Url::internal('') );
}

Seems to have worked.

What do you think of my method? Any downsides?

Edited by BlackShot
Link to comment
Share on other sites

  • 0
On 6/1/2021 at 1:25 AM, BlackShot said:

Had I only seen your message before, haha! But I'd like your opinion here.

I actually did some digging myself and edited login.php in applications > core > modules > front > system. There, I changed the following code:


/* Did we just log in? */
        if ( \IPS\Member::loggedIn()->member_id and isset( \IPS\Request::i()->_fromLogin ) )
        {
            \IPS\Output::i()->redirect( \IPS\Http\Url::internal('') );
}

To:


 /* Are we logged in already? */
        if ( \IPS\Member::loggedIn()->member_id )
        {
            \IPS\Output::i()->redirect( \IPS\Http\Url::internal('') );
}

Seems to have worked.

What do you think of my method? Any downsides?

You shouldn't manually edit the origin php files, changes will be lost when you update the forums. It's better to create a hook or just edit the template in ACP if you're lazy.

Link to comment
Share on other sites

  • 0
21 hours ago, Gm Prodigy said:

You shouldn't manually edit the origin php files, changes will be lost when you update the forums. It's better to create a hook or just edit the template in ACP if you're lazy.

I figured that. You're right! I'm not familiar with creating hooks, but I guess it shouldn't be that hard, right? If you have any links/instructions to share, feel free to do so! I'll appreciate it.

Thanks for all the help BTW! 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...