CreateUserWizardControl
I'm trying to implement the CreateUserWizard Control I downloaded from here: http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/createwizarduser-explains.aspx
Hi Kristian,
AddUserToRole is a methodof Telerik.Security.UserManager class.SetProfileProperties is a method of Telerik.Security.WebControls.ManageProfile class.
Best wishes,
Ivan Dimitrov
the Telerik team
Hi Kristian,
These are methods for Sitefinity 3.x edition. The API for Sitefinity 4.0 is different. In 4.0 you can use Telerik.Sitefinity.Security.RoleManager and its AddUserToRole method.
var provider =
"RolePRovider"
;
var manager = Telerik.Sitefinity.Security.RoleManager.GetManager(provider);
manager.AddUserToRole(param1, param2);
Thanks, but now I receive this error
|
void
CreateUserWizard1_CreatedUser(
object
sender, EventArgs e)
var provider =
"RoleProvider"
;
var manager = RoleManager.GetManager(provider);
User user =
new
User();
user.SetUserName(CreateUserWizard1.UserName);
Role role =
new
Role();
if
(defaultRoles !=
null
)
foreach
(
string
roleProfile
in
defaultRoles)
role.Name = roleProfile;
manager.AddUserToRole(user, role);
//this.Profile.SetPropertyValue("UserName", user.UserName);
Hi Kristian,
By default there are two providers - "Default" and "AppRoles". There is a third provider for LDAP. In your code you are passing "RoleProvider" to GetManager
().
Regards,
Ivan Dimitrov
the Telerik team
Ah thank you! that helps
Hi Kristian,
You can use Telerik.Sitefinity.Security.UserManager - Represents an intermediary between users and membership data providers. and Telerik.Sitefinity.Security.Model.User class - The persistent membership user class used by OpenAccess membership provider.
// getting user
var manager = Telerik.Sitefinity.Security.UserManager.GetManager();
var user = manager.GetUsers().Where(u => u.FirstName ==
"foo"
);
// creating user, setting properties
System.Web.Security.MembershipCreateStatus status;
var newUser = manager.CreateUser(
"username"
,
"pword"
,
"email"
,
"val"
,
"val"
,
true
,
null
,
out
status);
if
(status == System.Web.Security.MembershipCreateStatus.Success)
newUser.FirstName =
"val"
;
newUser.LastName =
"val"
;
manager.SaveChanges();
I'm not sure what Im doing wrong here, but I try that code and no user is created in the back end.
Hello Kristian,
Try using the default provider for UserManager. Verify that the status is "Success" otherwise the user will not be created. Note that the password must have special char in it
System.Web.Security.MembershipCreateStatus status;
var manager = UserManager.GetManager(
"Default"
);
var newUser = manager.CreateUser(
"username"
,
"username@username"
,
"email@test.com"
,
"val"
,
"val"
,
true
,
null
,
out
status);
if
(status == System.Web.Security.MembershipCreateStatus.Success)
newUser.FirstName =
"val"
;
newUser.LastName =
"val"
;
manager.SaveChanges();
Ah thank you, it was the special character in the password that was throwing me.
I have one more question, what do i need to do to retrieve an existing role and then add the user to the role.
when trying to use the wizard when not logged in, would there be some setting in the web.config to allow this?
Hello Kristian,
By default anonymous users are not allowed to manage users. When you are not logged in, you are an anonymous user. You can grant needed rights for a given role from Settings >> Permissions section of Sitefinity's backend.
All the best,
Ivan Dimitrov
the Telerik team