protected override SubmissionExecuteResult Execute(RegisterCustomerModel model)
        {
            var membership = MemberPluginHelper.GetMembership();
            var user       = _userManager.Create(membership, model.Email, model.Email, model.Password, true, "en-US", null);

            var customer = new Customer
            {
                Email     = model.Email,
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Gender    = model.Gender
            };

            if (model.CustomFields != null)
            {
                foreach (var each in model.CustomFields)
                {
                    customer.CustomFields.Add(each.Key, each.Value);
                }
            }

            var customerId = Site.Commerce().Customers.Create(customer);

            if (model.SetAuthCookie)
            {
                var auth = new MembershipAuthentication(Site, membership, HttpContext);
                auth.SetAuthCookie(customer.Email, false);

                var sessionId = EngineContext.Current.Resolve <IShoppingCartSessionIdProvider>().GetCurrentSessionId(false);
                if (!String.IsNullOrWhiteSpace(sessionId))
                {
                    Site.Commerce().ShoppingCarts.MigrateCart(customerId, sessionId);
                }
            }

            return(new SubmissionExecuteResult
            {
                RedirectUrl = ResolveUrl(model.ReturnUrl, ControllerContext),
                Data = new RegisterCustomerResult
                {
                    CustomerId = customer.Id
                }
            });
        }
Beispiel #2
0
        protected virtual bool RegisterCore(ControllerContext controllerContext, SubmissionSetting submissionSetting, out string redirectUrl)
        {
            redirectUrl = "";
            var membership = MemberPluginHelper.GetMembership();

            var registerMemberModel = new RegisterMemberModel();

            bool valid = ModelBindHelper.BindModel(registerMemberModel, "", controllerContext, submissionSetting);

            if (valid)
            {
                redirectUrl = registerMemberModel.RedirectUrl;
                if (!string.IsNullOrEmpty(redirectUrl))
                {
                    redirectUrl = MemberPluginHelper.ResolveSiteUrl(controllerContext, redirectUrl);
                }
                try
                {
                    var membershipUser = _manager.Create(membership, registerMemberModel.UserName, registerMemberModel.Email, registerMemberModel.Password, registerMemberModel.IsApproved, registerMemberModel.Culture
                                                         , registerMemberModel.TimeZoneId, registerMemberModel.PasswordQuestion, registerMemberModel.PasswordAnswer, null, registerMemberModel.Profiles, null);

                    if (registerMemberModel.IsApproved == false)
                    {
                        SendActivateMail(controllerContext, Site.Current, membershipUser, registerMemberModel, membershipUser.ActivateCode);
                    }
                }
                catch (DataViolationException e)
                {
                    controllerContext.Controller.ViewData.ModelState.FillDataViolation(e.Violations);
                    valid = false;
                }
                catch (Exception e)
                {
                    controllerContext.Controller.ViewData.ModelState.AddModelError("", e.Message);
                    Kooboo.HealthMonitoring.Log.LogException(e);
                    valid = false;
                }
            }
            return(valid);
        }
Beispiel #3
0
        public virtual ActionResult Create(CreateMembershipUserModel model, string @return)
        {
            JsonResultData data = new JsonResultData();

            if (ModelState.IsValid)
            {
                data.RunWithTry((resultData) =>
                {
                    try
                    {
                        _manager.Create(Membership, model.UserName, model.Email, model.Password, model.IsApproved, model.Culture, model.TimeZoneId, model.PasswordQuestion, model.PasswordAnswer
                                        , model.MembershipGroups, model.Profiles, model.Comment);
                        resultData.RedirectUrl = @return;
                    }
                    catch (DataViolationException dataViolationException)
                    {
                        ModelState.FillDataViolation(dataViolationException.Violations);
                    }
                });
            }
            data.AddModelState(ModelState);
            return(Json(data));
        }