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
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" /> ...
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...
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
sample of my Skin-CreateUser.ascx:
A couple of notes:
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?
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:
and this does not seem to be saved (what i typed does not show up in the normal edituser)
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.
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
Glad to hear it's making sense.
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.
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.
I would change the <asp:literal> control to just use the old asp syntax:
<%= CSContext.Current.User.GetExtendedAttribute("HomeUniversity") %>
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
Ahhh...yes. And again, you are right.
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.
cool it is working
Copyright© 2008 Telligent Systems Inc. All rights reserved CommunityServer.com • Telligent.com