Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: wixi - marraskuu 26, 2013, 01:13:49 IP

Otsikko: Redirecting to Mod Function on Login
Kirjoitti: wixi - marraskuu 26, 2013, 01:13:49 IP
A mod I am developing requires the user to set some options before they can use it. As such, once the mod is installed, I'd like all the users to be redirected to the 'OPTIONS' page of my mod on login (if they haven't already set the options). Can someone guide me on how to to do this?

On a side not, can you also point me to more documentation on $context. Thanks.
Otsikko: Re: Redirecting to Mod Function on Login
Kirjoitti: margarett - marraskuu 26, 2013, 01:26:46 IP
For $context, it is filled dynamically in each action, so the variable has different values in different places.
Bes bet is to use

echo '<pre>';
print_r($context);
echo '</pre>';

Somewhere in index.template.php.

For redirect, you can use redirectexit()
http://support.simplemachines.org/function_db/index.php?action=view_function;id=224
Otsikko: Re: Redirecting to Mod Function on Login
Kirjoitti: wixi - marraskuu 26, 2013, 02:42:54 IP
Redirect -
So I will need to modify the login function, check if mod-options have been set, and accordingly redirectexit to appropriate action, right?

$context -
Can we add our own data to $context; like, $context["firstrun"] = 0 ?
Otsikko: Re: Redirecting to Mod Function on Login
Kirjoitti: margarett - marraskuu 26, 2013, 02:48:29 IP
Redirect - yes. Not sure how what you really want to do, but something in Register.php --> Register2() function. After the registration is complete, there is already a redirect:
redirectexit('action=login2;sa=check;member=' . $memberID, $context['server']['needs_login_fix']);
Where you are automatically logged in after register.
Maybe what you really need is to change the login2() function to check where you come from and then... do things :P

As for $context, yes, you can.
Otsikko: Re: Redirecting to Mod Function on Login
Kirjoitti: wixi - marraskuu 26, 2013, 03:22:58 IP
To clarify -
After a mod is installed by the administrator, I need all the EXISTING users to set some options before they can start using it. So I want to redirect them on their next login to an "introduction / option page" so that they are informed about the mod and can then set its options if they want to use it. I think the login function should do ... will look into it and get back.

Thanks for your help.
Otsikko: Re: Redirecting to Mod Function on Login
Kirjoitti: Arantor - marraskuu 26, 2013, 03:25:16 IP
What options need configuring, exactly? The fact you have users that might not want to be involved does suggest you don't *need* them to configure it immediately.
Otsikko: Re: Redirecting to Mod Function on Login
Kirjoitti: wixi - marraskuu 26, 2013, 05:43:24 IP
Sure, in some cases a user may not need to configure a mod to use it. But some cases where you are integrating SMF with an external web app does require the immediate attention of the user (at-least in the form of a notification).

Otsikko: Re: Redirecting to Mod Function on Login
Kirjoitti: Arantor - marraskuu 26, 2013, 05:45:54 IP
As with everything this goes so much easier when context is given as opposed to being very generic.