Profile Management
Hi,
I have a requirement to extend some properties of a user account profile and i need to:
- Add several new fields when saving the user and creating their profile
- one of the profile fields will be a boolean for acceptance (there account needs to be confirmed) can i have this manageable on the user section of the admin.
I know there is some code currently in the forums, but has this changed in 4.1? and if so where would i find the information to get this done, i cant seem to find to much in the documentation.
Rob
Hi Roberto,
There is such functionality you require in Sitefinity 4.1 (Sitefinity’s Custom Profiles and Custom Profile Field feature) you can use documentation for information on how to create new profile types and add custom fields to them.
We are still having some issues with profile custom fields that will be resolved soon. In this case I will advise you to extend your profiles with custom fields by using only the Basic profile type and adding custom fields to it to avoid issues. let me know if you need more information on this.
Hi Stanislav,
Thank you for the response i will read through the documentation. If i add items to the profile will i be able to manage them in the administration?
Thank you,
Rob
Hello Roberto,
Yes you will be able to add the custom fields to the profiles you create and manage them and use the new profile widgets to aid you in achieving the results you require. Just make sure you are using basic profile type when adding custom fields to profiles to avoid issues we are working to resolve.
Best wishes,Hi there again,
I have update the basic profile (thank you for that info) but have hit a bit of a problem. I have written my own registration control as i have to do some additional work when creating users etc and for some reason i cannot seem to update the fields i created in the basic profile.
i recieve:
protected void cmdSubmit_Click(object sender, EventArgs e)
var transactionName = "Insert";
UserManager manager = UserManager.GetManager("Default", transactionName);
RoleManager roleManager = RoleManager.GetManager("Default");
UserProfileManager profileManager = UserProfileManager.GetManager();
profileManager.TransactionName = transactionName;
MembershipCreateStatus status;
//Create User
var user = manager.CreateUser(txtUsername.Text,
txtPassword.Text,
txtEmailAddress.Text, "", "", true, null, out status);
if (user == null)
//TODO:
else
roleManager.AddUserToRole(user, roleManager.GetRole("TradeRole"));
roleManager.SaveChanges();
var prf = profileManager.CreateProfile(user);
prf.SetValue("CompanyName", txtCompanyName.Text);
prf.SetValue("FirstName", txtFirstName.Text);
prf.SetValue("LastName", txtLastName.Text);
TransactionManager.CommitTransaction(transactionName);
Hi Roberto,
You need to use SitefinityProfile object
www.sitefinity.com/.../retrieving-custom-profile-fields.aspx
www.sitefinity.com/.../how-to-set-avatar-in-user-profile.aspx
Profiles API has been changed with Sitefinity 4.1( Q1) release.
Greetings,
Ivan Dimitrov
the Telerik team
Thanks Ivan,
it was due to not using the SitefinityProfile type.
Rob
I've tried to implement this, but I can't see to get the values of the userprofile to save to sitefinity. This is the code I have so far.
UserManager usermanager = UserManager.GetManager("Default", _transactionName);
RoleManager roleManager = RoleManager.GetManager("Default");
var profileManager = UserProfileManager.GetManager();
profileManager.TransactionName = _transactionName;
usermanager.Provider.SuppressSecurityChecks = true;
roleManager.Provider.SuppressSecurityChecks = true;
profileManager.Provider.SuppressSecurityChecks = true;
MembershipCreateStatus status;
//Create User
UserObject = usermanager.CreateUser(UserName,
Password,
Email, "", "", true, null, out status);
if (UserObject != null)
roleManager.AddUserToRole(UserObject, roleManager.GetRole(role));
roleManager.SaveChanges();
var prf = profileManager.CreateProfile(UserObject, typeof(SitefinityProfile).FullName);
DataExtensions.SetValue(prf, "FirstName", FirstName);
DataExtensions.SetValue(prf, "LastName", LastName);
TransactionManager.CommitTransaction(_transactionName);
I also tried to save through the user profile (prf.SetValue("FirstName", FirstName)), but this also doesn't seem to work. How must I fix this?
I'm runnig on sitefinity 4.1.
Kind regards,
Mark
Hello ,
Please try using the code below. After you call SaveChanges of the manager, call GetValue to see whether the data is persisted. I checked this at my end the the extension method returns correct data.
var profileManager = UserProfileManager.GetManager();
var usermanager = UserManager.GetManager();
var UserObject = usermanager.GetUsers().First();
var prf = profileManager.CreateProfile(UserObject,
typeof
(SitefinityProfile).FullName);
prf.SetValue(
"FirstName"
,
"Fname"
);
prf.SetValue(
"LastName"
,
"lname"
);
profileManager.SaveChanges();
var uo = usermanager.GetUsers().First();
var f = prf.GetValue(
"FirstName"
);
var l = prf.GetValue(
"LastName"
);
Hi,
We used the following code to update the profile. We extened the basic profile as i was told there were issues with extending the system by creating your own. Our profile update was part of our user creation routine.
if (Page.IsValid)
var transactionName = "Insert";
UserManager manager = UserManager.GetManager("Default", transactionName);
RoleManager roleManager = RoleManager.GetManager("Default");
UserProfileManager profileManager = UserProfileManager.GetManager();
MembershipCreateStatus status;
//Create User
var user = manager.CreateUser(txtUsername.Text,
txtPassword.Text,
txtEmailAddress.Text, "", "", true, null, out status);
if (user == null)
string error = "A problem has occoured";
//Get Error
switch (status)
case MembershipCreateStatus.DuplicateUserName:
error = "Username already exists in the system.";
break;
case MembershipCreateStatus.DuplicateEmail:
error = "Email address already registred. If you have an account already, please login.";
break;
case MembershipCreateStatus.InvalidPassword:
error = "Password is invalid, please ensure your password is at least 7 characters in length.";
break;
case MembershipCreateStatus.InvalidUserName:
error = "Username is invalid, please try another";
break;
pnlError.Visible = true;
litError.Text = error;
else
roleManager.AddUserToRole(user, roleManager.GetRole("NewRole"));
roleManager.SaveChanges();
var prf = profileManager.CreateProfile(user, typeof(SitefinityProfile).FullName);
DataExtensions.SetValue(prf, "FirstName", txtFirstName.Text);
DataExtensions.SetValue(prf, "LastName", txtLastName.Text);
DataExtensions.SetValue(prf, "CompanyName", txtCompanyName.Text);
DataExtensions.SetValue(prf, "County", txtCounty.Text);
DataExtensions.SetValue(prf, "City", txtCity.Text);
DataExtensions.SetValue(prf, "PostalCode", txtPostCode.Text);
DataExtensions.SetValue(prf, "Country", txtCountry.Text);
DataExtensions.SetValue(prf, "PhoneNumber", txtPhone.Text);
profileManager.SaveChanges();
TransactionManager.CommitTransaction(transactionName);
Thanks for your quick replies. I've tried both your codes and in both cases calling profileManager.SaveChanges() results in an error. The message I'm getting is:
Cannot use SaveChanges or CancelChanges on instance manager that was specified to use global or distributed transaction. Instead, use TransactionManager static methods CommitTransaction(string transactionName) or RollbackTransaction(string transactionName).
Any Ideas?
@Roberto: Do you know if own extended profile are still a problem, because I'm using two custom profiles as well. So maybe I have to redesign to only the basic profile.
With kind regards,
Mark
Hi,
The error you are getting indicates that you use an object in two scopes. Generally this happens when there are two managers that are trying to use one object. In this case you should use TransactionManager.CommitTransaction. If you use the fluent API you should create an instance of App.Prepare and use it.
Greetings,
Ivan Dimitrov
the Telerik team
Hi,
I've been following this thread to get the profile manager to to accept custom fields upon user registration. I'm just getting an error on profileManager.SaveChanges(); and i cant get it to work with TransactionManager.CommitTransaction(transactionName);
I'd just like to know if it is possible to extend the basic profile in 4.1 upon registration.
If so any further advice would be appreciated.
Warm regards,
Pat
error:
Hello Pat,
Can you show the code you use?
Greetings,
Ivan Dimitrov
the Telerik team
Hi pat,
I had the same problem, because I declared a manager on the class level and in the create function I created another manager. For me this caused the problem, so I removed the manager on class level. You can download the class I use for creating and updating the userprofile here.
I've also looked into creating custom profiles, but couldn't get it to work when I created a new user. So therefor I just extended the basic userprofile with the fields I needed. Perhaps this is also the way to go for you. It sertenly is the most easy path to follow.
Hope this helps you out.
With kind regards,
Mark
Hi Mark,
Thanks so much for that, i was able to hack up my code from looking at your example and got it working.
Kind Regards,
Pat
public partial class register : System.Web.UI.UserControl
protected void cmdSubmit_Click(object sender, EventArgs e)
string transactionName = "Insert";
UserManager manager = UserManager.GetManager("Default",transactionName);
RoleManager roleManager = RoleManager.GetManager("Default");
UserProfileManager profileManager = UserProfileManager.GetManager();
MembershipCreateStatus status;
//Create User
User user = manager.CreateUser(txtUsername.Text,
txtPassword.Text,
txtEmailAddress.Text, "", "", true, null, out status);
if (user == null)
//TODO:
else
roleManager.AddUserToRole(user, roleManager.GetRole("frontEndUsers"));
roleManager.SaveChanges();
var prf = profileManager.CreateProfile(user, typeof(SitefinityProfile).FullName);
if (prf.DoesFieldExist("FirstName")) prf.SetValue("FirstName", txtFirstName.Text); else pagecommand.Text = "<script>alert('no first name');</script>";
if (prf.DoesFieldExist("LastName")) prf.SetValue("LastName", txtLastName.Text); else pagecommand.Text = "<script>alert('no last name');</script>";
if (prf.DoesFieldExist("division")) prf.SetValue("division", txtDivision.Text); else pagecommand.Text = "<script>alert('no division');</script>";
profileManager.SaveChanges();
/*DataExtensions.SetValue(prf, "FirstName", txtFirstName.Text);
DataExtensions.SetValue(prf, "LastName", txtLastName.Text);
DataExtensions.SetValue(prf, "division", txtDivision.Text);*/
TransactionManager.CommitTransaction(transactionName);
Hi Pat, did you get this to work on sitefinity 4.2, Or any one out there got some sample code.
Very disappointed that sitefinity does not seem to be giving us some good quality of sample of code, as they used to in the old days.
Help any one.
Hello,
In 4.2 you can use the UserProfileManager Class
Regards,
Ivan Dimitrov
the Telerik team
Dear Ivan, first of all very much for the Link, WHOEVER I stand by my word, YOU NEED SAMPLE CODE, specially if you make huge changes, how things work from 4.1. to 4.2.
Something as simple as the code below, would have saved me hours of trial and error, which many companies do not have the previlege of, sitefinity is supose to save us time, instead I feel im spending more time being a beta tester thant I should due to the lack o sample code.
Note: after some help from an external source I realized I had some missing references, the code below works for me for Sitefinity 4.2 , I hope this helps any one else out there.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.Security;
using
System.Data;
using
System.Data.SqlClient;
using
Telerik.Sitefinity;
using
Telerik.Sitefinity.Configuration;
using
Telerik.Sitefinity.Data.Configuration;
using
Telerik.Sitefinity.Security;
using
Telerik.Sitefinity.Security.Model;
using
Telerik.Sitefinity.Model;
using
Telerik.Sitefinity.Data;
public
partial
class
RegisterUserTest : System.Web.UI.UserControl
protected
void
Page_Load(
object
sender, EventArgs e)
string
transactionName =
"Insert"
;
UserManager manager = UserManager.GetManager(
"Default"
, transactionName);
RoleManager roleManager = RoleManager.GetManager(
"Default"
);
UserProfileManager profileManager = UserProfileManager.GetManager();
System.Web.Security.MembershipCreateStatus status;
//Create User
User user = manager.CreateUser(
"myuser2011"
,
"sitefinity560478$"
,
"temp@temp666.com"
,
""
,
""
,
true
,
null
,
out
status);
if
(user ==
null
)
//TODO:
else
roleManager.AddUserToRole(user, roleManager.GetRole(
"MY_ROLE"
));
roleManager.SaveChanges();
var prf = profileManager.CreateProfile(user,
typeof
(SitefinityProfile).FullName);
if
(prf.DoesFieldExist(
"FirstName"
)) prf.SetValue(
"FirstName"
,
"FirstName 111"
);
if
(prf.DoesFieldExist(
"LastName"
)) prf.SetValue(
"LastName"
,
"LastName 222"
);
if
(prf.DoesFieldExist(
"Address1"
)) prf.SetValue(
"Address1"
,
"Address1 333"
);
profileManager.SaveChanges();
/*DataExtensions.SetValue(prf, "FirstName", txtFirstName.Text);
DataExtensions.SetValue(prf, "LastName", txtLastName.Text);
DataExtensions.SetValue(prf, "division", txtDivision.Text);*/
TransactionManager.CommitTransaction(transactionName);
I'm trying to run a front-end registration form with Sitefinity 5.0 SP1, but not with the default membership provider but "OpenAccessMembership37Provider".
I have the following code, which results in an error on the line that defines the RoleManager (row 02).
01.
UserManager manager = UserManager.GetManager("OpenAccessMembership37Provider");
02.
RoleManager roleManager = RoleManager.GetManager("OpenAccessMembership37Provider");
03.
UserProfileManager profileManager = UserProfileManager.GetManager();
04.
MembershipCreateStatus status;
05.
06.
manager.Provider.SuppressSecurityChecks = true;
07.
roleManager.Provider.SuppressSecurityChecks = true;
08.
profileManager.Provider.SuppressSecurityChecks = true;
09.
10.
//Create User
11.
var user = manager.CreateUser(UserName.Text, Password.Text, Email.Text, "", "", false, null, out status);
12.
if (status != MembershipCreateStatus.Success)
There is no configuration for data provider with the name of "OPENACCESSMEMBERSHIP37PROVIDER" for "Telerik.Sitefinity.Security.RoleManager" manager. Please check the spelling of the name and whether such configuration exists.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Telerik.Sitefinity.Data.MissingProviderConfigurationException: There is no configuration for data provider with the name of "OPENACCESSMEMBERSHIP37PROVIDER" for "Telerik.Sitefinity.Security.RoleManager" manager. Please check the spelling of the name and whether such configuration exists.
Source Error:
Line 250:
Line 251: UserManager manager = UserManager.GetManager("OpenAccessMembership37Provider");
Line 252: RoleManager roleManager = RoleManager.GetManager("OpenAccessMembership37Provider");
Line 253: UserProfileManager profileManager = UserProfileManager.GetManager();
Line 254: MembershipCreateStatus status;
To answer myself:
Line in question should read:
RoleManager roleManager = RoleManager.GetManager("AppRoles");
if (roleManager.RoleExists("Members"))
Role role = roleManager.GetRole("Members");
roleManager.AddUserToRole(user, role);
roleManager.SaveChanges();