Topic-icon Google authentication and profile import

1 year 3 months ago - 1 year 2 months ago #68453 by rcaragao
Hello! I added sign-in with Google on my site, which is working great. The only thing I'm trying to figure out is how to fix the first name that has been filling up with the first part of the email before the @.

For example, if Joe Doe signs in with his email This email address is being protected from spambots. You need JavaScript enabled to view it., then the name of the user will be 2023jd Doe.

Any clue on how to solve this?

Thanks.
Last edit: 1 year 2 months ago by mel.
The topic has been locked.
Support Specialist
1 year 2 months ago #68454 by alzander
That behavior is a workaround in the event that the first name isn't set for a user in Google. Joomla requires that the first name field is set, so we have to get something to put in that field.

With that said, that code was written quite a while back and may not be correct anymore. If you'd be up for making a minor code change, it may get you going how you'd like right now.

I believe we could set that first name field to be blank now and just have the user's last name. There may be other options as well as the Google integration was written some time ago and the first name functionality may not be so limited within Joomla.

If you're interested in trying some options out, the following code change is where you'd start:
In the /plugins/jfbconnect/provider_google/profile/google.php file. At line 76, you should see:
$profile->set('first_name', substr($profile->get('email'), 0, strpos($profile->get('email'), '@')));
You can change that to:
$profile->set('first_name', $data->given_name);
This will try to use whatever Google responded with for the user's first name.

Or:
$profile->set('first_name', " ");
This will set the first name to a blank.

Or:
$profile->set('first_name', "Unknown");
This will set the first to a specific value for all users.

We don't have a Google user that has this behavior.. ours apparently have first names.. but at the time we wrote that code, we had users who told us of similar issues, which is why we started using the first portion of the email instead to make things work.

I hope the above helps and is clear. If not, or you need assistance, just let us know!

Thanks,
Alex
The topic has been locked.
1 year 2 months ago #68455 by rcaragao
Thank you so much. The first option did the trick. 

Roberto
The topic has been locked.
1 year 2 months ago #68463 by rcaragao
Hi! I just found an issue. Now I see the following warning when accessing EasyDiscuss:

Warning
: Attempt to read property "given_name" on array in
.../plugins/jfbconnect/provider_google/profile/google.php
on line

Is there any workaround, or should I contact Stack Ideas?

Thank you,

Rob
The topic has been locked.
Support Specialist
1 year 2 months ago #68466 by alzander
Stack Ideas won't be able to help you with that.. it's a message from JFBConnect.

The PHP warning is saying that 'given_name' can't be read from whatever Google is returning about the user. When you said above that "The first option did the trick.", is the first name actually coming in correctly.. or is there just no first name for the user?

In the meantime... My guess why it's happening in EasyDiscuss is that their extension may be changing the setting for Error Reporting. Since it's a PHP warning (not an error), you should be able to hide that message by setting "Error Reporting" in the Joomla Global Configuration area to "None". That won't help importing the user's first name or anything... but should hide that message while we make sure the code change is actually working.

I hope that all helps,
Alex
The topic has been locked.