public override void Process(SignInArgs args)
        {
            try
            {
                // get current user
                string         username = args.User.InnerUser.Profile.Email;
                GetUserRequest request  = new GetUserRequest(username);
                GetUserResult  user     = _customerServiceProvider.GetUser(request);
                if (!user.Success || user.CommerceUser == null)
                {
                    // if user isn't a customer, run customer create pipeline
                    string            password          = Guid.NewGuid().ToString();
                    CreateUserRequest createUserRequest = new CreateUserRequest(username, password, username, _storefrontContext.CurrentStorefront.ShopName);
                    CreateUserResult  createUserResult  = _customerServiceProvider.CreateUser(createUserRequest);
                }

                // identify commerce user and merge anonymous cart
                Cart result = _cartManager.GetCurrentCart(_visitorContext, _storefrontContext, false).Result;
                Tracker.Current.CheckForNull().Session.IdentifyAs("CommerceUser", username);
                _visitorContext.UserJustLoggedIn();
                _cartManager.MergeCarts(_storefrontContext.CurrentStorefront, _visitorContext, _visitorContext.CustomerId, result);
            }
            catch (Exception ex)
            {
                // log error
                Sitecore.Diagnostics.Log.Error($"Failed to create a customer for external user login {args.User.UserName}. {ex.Message}", this);
            }
        }
Ejemplo n.º 2
0
        public ManagerResponse <CreateUserResult, CommerceUser> RegisterUserCustomer(IStorefrontContext storefrontContext, string userName, string password,
                                                                                     string email, string secondaryEmail)
        {
            Assert.ArgumentNotNull(storefrontContext, nameof(storefrontContext));
            Assert.ArgumentNotNullOrEmpty(userName, nameof(userName));
            Assert.ArgumentNotNullOrEmpty(password, nameof(password));
            CreateUserResult createUserResult1;

            try
            {
                var createUserRequest = new CreateUserRequest(userName, password, email, storefrontContext.CurrentStorefront.ShopName);
                createUserRequest.Properties.Add("SecondEmail", secondaryEmail);
                createUserResult1 = CustomerServiceProvider.CreateUser(createUserRequest);
                //createUserResult1 = CustomerServiceProvider.CreateUser(new CreateUserRequest(userName, password, email, storefrontContext.CurrentStorefront.ShopName));
                if (!createUserResult1.Success)
                {
                    Helpers.LogSystemMessages(createUserResult1.SystemMessages, createUserResult1);
                }
                else if (createUserResult1.Success)
                {
                    if (createUserResult1.CommerceUser == null)
                    {
                        if (createUserResult1.SystemMessages.Count == 0)
                        {
                            createUserResult1.Success = false;
                            createUserResult1.SystemMessages.Add(new SystemMessage()
                            {
                                Message = storefrontContext.GetSystemMessage("User Already Exists")
                            });
                        }
                    }
                }
            }
            catch (MembershipCreateUserException ex)
            {
                CreateUserResult createUserResult2 = new CreateUserResult {
                    Success = false
                };
                createUserResult1 = createUserResult2;
                createUserResult1.SystemMessages.Add(new SystemMessage()
                {
                    Message = ErrorCodeToString(storefrontContext, ex.StatusCode)
                });
            }
            catch (Exception ex)
            {
                CreateUserResult createUserResult2 = new CreateUserResult {
                    Success = false
                };
                createUserResult1 = createUserResult2;
                createUserResult1.SystemMessages.Add(new SystemMessage()
                {
                    Message = storefrontContext.GetSystemMessage("Unknown Membership Provider Error")
                });
            }
            CreateUserResult serviceProviderResult = createUserResult1;

            return(new ManagerResponse <CreateUserResult, CommerceUser>(serviceProviderResult, serviceProviderResult.CommerceUser));
        }
Ejemplo n.º 3
0
        public ActionResult CreateUser()
        {
            var customerService = new CustomerServiceProvider();

            var request = new CreateUserRequest("CommerceUsers\\[email protected]", "password", "*****@*****.**", "CommerceEngineDefaultStorefront");

            var result = customerService.CreateUser(request);

            return(View(result));
        }
Ejemplo n.º 4
0
        public ManagerResponse <CreateUserResult, CommerceUser> RegisterUser(RegisterUserInputModel inputModel)
        {
            Assert.ArgumentNotNull(inputModel, nameof(inputModel));
            Assert.ArgumentNotNullOrEmpty(inputModel.UserName, nameof(inputModel.UserName));
            Assert.ArgumentNotNullOrEmpty(inputModel.Password, nameof(inputModel.Password));
            if (StorefrontContext.Current == null)
            {
                throw new InvalidOperationException("Cannot be called without a valid storefront context.");
            }

            CreateUserResult result;

            // Attempt to register the user
            try
            {
                var request = new CreateUserRequest(inputModel.UserName, inputModel.Password, inputModel.UserName, StorefrontContext.Current.ShopName);
                result = CustomerServiceProvider.CreateUser(request);
                result.WriteToSitecoreLog();

                if (result.Success && result.CommerceUser == null && !result.SystemMessages.Any())
                {
                    // Connect bug:  This is a work around to a Connect bug.  When the user already exists,connect simply aborts the pipeline but
                    // does not set the success flag nor does it return an error message.
                    result.Success = false;
                    result.SystemMessages.Add(new SystemMessage
                    {
                        Message = DictionaryPhraseRepository.Current.Get("/System Messages/Accounts/User Already Exists", "User name already exists. Please enter a different user name.")
                    });
                }
            }
            catch (MembershipCreateUserException e)
            {
                result = new CreateUserResult {
                    Success = false
                };
                result.SystemMessages.Add(new SystemMessage {
                    Message = ErrorCodeToString(e.StatusCode)
                });
            }

            return(new ManagerResponse <CreateUserResult, CommerceUser>(result, result.CommerceUser));
        }
        public PipelineExecutionResult Execute(IPipelineArgs <CreateMemberRequest, CreateMemberResponse> subject)
        {
            if (subject.Request.Properties.ContainsKey("FromUCommerce"))
            {
                if (!(bool)subject.Request.Properties["FromUCommerce"])
                {
                    return(PipelineExecutionResult.Success);
                }
            }

            var customerService = new CustomerServiceProvider();

            var createUserRequest = new CreateUserRequest(
                subject.Response.Member.LoginName,
                subject.Response.Member.Password,
                subject.Response.Member.Email,
                Context.GetSiteName());

            createUserRequest.Properties["FromUCommerce"] = true;

            customerService.CreateUser(createUserRequest);

            return(PipelineExecutionResult.Success);
        }