public IdentityCreateReply IdentityCreate(IdentityCreateRequest request) { try { IdentityCreateReply response = new IdentityCreateReply(); MembershipCreateStatus status = MembershipCreateStatus.ProviderError; MembershipUser user = request.User; user = _membership.CreateUser(user.UserName, request.Password, user.Email, user.PasswordQuestion, request.Answer, user.IsApproved, user.ProviderUserKey, out status); setStatus(response, status); response.User = user; response.CreateStatus = status; if (status == MembershipCreateStatus.Success && user != null) { user.IsApproved = false; user.Comment = Guid.NewGuid().ToString(); _membership.UpdateUser(user); response.ActivationKey = user.Comment; } return(response); } catch (Exception ex) { throw ex.NewFault(); } }
private void setStatus(IdentityCreateReply response, MembershipCreateStatus status) { switch (status) { case MembershipCreateStatus.DuplicateEmail: response.Messages.Add(ActionStatus.Conflict, "EMail address already exists"); break; case MembershipCreateStatus.DuplicateProviderUserKey: response.Messages.Add(ActionStatus.Conflict, "Provider User Key already exists"); break; case MembershipCreateStatus.DuplicateUserName: response.Messages.Add(ActionStatus.Conflict, "Username already exists"); break; case MembershipCreateStatus.InvalidAnswer: response.Messages.Add(ActionStatus.Error, "Answer is missing or invalid"); break; case MembershipCreateStatus.InvalidEmail: response.Messages.Add(ActionStatus.Error, "EMail is missing or invalid"); break; case MembershipCreateStatus.InvalidPassword: response.Messages.Add(ActionStatus.Error, "Password is invalid. Password " + expandPasswordRules()); break; case MembershipCreateStatus.InvalidProviderUserKey: response.Messages.Add(ActionStatus.Error, "Invalid provider user key"); break; case MembershipCreateStatus.InvalidQuestion: response.Messages.Add(ActionStatus.Error, "Question is missing or invalid"); break; case MembershipCreateStatus.InvalidUserName: response.Messages.Add(ActionStatus.Error, "Username is missing or invalid"); break; case MembershipCreateStatus.ProviderError: response.Messages.Add(ActionStatus.InternalError, "Membership provider discovered some kind of error"); break; case MembershipCreateStatus.UserRejected: response.Messages.Add(ActionStatus.Error, "User not created"); break; } response.CreateStatus = status; if (response.IsValid == true) { response.Status = ActionStatus.Created; } else { response.Status = response.Messages[0].Severity; } }