Topic-icon Login Redirect - Presale Question

Active Subscriptions:

None
10 years 7 months ago #35860 by joshuacenter
I am researching the features of the JFBConnect and have a couple of questions to ask prior to purchasing.

I would like to know if it is possible to redirect users to different webpage URLs based on the User Group they are assigned to?

Is there a way to handle a redirect if a person is assigned to multiple user groups?

If none of this is possible, what are your suggestions?

Thank in advance for your prompt reply.
Jack
The topic has been locked.
Support Specialist
10 years 7 months ago #35870 by alzander
Jack,
Thanks for your interest in JFBConnect. Hopefully the answers below help you, but if you have any others, just let me know.

Right now, no, there isn't a way to redirect based on user group. I'm honestly not sure if you mean a redirection after their initial registration and being assigned to the groups or if the return to the site, login with Facebook or Google, and redirect them then. In either case, we don't have specific support to redirect based on group. With that said, doing so would be very easy to do with a few lines of code as our redirection logic is handled in one place. Adding a few more checks for the user group and assigning where they should go, if anywhere, wouldn't be difficult.

Additionally, right now, JFBConnect has a plugin to assign the user's to a specific group during registration. It's not a part of the main download package yet because it hasn't been fully tested, but is available on request. With that plugin, the user can select what group they want to be a part of during the registration process, like a "Student" or a "Teacher".

I hope that helps answer your question, but again, let me know if you have more.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
10 years 7 months ago #35935 by joshuacenter
Thank you Alex. I have purchased the JFBConnect and would like access to the module you mentioned about assigning to different user groups.

In addition, if you could point me to the module or plug-in where I would need to make changes to the code for it to redirect to a page based on the user group the person belongs to would be much appreciated.

Thanks again for this great app!

Jack
The topic has been locked.
Support Specialist
10 years 7 months ago #35992 by alzander
Jack,
I haven't forgotten about you. I'm hoping to get you a good, detailed answer tomorrow. A little looking into things I need to do as well as testing the user group plugin that we have with the new v5.1.0 release. It should work, but I don't want to send you something that hasn't been tested at all with this one.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
10 years 7 months ago #36034 by joshuacenter
Alex,

Thanks for responding... I am waiting on pens and needles.
The topic has been locked.
Support Specialist
10 years 7 months ago #36091 by alzander
Jack,
Thanks for your patience. We just tested the Joomla Group plugin and made sure it works. To test it yourself, please grab it here

Some notes to be aware of:
* This has never been widely released or publicized, so you may run into an issue. Let us know.. We'd love more feedback on it and include it in the next release as a full-fledged JFBConnect plugin.
* The plugin has been tested on Joomla 2.5. It may work on 3.x, but haven't even tried on it. If you need 3.x, let us know, we'll gladly make any minor changes that may be necessary.
* The Profiles interface is pretty ugly, but functional
* To use, just go to the Profiles area and set what user groups a user is allowed to join.
* Right now, this requires "Normal Registration" mode so that a user can select their group. If you're looking to just assign Facebook or G+ user's automatically to a specific group, that would be done differently.. let me know, again, and I can help

Any feedback welcome. We initially created this for another user and got a little feedback, but it's rarely requested, so it just never hit the level of feedback or interest we wanted to include it.

Redirection based on group
To redirect user's differently based on group, you'd want to edit /components/com_jfbconnect/models/loginregister.php Around line 115, you'll see:
public function getLoginRedirect($provider = null)
    {
        if (($provider !== null && $provider->initialRegistration) && JFBCFactory::config()->getSetting('facebook_new_user_redirect') != '')
        {
            $itemId = JFBCFactory::config()->getSetting('facebook_new_user_redirect', '0');
            $redirect = SCSocialUtilities::getLinkFromMenuItem($itemId, false);
        }
        else if (JFBCFactory::config()->getSetting('facebook_login_redirect') != '')
        {
            $itemId = JFBCFactory::config()->getSetting('facebook_login_redirect', '0');
            $redirect = SCSocialUtilities::getLinkFromMenuItem($itemId, false);
        }
        else
        {
            // Get whatever has been saved in the com_jfbconnect.login.redirect state variable.
            $redirect = JFactory::getApplication()->getUserState('com_jfbconnect.login.return', 'index.php');
            //JFactory::getApplication()->setUserState('com_jfbconnect.login.return', null);
        }

        return $redirect;
    }
You'll want to update that last 'else' block like so:
else
{
    // Get whatever has been saved in the com_jfbconnect.login.redirect state variable.
    $redirect = JFactory::getApplication()->getUserState('com_jfbconnect.login.return', 'index.php');
    //JFactory::getApplication()->setUserState('com_jfbconnect.login.return', null);
 
   $user = JFactory::getUser();
   $groups = $user->get('groups');
   $authGroups = $user->getAuthorisedGroups();
   if (in_array(4, $authGroups))
       $redirect = 'index.php?test=blah';
   else if (in_array(5, $authGroups))
       $redirect = 'index.php?test=boo';
}
That last part with the if (in_array(..)) statements is where you can check for a certain user group ID and redirect based on that. If no group is matched, then the user will be left on the same page. Oh yeah, you'll need the redirection setting in JFBConnet to be set to "Same Page" for that to work.

Whew! I hope that gets you going, but please let me know any feedback or comments you have.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
10 years 7 months ago #36116 by joshuacenter
Alex,

You provide great support! I will be sure to give you great support kudos once this is all done.

Here is what I am trying to do....

I volunteer my time and programming background to a non-profit foundation that helps kids with neurological disorders.

We have several sections on our website that are only available to specific groups.

We have a section for Teachers
We have a section for Volunteers
We have a section for Office Support
We have a section for our Community Partnership for Schools.

What I want to be able to do is assign users to one of the groups (which I know how to do), and then when they sign in (via a login redirect) I want the system to display their home page based on the group they belong.

Hopefully I will be able to do this based on what you have provided to me thus far. If you see an issue with the way I want to do this please let me know.

I will wait to implement what you sent last until you have read this message and tell me that is what you just provided the ability to do.

Thanks,
Jack
The topic has been locked.
Support Specialist
10 years 7 months ago #36129 by alzander
Jack,
Glad you're enjoying our support so far. That's what we're here for!

What I want to be able to do is assign users to one of the groups (which I know how to do),

The plugin I linked to above is to let a user select their group on registration. If you're looking to assign them to a group after they register, or even create their account beforehand and assign them to a group, you wouldn't want to use that plugin as it wouldn't be necessary.

Once they are in the proper group, the code change above will perform the redirection if they are signing in with their Facebook or Google+ credentials. That redirection won't occur if they're logging in with standard Joomla credentials though. We don't affect the normal Joomla login process, we only implement our own for Social Network logins. Just wanted to point that out.

Let me know if the above helps explain more, or causes more confusion, and we'll gladly keep helping.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
10 years 7 months ago #36150 by joshuacenter

alzander wrote:

else
{
    // Get whatever has been saved in the com_jfbconnect.login.redirect state variable.
    $redirect = JFactory::getApplication()->getUserState('com_jfbconnect.login.return', 'index.php');
    //JFactory::getApplication()->setUserState('com_jfbconnect.login.return', null);
 
   $user = JFactory::getUser();
   $groups = $user->get('groups');
   $authGroups = $user->getAuthorisedGroups();
   if (in_array(4, $authGroups))
       $redirect = 'index.php?test=blah';
   else if (in_array(5, $authGroups))
       $redirect = 'index.php?test=boo';
}
That last part with the if (in_array(..)) statements is where you can check for a certain user group ID and redirect based on that. If no group is matched, then the user will be left on the same page. Oh yeah, you'll need the redirection setting in JFBConnet to be set to "Same Page" for that to work.

Whew! I hope that gets you going, but please let me know any feedback or comments you have.

Thanks,
Alex


Alex... As for the code
(in_array(4, $authGroups))

How do I determine what is in the In_array(4, $authGroups)) ?
The topic has been locked.
Support Specialist
10 years 7 months ago #36162 by alzander

How do I determine what is in the In_array(4, $authGroups)) ?

Woops, guess I could have explained that more... To determine the number to use there, in the admin area, simply go to Users -> Groups. Then, note the "ID" column in the right. The ID there is what you need to use. For example, if the Teachers row has an ID of 12, use 12 in the in_array(12, $authGroups)) line and the $redirect variable right after that line will be used for Teachers.

I hope that helps explain, but if you have any other questions, just let me know.

Thanks,
Alex
The topic has been locked.