Adding custom properties to Social Connected users profile

Social Connected module gives the ability for website users to register through their social networks, like Facebook, Twitter, Linkedin and Google+, the module does a good job of mapping users data from these networks and add them to user profile in sitecore.

Recently, we needed to add our own custom properties into users registered through Social networks, i was able to do this by using [social:connector:user:created] event.

The following code grabs the user object from event parameters, and update the profile with our own custom property:

namespace Sitecore.SharedSource.Events.Social
{
    public class UserCreated
    {
        protected void UpdateUserProfile(object sender,  EventArgs args)
        {
            var user = Sitecore.Events.Event.ExtractParameter(args, 0) as Sitecore.Security.Accounts.User;
            if(user!=null)
            {
                user.Profile.SetCustomProperty("CustomPropertyName", "CustomPropertyValue");
                
                user.Profile.Save();

            }
        }
    }
}

You need to add the following configurations in your include folder

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events>
      <event name="social:connector:user:created">
        <handler type="Sitecore.SharedSource.Events.Social.UserCreated, Sitecore.SharedSource" method="UpdateUserProfile"/>
      </event>
    </events>
  </sitecore>
</configuration>

Hope this helps!

Comments

  1. The free STL information perfect for|are good for} classroom printing and come with instructor education materials. Please thoughts that|remember that|understand that} the curriculum is just out there after you register. Moreover, manufacturing may occur in response to precise demand, not anticipated or forecast demand. In the final several of} years 3D printing has been Hanes Men's Boxers intensively used by within the cultural heritage field for preservation, restoration and dissemination functions. Many Europeans and North American Museums have bought 3D printers and actively recreate missing pieces of their relics and archaeological monuments similar to Tiwanaku in Bolivia. The Metropolitan Museum of Art and the British Museum have started utilizing their 3D printers to create museum souvenirs which might be} out there within the museum outlets.

    ReplyDelete

Post a Comment

Popular posts from this blog

Building Sitecore Content Search Queryable using Rules engine

Attaching a file on WFFM Send email action

Caching Rendering HTML when conditional rules are applied