I do this with the following line. Note that Member Type and Roles are different. With the following code you can create a member specifying username, email, password and they MemberType.
var newMember = Services.MemberService.CreateWithIdentity("uniqueUserName", "[email protected]", "defaultpassword", "Social");
I should also add that you may want to check to see if user exists prior to trying to create then you can run create or update code. So something like:
var memberExists = Services.MemberService.Exists("[email protected]");
if (memberExists)
{
var userToSave = AppHelpers.UmbMemberHelper().CreateRegistrationModel(AppConstants.MemberTypeAlias);
userToSave.Name = userToSave.Username;
userToSave.UsernameIsEmail = false;
userToSave.Email = userModel.Email;
userToSave.Password = userModel.Password;
MembershipCreateStatus createStatus;
AppHelpers.UmbMemberHelper().RegisterMember(userToSave, out createStatus, false);
if (createStatus != MembershipCreateStatus.Success)
{
// Failed
}
else
{
// re-get the umbraco member, so we pick up anything that was added during the save
var umbracoMember = AppHelpers.UmbServices().MemberService.GetByUsername(userToSave.Username);
// Set the role/group they should be in
AppHelpers.UmbServices().MemberService.AssignRole(umbracoMember.Id, newMemberGroup.Name);
}
(Sorry couldn't get the code formatting to work). This is what I use on Umbraco 7.5x
How to add member to the specific Member Type
Hi everyone,
I installed package
(Install-Package UmbracoIdentity)
, all are works so fine. But I want to add the user to my created Member Type called ("Social").Here's my code.
But I got an error![enter image description here](/media/upload/323eb99a-0e68-48a5-a3e7-851e62b9ff2c/Capture.PNG)
Can anyone help me, I'm new in Umbraco also in ASP and I'm stuck.
Any help will be appreciated. Thanks in advance.
Regards,
Jin
I tried to delete this line
the error has gone but the page isn't redirecting and it always says
even if that is the first email I register, and also I tried to change the email, it's always says
Name... is already taken. Email.... is already taken
Am I doing right, or I got missing code?
Regards,
Jin
Hi Jin,
I do this with the following line. Note that Member Type and Roles are different. With the following code you can create a member specifying username, email, password and they MemberType.
I should also add that you may want to check to see if user exists prior to trying to create then you can run create or update code. So something like:
// create new member code here... }
Where did you find the package "Install-Package UmbracoIdentity", I am looking to do something similar, maybe I can help figure this out
Hi John, I can't say for sure, but Jin might be referring to the following:
https://github.com/Shazwazza/UmbracoIdentity
Hi John,
Yes, Phill is right,
Thanks Phil, I bet you are right
Help me, I'm stuck
Anyone can help me?
Try something like this
(Sorry couldn't get the code formatting to work). This is what I use on Umbraco 7.5x
Formatting fixed. For future reference, there's a button ;)
I tried that, it kept only formatting a small subset of it and then injected a horizontal scroll bar and turned the rest to text.
(Thanks for fixing the formatting)
is working on a reply...