Exemple #1
0
        public virtual ManagerResponse <CreateUserResult, CommerceUser> RegisterUser(IStorefrontContext storefrontContext, string userName, string password, string email, StringPropertyCollection propertyBag = null)
        {
            Diagnostics.Assert.ArgumentNotNull(storefrontContext, "storefrontContext");
            Diagnostics.Assert.ArgumentNotNullOrEmpty(userName, "userName");
            Diagnostics.Assert.ArgumentNotNullOrEmpty(password, "password");
            CreateUserResult createUserResult;

            try
            {
                CreateUserRequest request = new CreateUserRequest(userName, password, email, storefrontContext.CurrentStorefront.ShopName);
                request.CopyPropertyBag(propertyBag);
                createUserResult = _customerServiceProvider.CreateUser(request);
                if (!createUserResult.Success)
                {
                    Helpers.LogSystemMessages(createUserResult.SystemMessages, createUserResult);
                }
                else if (createUserResult.Success && createUserResult.CommerceUser == null && createUserResult.SystemMessages.Count == 0)
                {
                    createUserResult.Success = false;
                    createUserResult.SystemMessages.Add(new SystemMessage
                    {
                        Message = storefrontContext.GetSystemMessage("User Already Exists")
                    });
                }
            }
            catch (MembershipCreateUserException ex)
            {
                createUserResult = new CreateUserResult
                {
                    Success = false
                };
                createUserResult.SystemMessages.Add(new SystemMessage
                {
                    Message = ex.StatusCode.ToString()
                });
            }
            catch (Exception ex)
            {
                createUserResult = new CreateUserResult
                {
                    Success = false
                };
                createUserResult.SystemMessages.Add(new SystemMessage
                {
                    Message = storefrontContext.GetSystemMessage("Unknown Membership Provider Error")
                });
            }
            return(new ManagerResponse <CreateUserResult, CommerceUser>(createUserResult, createUserResult.CommerceUser));
        }