Topic-icon Custom Facebook button to login if account exists

Active Subscriptions:

None
Hi,

Is it possible to have a Facebook button that logs in existing users, but doesn't direct non-existing users to register and create a user. Reason being, we want to have an exclusive sign in page for people that we ask to sign up with a Sign in with Facebook button... but we don't want anyone to be able to create an account.

If it is possible, is it then possible to have a different Facebook button on a registration page that will then register the users (if they have been invited to the hidden registration page).

Thanks,
Matt
The topic has been locked.
Support Specialist
11 years 7 months ago #47968 by alzander
There's no way to allow registration to work from page 'x' but not page 'y', even if 'y' is hidden in some way.

What you can do is setup Joomla to require admin activation of users, in which case the user can register with Facebook, but won't be able to login until you (the admin) have approved their account. You can definitely still create your own 'hidden' page for registration or login, but not a way to allow either from just that page.

Beyond that, there are ways to prevent user's from registering altogether using Facebook. With that, you can let the user login through Joomla and *link* their account to Facebook, but not register with Facebook. However, it doesn't sound like that's what you're looking for.

I hope that helps explain,
Alex
The topic has been locked.
Active Subscriptions:

None
11 years 7 months ago - 11 years 7 months ago #47989 by matgray87
Hi Alex, thanks for your quick reply.

Having it work on one page but differently another was just a bonus - it's not necessary.

That's not quite what I need, no...
I understand the login/activation method but that's not quite what I need either.
It's more one of two outcomes...

1). the user exists, and their FB email is recognised in the database - the user then signs in as normal
2). the user doesn't exist, and so their FB email isn't recognised in the database - the user gets a message (or redirected), saying no account detected etc (instead of registering).

Is this possible with a bit of change back-end? If so, is it relatively simple to implement? If not, how would I get about one of your team to help me develop that, and at what cost?

Thanks,
Matt
Last edit: 11 years 7 months ago by matgray87.
The topic has been locked.
Support Specialist
11 years 7 months ago #47999 by alzander
There's not a switch in the admin area to do what you're looking for, but the code change is pretty simple. This is with the latest 6.2 release, but should be very similar for whatever release you're using.
Edit the /components/com_jfbconnect/controllers/login.php file. Around line 74, you'll see:
$jUserEmailId = $userMapModel->getJoomlaUserIdFromEmail($providerEmail);
                    if (!empty($jUserEmailId))
                    {
                        // Found a user with the same email address
                        // do final check to make sure there isn't a FB account already mapped to it
                        $tempId = $userMapModel->getProviderUserId($jUserEmailId, strtolower($provider->name));
                        if (!$tempId)
                        {
                            SCSocialUtilities::clearJFBCNewMappingEnabled();
                            if ($userMapModel->map($jUserEmailId, $providerUserId, strtolower($provider->name), $provider->client->getToken()))
                            {
                                $app->enqueueMessage(JText::sprintf('COM_JFBCONNECT_MAP_USER_SUCCESS', $provider->name));
                                $jUserId = $jUserEmailId; // Update the temp jId so that we login below
                            }
                            else
                                $app->enqueueMessage(JText::sprintf('COM_JFBCONNECT_MAP_USER_FAIL', $provider->name));

                        }
                    }
After that, add the following block, which will execute if the user's account wasn't found in your system:
else
{
     $app->enqueueMessage("Oh no! You don't have an account here yet. Please contact some cool guy to get one first");
     $app->redirect('index.php');
}
That last line just redirects the user to whatever page you want.. which could be an info page on how to get a real account.

I hope that helps, but if you have any questions, just let us know. Also, I see your subscription expired. We hope to see you back as an active subscribers soon!

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

None
11 years 7 months ago - 11 years 7 months ago #48063 by matgray87
Thanks for your response again... That works perfectly... Now I've just got to work out how to implement it the best way and that's the hard bit...

Here's another idea... is it possible to only run the below code that you suggested based on whether the page is login or register, so maybe by the Itemid of the page?

I've tried this, but it doesn't seem to be working (my Sign In page has an Itemid of 487), and $itemid is being pulled correctly
else
												
														$itemid = JRequest::getVar('Itemid');
														$application = JFactory::getApplication();
														$menu = $application->getMenu();
														$item = $menu->getItem($itemid);
														$link = new JURI($item->link);
														$link->setVar('ItemId', $itemid);
														
														if ( $itemid == '487' ) {	

												
													{ 
														 $app->enqueueMessage("Oh no! You don't have an account here yet. Please contact some cool guy to get one first"); 
														 $app->redirect('index.php'); 
													}
													
														}


Yep, a bit annoying, as I subscribed 6 months ago, and only got round to start using the component a few weeks ago. Silly me - would have made my life a lot simpler ages ago! Will definitely be resubscribing for the new release that hopefully pulls in twitter info on account creation too!
Thanks again, and all the best.
Matt
Last edit: 11 years 7 months ago by matgray87.
The topic has been locked.
Support Specialist
11 years 7 months ago #48080 by alzander
Now, the code above wouldn't work because that would execute on the login/authentication URL that is loaded when the button is clicked, not the URL that the click actually came from.

I'm not sure of an easy way to do what you're looking for without a bit of code changes to pass the originating URL along and check various different scenarios of the login page.

Will definitely be resubscribing for the new release that hopefully pulls in twitter info on account creation too!

Not sure what you mean by this. Right now, JFBConnect can pull in various Twitter info and it should work. The only thing we can't get is email address because that's not something that Twitter allows access too.

Alex
The topic has been locked.
Active Subscriptions:

None
11 years 7 months ago #48092 by matgray87
I see, that makes sense, thanks - no wonder I couldn't get it to work.

I was talking about bringing twitter information into the initial registration for K2 as we had been talking about in another thread a few days ago...

RE the below:
"I'm not sure of an easy way to do what you're looking for without a bit of code changes to pass the originating URL along and check various different scenarios of the login page."

Would you be able to do this, and at what cost... I can grant you access to my installation/ftp etc.

Would you also be able to help forcing the Itemid after specific redirects?

Thanks,
Matt
The topic has been locked.
Support Specialist
11 years 7 months ago #48099 by alzander

I was talking about bringing twitter information into the initial registration for K2 as we had been talking about in another thread a few days ago...

Gotcha. I was confused because that's not a Twitter specific issue.. the data isn't populated for any extension.. but if you have Auto Registration enabled, then Twitter would be the only one you'd likely notice the problem on. This is in our tracker to-do list, but isn't planned until the 6.3 release, late this year.

Would you be able to do this, and at what cost... I can grant you access to my installation/ftp etc.

We don't perform paid customization services. We do, however, support all our users however we can. I'd have to investigate this a bit further to determine the best way to do it. We do save the page the user came from in a session variable, but I'm not sure if it'd always be accurate enough for the purposes you need. I think it would work though. If you want to tinker, you can try the following code:
$redirect = JFactory::getApplication()->getUserState('com_jfbconnect.login.return', 'index.php');
That should get the page the user came from, and you can try to parse it out to find whatever specific info you need.

If you want further help on that one to actually implement, unfortunately, I'd have to say you need an active subscription. If you don't (or can't) re-subscribe right now, no worries. If you have questions or post some code you come up with, or run into stumbles, we'll gladly help with pointers however we can.. but I can't devote big times to developing a code solution otherwise.

Would you also be able to help forcing the Itemid after specific redirects?

I'm not sure what you mean by this at all.

I hope that helps,
Alex
The topic has been locked.
Active Subscriptions:

None
11 years 7 months ago #48145 by matgray87
Hi Alex,

No problem - subscription renewed!

I'll have a play with $redirect = JFactory::getApplication()->getUserState('com_jfbconnect.login.return', 'index.php');, but I'm not quite sure how to parse any information

$redirect returns "index.php?option=com_users&view=profile" but it doesn't include any information about the ItemID..

If it works once, it should be accurate, as there's only ever 1 itemID where I want the button to allow registration (on the registration page Itemid=488). The only other place where the Facebook button exists is on the sign in page (Itemid=487), so that's where it needs to recognise the itemid and say sorry, you do not have an account...

What I meant by:

Would you also be able to help forcing the Itemid after specific redirects?

was that, when automatically registering an account, and sending a user-activation email, the user is redirected to the sign in page, but with the wrong itemID, so where can I add that in?

It'd be a nice feature if you could always force the itemID on any registration/password/login page from the back end so that you don't have to modify core code...

Thanks again,
Matt
The topic has been locked.
Support Specialist
11 years 7 months ago #48148 by alzander

$redirect returns "index.php?option=com_users&view=profile" but it doesn't include any information about the ItemID..

That URL isn't the page that you clicked the Facebook button from? That's strange. When you're testing, you can't just refresh the page, you'll need to actually test the full login/registration process. If the URL always looks like the one above, try from a few different pages to see if it ever changes, as that will help narrow down if my thinking is wrong about that value.

was that, when automatically registering an account, and sending a user-activation email, the user is redirected to the sign in page, but with the wrong itemID, so where can I add that in?

It'd be a nice feature if you could always force the itemID on any registration/password/login page from the back end so that you don't have to modify core code...

Ahh.. the redirect after a failed login is generated by Joomla itself *if* you've set the "new user redirection" link to a registered page. Basically, JFBC is redirecting to the page you set, but Joomla is denying them access and bringing them to the login page.

Set the new user redirection to a public page and JFBConnect will redirect the user there properly without forcing them to the login page.

I hope that helps explain, but if not, just let me know.

Thanks,
Alex
The topic has been locked.