2.0b1 user profile extra fields?

This post has 71 Replies | 14 Followers

Not Ranked
Posts 25
Points 350
Andreas Birgerson Posted: Mon, Jan 9 2006 7:49 PM

Is there a simple way to add custom fields to the user profile in 2.0b1 or do we have to do it the old way by recompiling once we have the source?

It would seem a simple feat to me to just add another field to the userprofile fields (which are stored in a blob) without actually declaring the fields in the profile object

ie. userprofile.setcustomfield("BirthTown","Seattle")

instead of userprofile.birthtown="Seattle"

in the case of a get, a get of an unknown field would just return an empty string?

 

Maybe this is already in there, if so, could someone please show me the way to go, for i would very much like to enable this asap since i will have ~300 new users registering within the next two weeks (start of new semester).

 

Thanks and Telligent you do an excellent job!!

 

 

Andreas

www.exchangestudent.se

 

  • | Post Points: 20
Top 25 Contributor
Posts 1,879
Points 37,940
CS Developers
Jose Lema replied on Mon, Jan 9 2006 11:56 PM

While CS has always allowed the extension of the user profile via ExtendedAttributes, there is a new feature in CS 2.0 that allows something similar to what you're talking about, though the functionality is not completely as you describe. We are definitely thinking about ways to implement a more customizable user in vNext.

For now, if in your community, you want to capture additional profile information, we enable this scenario by allowing you to declaratively specify the fields to be used during 1) registration and 2) profile editing. You would be responsible for changing the skins to include those additional controls, which must match the field names. When the reg form is saved and when the edit profile forms (self-edit and admin-edit) are bound and saved, a method looks up the extended user data and attempts to find controls with matching names. If found, it'll bind the value of the profile information. Upon saving, it'll run through the list again and persist the new values.

So for example, if you wanted to capture field "foo" and "bar" for each user you would do the following:

1.Open communityserver.config and add the following anywhere inside the <CommunityServer> tags:

<ExtendedUserData>
    <add name = "foo" />
    <add name = "bar" />
 </ExtendedUserData>

2. Open Skin-CreateUser.ascx and Skin-EditUser.ascx in Web\Themes\default\Skins\ and UserEdit.aspx in Web\ControlPanel\Membership and place your controls in the form:

...

Enter foo: <asp:textbox id="foo" runat="server" /><br />
<asp:CheckBox id="bar" runat="server" Text="I'm interested in bar" />

...

That's it! Now whenever a user registers, s/he would see the additional controls and they'd be databound to extended attributes on the User object. At this time, the code can handle binding to TextBox, CheckBox, ListControl, or any subclass of those controls.

Similar to the existing functionality, you can always reference extended attributes from skins by binding to User.GetExtendedAttribute("foo") or User.GetExtendedAttribute("bar"). Again, while this is not the final story for extending the user profile, it's a first step that should fill the gap before we support a fully customizable User.

To see this type of behavior in action, check out www.hive.net.

Thanks.

One is glad to be of service...

Jose Lema

  • | Post Points: 65
Not Ranked
Posts 25
Points 350

I did the <ExtendedUserData> thing in communityserver.config and modified Skin-createuser.ascx in /themes/default/skins to include some of my new fields and some from the regular user profile and it looks okay but the fields don't get saved, not even the regular ones that i added like msnIM

Do i need to modify /user/CreateUser.aspx in anyway, and if so, what do i need to do? Must Web.config<Profiles><Properties> be modified also?

 

Cheers,

andreas birgerson

www.exchangestudent.se

 

sample of my Skin-CreateUser.ascx:

<h2 class="CommonTitle">
 Finding you
</h2>
<table cellpadding="0" cellspacing="0" border="0" bgcolor="77ff77">
<tr>
 <td>
  <div class="CommonFormFieldName">MSN address (if any)</div>
  <div class="CommonFormField">
  <asp:textbox id="msnIM"  MaxLength="64" runat="server" columns="40"/>
  </div>
 </td>
 <td>
  <div class="CommonFormFieldName">ICQ no. (if any)</div>
  <div class="CommonFormField">
  <asp:textbox id="icqIM"  MaxLength="64" runat="server" columns="40"/>
  </div>
 </td>
</tr>
<tr>
 <td>
  <div class="CommonFormFieldName">Mobile phone no. (+49172xxxxx)</div>
  <div class="CommonFormField">
  <asp:textbox id="MobilePhoneNo"  MaxLength="64" runat="server" columns="40"/>
  </div>
 </td>
 <td>
  <div class="CommonFormFieldName">Home Country</div>
  <div class="CommonFormField">
  <asp:textbox id="Country"  MaxLength="64" runat="server" columns="40"/>
  </div>
 </td>
</tr>
</table>
  • | Post Points: 20
Top 25 Contributor
Posts 1,879
Points 37,940
CS Developers
Jose Lema replied on Tue, Jan 10 2006 10:54 AM

A couple of notes:

  • This will only work for fields listed in ExtendedUserData.
  • Names must match identically (casing counts)

If you're already doing this correctly, could you post/PM/email me your communityserver.config file? Also, how are you verifying that the data was indeed saved or not?

 

One is glad to be of service...

Jose Lema

  • | Post Points: 20
Not Ranked
Posts 25
Points 350

OK i checked in sqlserver now and the values do indeed get saved, except i was confused by the fields that belong to the standad profile that i added to my createuser-skin, they apparently don't get saved.

You already have some ascx source for this above. I am trying to update the msnIM icqIM, and CommonName and Gender fields, the gender like this:

 

<tr>
 <td>
  <div class="CommonFormFieldName">Real name (first & last please)</div>
  <div class="CommonFormField">
  <asp:textbox id="CommonName"  MaxLength="64" runat="server" columns="40"/>
  </div>
 </td>
 <td>  
 <div class="CommonFormFieldName">
     <CS:ResourceControl runat="server" ResourceName="EditProfile_AboutGender" id="Resourcecontrol11"/></div>
 <div class="CommonFormField">
  <CS:GenderRadioButtonList Cssclass="txt1" id="Gender" RepeatColumns="3" runat="server" /></div>
 </td></tr>

and this does not seem to be saved (what i typed does not show up in the normal edituser)

 

  • | Post Points: 20
Top 25 Contributor
Posts 1,879
Points 37,940
CS Developers
Jose Lema replied on Tue, Jan 10 2006 12:51 PM

Unfortunately, like I said before, this only works for fields that are listed in ExtendedUserData. Any data stored in ExtendedAttributes can be accessed using this feature. Since Gender, CommonName, ... are part of the profile, and not extended attributes, they can't participate in this feature. Sad [:(]

One is glad to be of service...

Jose Lema

  • | Post Points: 20
Not Ranked
Posts 25
Points 350

Oh okay now I get it! Thank you for your patience and your quick replies! You have really made my day (it is not so easy to force users to enter supplemental data once they have registered)

I expect I will store these things in ExtendedUserData and migrate them with an sp that i run with sqlserveragent until such a time that i can make a proper implementation

Cheers,

 

Andreas

  • | Post Points: 20
Top 25 Contributor
Posts 1,879
Points 37,940
CS Developers
Jose Lema replied on Tue, Jan 10 2006 1:44 PM

Glad to hear it's making sense. Smile [:)]

As for the sproc to copy data out of ExtendedAttributes, you may want to peek at the code sample at http://code.communityserver.org. Expand CS Tree > Sample Code > SQL > FetchExtendedAttribute.

Hope this helps.

One is glad to be of service...

Jose Lema

  • | Post Points: 20
Not Ranked
Posts 25
Points 350

Thank you. The procedure name has a funny spelling mistake in it.

 

So how would i go about publishing the information in these extendedattributes on for example Skin-Userprofile.ascx?

I suppose I need a <script language="C#" runat="server"/> but i don't know what to put in it....

my field representation on this template would look like this:

<tr>
     <td class="CommonFormFieldName">
      Home-University
     </td>
     <td class="CommonFormField">
      <asp:Literal id="HomeUniversity" runat="server" />
     </td>
 </tr>

i suppose i could change the <asp:literal> to read <HomeUniversity/> and end up with something like <script> HomeUniversity.InnerHtml=CSContext.User.GetExtendedAttribute("HomeUniversity") </script> but some real world sample code would be much appreciated since i don't know too much about how this should be coded.

 

  • | Post Points: 20
Top 25 Contributor
Posts 1,879
Points 37,940
CS Developers
Jose Lema replied on Wed, Jan 18 2006 6:22 PM

I would change the <asp:literal> control to just use the old asp syntax:

<%= CSContext.Current.User.GetExtendedAttribute("HomeUniversity") %>

Hope this helps.

One is glad to be of service...

Jose Lema

  • | Post Points: 20
Not Ranked
Posts 25
Points 350

As always a no-delay answer from you. How do you do it ;-)

Well it accepts the syntax but there is nothing happening for me....

the casing is just right and the fields do exist in the db

 

  • | Post Points: 20
Top 25 Contributor
Posts 1,879
Points 37,940
CS Developers
Jose Lema replied on Wed, Jan 18 2006 7:16 PM

Ahhh...yes. And again, you are right. Smile [:)]

The CSContext.Current.User would hold the logged on user. If you want to get data from an alternate user, add the following to your skin.

User GetUserToView()
{
   User user = null;
   CSContext csContext = CSContext.Current;
   int userid = csContext.UserID;

   // Check for valid UserID
   if (userid <= 0)
   {
      // Check for valid username
      if (Context.Request.QueryString["UserName"] == string.Empty)
         throw new CSException(CSExceptionType.UserNotFound);
      else // username parameter exists
         user = Users.GetUser(0, Context.Request.QueryString["UserName"], false, true);
   }
   else // userID parameter exists
   {
      user = Users.GetUser(csContext.UserID, false, true);
   }

   return user;
}

Then you can reference data with <%= GetUserToView().GetExtendedAttribute("...") %>

Yup...that should do it. Smile [:)]

One is glad to be of service...

Jose Lema

  • | Post Points: 50
Not Ranked
Posts 25
Points 350

cool it is working

 

  • | Post Points: 20
Top 25 Contributor
Posts 1,879
Points 37,940
CS Developers
Jose Lema replied on Wed, Jan 18 2006 7:25 PM
Excellent!

One is glad to be of service...

Jose Lema

  • | Post Points: 5
Not Ranked
Posts 4
Points 65
Allow me to jump in. Is it also possible to add image field with upload feature? My community is dating oriented and I would like profile to contain personal stats and gallery with a main image. What would be the best way to accomplish this?

Thanks in advance for your time.
  • | Post Points: 20
Page 1 of 5 (72 items) 1 2 3 4 5 Next > | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com