We are using the Sitecore Social Connected Module version 3.0 with Sitecore 7.5. Everything is working fine, in the sense that we log the user in and see the profile information stored into MongoDb. However, there is a requirement to also store the profile information into a separate system.
I've successfully been able to do this by tapping into the following social module events:
<event name="social:connector:user:loggedin">
</event>
<event name="social:connector:user:socialprofileattached">
</event>
In those events, I utilize the following code to read MongoDb and attempt to update the profile in my external system:
INetworkManager networkManager = ExecutingContext.Current.IoC.Get<INetworkManager>(new IParameter[0]);
ISocialProfileManager socialProfileManager = ExecutingContext.Current.IoC.Get<ISocialProfileManager>(new IParameter[0]);
string name = networkManager.GetNetwork(new IDIdentifier(ID.Parse(MembershipParameters.LinkedIn_NetworkId))).Name;
SocialProfile socialProfile = socialProfileManager.GetSocialProfile(Tracker.Current.Contact.ContactId.GetIdentifier(), name);
if (!socialProfile.IsEmpty && socialProfile.Fields.Any())
{
MembershipUtil.UpdateLinkedInPofile(socialProfile);
}
The problem is that this only works on second+ log in attempts. On the first attempt, the socialProfile.Fields
count is always 0. It seems that the code is getting called too early.
What I really need is a event or pipeline AFTER mongo has been updated so that I can retrieve it and update the external system.
Any other suggestions on how to accomplish this would obviously be welcome as well. Thanks.
Turns out I was overthinking the whole process. With the help of a decompiler, I realized that the login methods called accepts a
Callback URL
sublayout parameter. This is where the user gets redirected to after the login, so I overwrote the login button and added a return url to the Callback url. Then in the callback url, I called my database update method.The login code was decompiled from
Sitecore.Social.Client.Connector.Controls.LoginButtonBase.Login
An important note here. The second parameter in the following line indicates whether the profile should be updated asynchronously. If this is set to true, then the profile may still not be available to you when you hit the callback url. Setting that to false ensured that the
UserProfile
object in the MongoDB record was updated and available to me on the callback page. There is naturally a cost involved with that.Call this in the callback url landing page: