Topic-icon [SOLVED] [development] Event after user login is finished

Active Subscriptions:

None
Hi,

I want to program a plugin that sends the user info to another place once that JFBConnect finishes the user login. I've read the code and it seems the last moment where JFBConnnect stores relevant user info is after the checkNewMapping() function call made in line 166 at frontend/controllers/login.php. So unless I'm wrong, ideally an event triggered after those lines would be nice to have for my use case.

Am I wrong? Should I forget about that checkNewMapping() call and use a plugin which is triggered by the "socialProfilesOnLogin" event (which is triggered before the checkNewMapping call and only if $provider->initialRegistration is false)?. Can you recommend me a course of action? Thanks.
The topic has been locked.
Support Specialist
I would definitely recommend using our existing plugin system to do what you're looking for, unless I'm missing something. If you just want to take the user's social network profile info and store it somewhere else, that's what our SocialProfile plugins are meant for. If you just want profile information stored in the database somewhere, we already have the Custom DB plugin which lets you set what columns of data should be set from the user's profile in an existing table.

Above and beyond all that, the plugin system is not connected to JFBConnect so, if you create a plugin, your code should still work after an update and you won't need to re-do the code when the update is applied.

I hope that helps explain, but if you need anything else, just let us know. More details about what you're trying to do wouldn't hurt either if you need more assistance.

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

None

alzander wrote: I would definitely recommend using our existing plugin system to do what you're looking for, unless I'm missing something. If you just want to take the user's social network profile info and store it somewhere else, that's what our SocialProfile plugins are meant for. If you just want profile information stored in the database somewhere, we already have the Custom DB plugin which lets you set what columns of data should be set from the user's profile in an existing table.

Above and beyond all that, the plugin system is not connected to JFBConnect so, if you create a plugin, your code should still work after an update and you won't need to re-do the code when the update is applied.

I hope that helps explain, but if you need anything else, just let us know. More details about what you're trying to do wouldn't hurt either if you need more assistance.

Thanks,
Alex


My use case implies that I'll send the user info via an API call to a custom server we have which has special authentication needs, so no existing plugin tackles our use case.

Without JFBConnect I'll just make a Joomla plugin with the onUserAfterLogin method:
docs.joomla.org/Plugin/Events/User#onUserAfterLogin

Looking at your code, you call $app->login in line 139 of frontend\controllers\login.php which will trigger onUserAfterLogin plugins before you store the social provider id, which means that info will be unavailable to me. So that's why I'm asking what I'm asking.

Maybe I'm wrong and at some other place of the code you trigger an event I can use.

Thanks.
The topic has been locked.
Support Specialist
Thanks for describing more. I'd recommend creating your own SocialProfile plugin. There's a function called onLogin that you can override and do whatever you want in there.

You can see the parent class in /libraries/sourcecoast/plugins/socialprofile. In that function, you can get access to the Joomla user, social network ID and fetch data from the user's profile.

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

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

None

alzander wrote: Thanks for describing more. I'd recommend creating your own SocialProfile plugin. There's a function called onLogin that you can override and do whatever you want in there.

You can see the parent class in /libraries/sourcecoast/plugins/socialprofile. In that function, you can get access to the Joomla user, social network ID and fetch data from the user's profile.

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

Thanks,
Alex


Thanks, Alex.

After looking a bit more about it, I think I'll have to make a plugin with a mix of socialProfilesOnRegister and socialProfilesOnLogin (onLogin in your file is called by socialProfilesOnLogin) events to solve my use case. I'm just wondering about how important is that checkNewMapping() call which happens after these events are triggered, but I'll give it a try anyway.
The topic has been locked.
Support Specialist
By the time onLogin is called, the user has been created and mapped in JFBConnect and Joomla. You'll want to use the onLogin function to make sure everything is setup properly. It's called pretty quickly in the socialProfilesOnLogin function.

The checkNewMapping is for a special case and not something that needs to be done before the socialProfilesOnLogin call. Everything will be setup by then.

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

None

alzander wrote: By the time onLogin is called, the user has been created and mapped in JFBConnect and Joomla. You'll want to use the onLogin function to make sure everything is setup properly. It's called pretty quickly in the socialProfilesOnLogin function.

The checkNewMapping is for a special case and not something that needs to be done before the socialProfilesOnLogin call. Everything will be setup by then.

Thanks,
Alex



Thanks, Alex.

I considered my issue solved for the time being. Extending the SocialProfilePlugin class and overriding onLogin and onRegister methods should do the job. OnRegister is needed too since I saw that the first time a user registers in the system and logins automatically, onLogin is not called but onRegister is.
The topic has been locked.
Support Specialist
Correct, you'd need to use onRegister and onLogin. They each have their purpose for first time registration and returning logins, which helps break out different behavior depending on what you want to do.

Glad you got things going. Should you need anything else, please let us know.

Finally, if you haven't already, please consider leaving a rating and review for JFBConnect, or our support, on the Joomla Extension Directory. It's certainly not required, but very appreciated:
extensions.joomla.org/extensions/extensi...l-display/jfbconnect

Thanks,
Alex
The topic has been locked.