In one of our project we have a user section in the site. The users can register to the site and create articles, comment on articles.The users have some additional properties (profile picture, date of birth, etc) in addition to the default ones.
We are implementing this using EPiServerProfile class.
Now the issue we are facing is how and where to display all the profiles in the CMS so that the WebAdmins can moderate them. Is there a built-in way to do this?
It should be that this oldie still works, might be that you'll still need some modifications though:
Working with user profiles can be quite tricky.
To get a user profile, you could do:
var epiProfile = EPiServerProfile.Get(username)
To get a profile of all users, you would have to get all users first, and then call EPiServerProfile.Get() inside the foreach loop.
Other way around is to call:
var profiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All);
foreach (ProfileInfo profile in profiles)
ProfileBase profileBase = // tricky part: convert ProfileIfo to ProbileBase
var epiProfile = EPiServerProfile.Wrap(profileBase);
The things get tricky if you have to make profiles searchable. For example, show me all users which are 30-40 years old.
If you don't have to use EPiServerProfile class, I think you'll have more success with creating some custom table and making your own implementation.
Hi Dejan, thanks for you input.
Now the question is where and how do I list all these profiles in the CMS. Do I need to create a pagetype for this and add a page based on that page type in the page tree. Then I will list all the profiles in that page.
I want webAdmins to browse through them.
Also does EPiServer Community module will be helpfull in the above scenerio?
On the link I've sent you, you have the solution that is integrated into admin -> search for users or groups. It's presented by user.
However, if you need an advanced search by profile values, then the best option is to create and admin tool. That's basically a page you can put anything to.
This is a quick and easy example: http://jondjones.com/epi-server-tutorial-how-to-create-a-custom-admin-plug-in-in-less-than-5-minutes/
I don't think installing EPiServer Community just for the sake of this functionality pays off. It's a big solution, with its own membership providers and lots of more functionality you basically don't need. IMO, it would be an overhead.
If you just want to see them in admin mode, then you can check the link Marija sent you.If you need to create your own solution using the code I posted, then you can create a plugin: http://www.frederikvig.com/2009/10/creating-an-episerver-plugin/This article is for EPiServer 5, but the logic is the same. Things haven't changed much since then :)
If you don't want to create additional tables in epi database, but don't want to use EPiServerProfile either, you can store profile information as EPiServer pages (one page per user profile).Profile information should be public anyway?
EPiServer pages give you the most flexibility.You can control who can view / edit / administer pages.You can use the API you're already familiar with (IContentLoader / IContentRepository).EPiServer pages are indexed by built-in EPi search, if you decide to use EPiFind, even better :) You don't have to hit the database and can do all kind of filtering.Just make sure you organize them nicely in epi. You don't want to end up with 1 000 pages under a single node :)
Thanks Marija and Dejan for your valuable inputs.
I think taking the EpiServer Page route for user profiles make sense.
So as soon as user registers I will register them using MemberShip class as below, and based on the ID I will create an EpiServer page for them.
Membership.CreateUser("username", "password", "email");
Is this what should be done?
After you created the user, you should create a profile page, and log-in the user automatically.
PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal(username);
I am able to creat the pages for the user, what do you suggests in terms of organizing them in a page tree.
How can I save them under container page type and not under start page.
That depends on the number of users.
You can have a container page under start page called Users, and then container pages A, B, C, D, etc. (first letter of the username), and user profile page below.
For example: Start/Users/J/John-Doe
Not long ago, I blogged about something very similar: http://dcaric.com/blog/importing-archived-articles-from-legacy-system-into-episerver-cms
I had to import the content as EPiServer pages and use a similar tree structure.
Hope this helps :)
I am creating the profile pages for all the users while registration.
I want to save the profile page reference (ContentReference) along with other profile information. I am able to save LinkURL with the lifo but ContentReference gives me an error.
Where are you saving that page reference? Can you show us the code?
var profilePage = _contentRepository.GetDefault<UserProfilePage>(initialContainerPage.ContentLink);
profilePage.Name = registrationInfo.Firstname + " " + registrationInfo.Lastname;
profilePage.FirstName = registrationInfo.Firstname;
profilePage.LastName = registrationInfo.Lastname;
profilePage.UserEmail = registrationInfo.Email;
profilePage.FBID = registrationInfo.FBID;
_contentRepository.Save(profilePage, SaveAction.Publish, AccessLevel.NoAccess);
ProfileBase curProfile = ProfileBase.Create(registrationInfo.Email);
I've opened web.config, and added the following value inside profile / properties
<add name="ProfileLink" type="EPiServer.Core.PageReference, EPiServer"/>
And here's the code for saving /reading the profile link:
var profile = ProfileBase.Create("email@example.com");
var pageReference = profile.GetPropertyValue("ProfileLink") as PageReference;
Instead of PageReference, maybe you could store the seo friendly URL?
But I'm not sure why you need both UserProfilePage and ASP.NET profiles?You could use the UserProfilePage as a replacement for ASP.NET profile.