Topic-icon [SOLVED] [dev] User Mapping availability inside onRegister event

Active Subscriptions:

None
Hi,

this is a follow up of this other topic I opened: www.sourcecoast.com/forums/jfbconnect/jf...er-login-is-finished

To recap: I need to send user info and the user mapping info to an external server, so I've made a SocialProfiles plugin to do it.

I've noticed that the user mapping info isn't available when the onRegister event is triggered. Even worst, if JFBConnect has the "Enable Automatic Registration" and "Skip Joomla User Activation" settings enabled, it won't trigger the onLogin event after the user logs in the first time, i.e. only onRegister is triggered. Can you fix it?

Notice I'd rather have the user mapping info available when the onRegister event happens than waiting for the "onLogin" event to be triggered, since those JFBConnect settings above won't be always enabled.

I've attached a demo plugin, so you can see yourselves what I'm telling you (just install it and enable it). It will dump in a log file (joomla_site/logs/jfbconnecttest.log.php) the user mapping info it sees when the onLogin and the onRegister events happen. If you have an alternative to what I'm doing, it will be welcome.

Tested with JFBConnect v1.7.2.

Thanks.

jfbconnecttest.zip
The topic has been locked.
Support Specialist
Check out the root class in the /libraries/sourcecoast/plugins/socialprofile.php file. The onRegister function *can* get the profile data, but it has to do it a little more special. It does it automatically and then calls the createUser function, which you may want to use instead for what you're trying to do. Otherwise, override the onRegister function and pull the user's profile manually as shown in that function.

On registration, JFBConnect can and definitely does import a user's profile. That's necessary when things like admin activation are disabled so that the profile is filled out before a an admin goes to approve it. In that case, the onLogin event shouldn't even be called.

I hope that helps explain more, but if not, let me know!

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

None

alzander wrote: Check out the root class in the /libraries/sourcecoast/plugins/socialprofile.php file. The onRegister function *can* get the profile data, but it has to do it a little more special. It does it automatically and then calls the createUser function, which you may want to use instead for what you're trying to do. Otherwise, override the onRegister function and pull the user's profile manually as shown in that function.

On registration, JFBConnect can and definitely does import a user's profile. That's necessary when things like admin activation are disabled so that the profile is filled out before a an admin goes to approve it. In that case, the onLogin event shouldn't even be called.

I hope that helps explain more, but if not, let me know!

Thanks,
Alex


Thanks, Alex. Instead of overriding onRegister, I'm overriding createUser($profileData) instead. Although it's called, it seems that $profileData is empty. I've followed the customDb example, put a call to importSocialProfile inside createUser and overrided the saveProfileField method, yet I still don't get anything.

Let's say that I only want from the user mapping the user id from the social provider and its user access token. I don't care about any other fields from the social profile. I've noticed that the userId from social provider is available in the socialId variable inside SocialProfilePlugin. I only need the access token but I don't know how to get it right now.

I've attached the example I made with my these changes.

jfbconnecttest2.zip
The topic has been locked.
Active Subscriptions:

None
Any news, Alex? I won't be able to successfully do what I wanted without that value.

After looking at JFBConnect code, I think it needs to be patched starting from /components/com_jfbconnect/models/loginregister.php, in its onAfterRegister method, adding $provider->client->getToken() to the $args variable. Then changing the signature of socialProfilesOnRegister to add the 4th parameter and so on...

But I didn't look deeper, so I'm not sure if all your social providers have a "client" with the getToken() method.

Thanks.
The topic has been locked.
Support Specialist
Very sorry for the delay. I missed your posts above. Hopefully we can get you going quickly.

For profile data not coming in, that sounds very strange. I'm unsure what's happening there but can help investigate further if you need. It doesn't sound like that's your priority now.

As for getting the token for the user, you can use the following call:
JFBCFactory::usermap()->getUserAccessToken($jUserId, 'facebook');
Just replace 'facebook' with whatever network you need the token from and $jUserId with the user's Joomla id, which you can get from the plugin easily.

I hope that helps, but please let me know if you need anything else.

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

None
Thanks, Alex.

That doesn't work when the user registers the first time (onRegister), but it works in the onLogin event. It's in use in the first example code I uploaded in this thread, yet it's empty when onRegister happens.

I think it's because you store the usermap after calling onRegister, so the usermap is not available when the onRegister event happens.
The topic has been locked.
Support Specialist
Whew.. you're right. I had to look through the code. It's been a while. For onRegister, the token isn't necessarily stored in the database yet. Your patch above shouldn't be necessary though since we create singletons of each social network provider. Because of that, you should be able to do the following to get the token currently registered for the session/user anywhere you want:
JFBCFactory::provider('facebook')->client->getToken()

Let me know how that goes, but if you still have issues, we'll gladly help.

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

None
Thanks, Alex! That did the job!
The topic has been locked.