Topic-icon Disable new user registration via JFBConnect 4.2 (in Joomla 2.5)

Active Subscriptions:

None
Hello,

I'd like to disable JFBConnect being able to register new users on my Joomla 2.5 website. I've already disabled the normal Joomla user self-registration method - but would now like to stop JFBConnect from creating users who don't exist. So effectively I only want existing site members (that I've created) to be able to connect their Joomla site accounts to Facebook (JFBConnect) should they wish to do so to make logging in easier and to also pull down their FB Avatar.

I have found this post on the Joomla 1.5 section, where I think you indicate it's possible:?
www.sourcecoast.com/forums/jfbconnect/jf...ew-user-registration

Can you confirm if it is possible and if so how I go about setting this up please?

Thanks in advance.

Parr
The topic has been locked.
Support Specialist
Parr,
We don't have a setting to disable new user registrations through JFBConnect, but it's pretty easy to add 2 lines of code to do what you're looking for.

First, in the JFBConnect Configuration, change the Registration Flow to "Normal Registration". Then, edit the /components/com_jfbconnect/controller.php file. Around line 72, you'll see the following block of code:
if ($configModel->getSetting('create_new_users') && $jUserId == null)
            { # User not in system, create new users setting enabled. Redirect to the login/register form

                SCSocialUtilities::setJFBCNewMappingEnabled();
                $redirect=''; $menuItemId=0;
                SCSocialUtilities::getCurrentReturnParameter($redirect, $menuItemId, LOGIN_TASK_JFBCONNECT);
                $app->redirect(JRoute::_('index.php?option=com_jfbconnect&view=loginregister&return='.base64_encode($redirect), false));
            }
Change that to:
if ($configModel->getSetting('create_new_users') && $jUserId == null)
            { # User not in system, create new users setting enabled. Redirect to the login/register form
                $app->enqueueMessage('New User Registration not allowed');
                $app->redirect(JRoute::_('index.php'));
            }
You can update both of those lines however you want to change the message or the location the user is redirected to after they are denied registration.

Hope that helps, but if you have any questions, just let us know!

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

None
Thanks Alex. I've given it a go and the above seems to work ok.

The main drawback though is that it means when they connect Facebook to their existing Joomla user account it doesn't pull down their FB Avatar or any profile information from Facebook. I have got "Always Import Profile Data:" set to 'No' because I wanted them to have the option to change their Avatar for our website if they wanted it to be different to Facebook - which if I put this setting to 'Yes' it'll be overwritten everytime they login with JFBConnect?

So is there anyway it can pull down their Avatar/FB profile information on the first time they 'connect' FB to their user account, but not pull it down on subsequent logins?

Thanks again for your help - really good support.
The topic has been locked.
Support Specialist
Parr,
Glad to hear that helped you with your original request.

For connecting accounts, you're correct, we don't re-import the information at that point. Honestly, I think we don't even do it then if the "Always Import" option is selected.. which is a bug in our tracker to be fixed.

There are 2 options on how to do what you're looking for:
1) What you asked for.. import the profile information when the user clicks the first links their Facebook account to their existing Joomla account.
2) Not what you asked for... a link that you can add to your site that, when clicked, will let the user import their profile information as you've configured it to be fetched. The user won't have control of what gets updated, it will use whatever settings are in the Profile plugin for avatar and field import, but gives the user the ability to do it at will.

The #2 option is something that will be in the next big release of Joomla as it's just a nice feature to have. It also isn't too tough to add with some code to the current version. The #1 bug will be fixed eventually as well, but it's not a critical priority.

Let us know what works for you, and we can get you some code modifications you can make to implement either (or both) if you want!

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

None
Hi Alex,

To implement both of those options would be fantastic - thanks for letting me know about the second one.

Option 1 is my priority; just to make sure they've got an Avatar set, some basic details on their profile filled out and it also makes the linking to FB worthwhile for the user (in addition to making it easier for them to login). But I'd also (now) like the second option as well just in case they do update their FB details at a later date and then want the option to import those changes into my site. I don't want it to import their details automatically everytime they log in just in case they do purposely give themselves a different Avatar/profile information for my Joomla site - so the manual link woud be perfect for this.

Looking forward to getting this setup - thanks again for your help.

Cheers,

Parr
The topic has been locked.
Active Subscriptions:

None
Hi Alex,

Is there any chance of getting this information by end of play on Monday? My site is not live yet - but I was hoping to implement the two options you've described above before I make it live. But if it'll take a while longer, then I'll probably make it live this weekend.

Thanks again for all your help.

Regards,

Parr
The topic has been locked.
Support Specialist
Parr,
I'm hoping to get you some answers later today. It may not be until tomorrow or Monday though if we run into issues coming up with the right code. Even then, the code will provide will be minimally tested (not like a full release), so we're going to make the recommendation that you test on a development site thoroughly first before implementing it.

Feel free to decide how to launch with that info, but I think we'll get you going 'soon' here :)

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

None
Thanks Alex, I ran into a few other separate problems with my site so I think I'll wait. I'll wait to hear from you.

Cheers.
The topic has been locked.
Support Specialist
Parr,
Sorry for the delay. We have an answer for you though! Below are the 2 code changes you'll need to make for both of the options above:

Import profile when user logs in (connecting accounts) on the Login / Register page of JFBConnect
Edit the /components/com_jfbconnect/controllers/loginregister.php file. Look for the loginMap() function. It will be in the middle of the file. In that block of code, you'll see a section like:
else //Logged in successfully
        {
Add the following lines directly after that:
            $jUser = JFactory::getUser();
            $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
            $fbUserId = $jfbcLibrary->getMappedFbUserId();
            $args = array($jUser->get('id'), $fbUserId);

            JPluginHelper::importPlugin('jfbcprofiles');
            $app->triggerEvent('scProfilesImportProfile', $args);
            $app->enqueueMessage('Profile Imported!');
Leave the rest of the code in that block the same. With that, a user's profile will be imported when the connect their accounts.

Provide link for users to pull their info from Facebook
Edit the /components/com_jfbconnect/controller.php file. At the very bottom right *before* the last }, add the following block of code:
function updateProfile()
    {
        $jUser = JFactory::getUser();
        $jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
        $fbUserId = $jfbcLibrary->getMappedFbUserId();
        $args = array($jUser->get('id'), $fbUserId);

        $app = JFactory::getApplication();
        JPluginHelper::importPlugin('jfbcprofiles');
        $app->triggerEvent('scProfilesImportProfile', $args);
        $app->enqueueMessage('Profile Imported!');
        $app->redirect('index.php');
    }
Then, create the following link on the front-end of your site wherever you want the user to be able to manually pull in their information:
<a href="index.php?option=com_jfbconnect&task=updateProfile">Pull from Facebook</a>
It's best to check if the user is already logged into Facebook, which you can do with the following PHP code:
<?php
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
if ($jfbcLibrary->getMappedFbUserId())
   echo '<a href="index.php?option=com_jfbconnect&task=updateProfile">Pull from Facebook</a>';
?>

Definitely test (a lot!) and let us know how it goes. We'll be implementing this in some fashion in the next release as well and would love to have your feedback!

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

None
Hi Alex,

Thanks again for your continued help with this. Unfortunately I didn't have any luck with either parts (it pulling down the avatar/profile upon the first login/FB connection or the button to pull the information on demand). I've double checked a few times that I've entered the code correctly - but I'm not sure if I'm missing something...
In terms of what happens, the connect to Facebook option for the users still works, but it doesn't pull down the avatar or any profile information - it doesn't seem to generate any obvious errors etc on screen. With the link (to pull the information on demand), it gives me the status message that it's been successful but none of the information or FB avatar appear.

Where do we go next? Would you be able to have a look on my website and if so would admin & ftp access help?

Cheers Alex.

Regards,

Parr
The topic has been locked.