public async Task <ActionResult> Register(OrderConfirmationRegistrationBlock currentBlock, OrderConfirmationRegistrationFormModel viewModel)
        {
            var purchaseOrder = _orderRepository.Load <IPurchaseOrder>(viewModel.OrderNumber);

            var model = new OrderConfirmationRegistrationModel
            {
                CurrentBlock = currentBlock,
                FormModel    = viewModel
            };

            if (purchaseOrder == null)
            {
                ModelState.AddModelError("Password2", "Something went wrong");
            }

            if (!ModelState.IsValid || purchaseOrder == null)
            {
                return(PartialView("NewCustomer", model.FormModel));
            }

            ContactIdentityResult registration = await UserService.RegisterAccount(new SiteUser(purchaseOrder)
            {
                Password           = viewModel.Password,
                RegistrationSource = "Order confirmation page",
                IsApproved         = true
            });

            if (registration.Result.Succeeded)
            {
                if (registration.Contact.PrimaryKeyId.HasValue)
                {
                    purchaseOrder.CustomerId = registration.Contact.PrimaryKeyId.Value;

                    _orderRepository.Save(purchaseOrder);
                }
                return(PartialView("Complete", registration.Contact.Email));
            }

            if (registration.Result.Errors.Any())
            {
                registration.Result.Errors.ToList().ForEach(x => ModelState.AddModelError("Password2", x));
                return(PartialView("NewCustomer", model.FormModel));
            }

            return(PartialView("Index", model.FormModel));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Register(OrderConfirmationRegistrationBlock currentBlock, OrderConfirmationRegistrationFormModel formModel)
        {
            var purchaseOrder = OrderContext.Current.GetPurchaseOrder(formModel.OrderNumber);

            var model = new OrderConfirmationRegistrationModel
            {
                CurrentBlock = currentBlock,
                FormModel    = formModel
            };

            if (purchaseOrder == null)
            {
                ModelState.AddModelError("FormModel.Password2", "Something went wrong");
            }

            if (!ModelState.IsValid || purchaseOrder == null)
            {
                return(PartialView("NewCustomer", model));
            }

            ContactIdentityResult registration = await UserService.RegisterAccount(new ApplicationUser(purchaseOrder)
            {
                Password           = formModel.Password,
                RegistrationSource = "Order confirmation page"
            });

            if (registration.Result.Succeeded)
            {
                if (registration.Contact.PrimaryKeyId.HasValue)
                {
                    purchaseOrder.CustomerId   = registration.Contact.PrimaryKeyId.Value;
                    purchaseOrder.CustomerName = registration.Contact.FullName;
                    purchaseOrder.AcceptChanges();
                }
                return(PartialView("Complete", registration.Contact.Email));
            }

            if (registration.Result.Errors.Any())
            {
                registration.Result.Errors.ToList().ForEach(x => ModelState.AddModelError("FormModel.Password2", x));
                return(PartialView("NewCustomer", model));
            }

            return(PartialView("Index", model));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> RegisterAccount(RegisterAccountViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                _addressBookService.LoadAddress(viewModel.Address);
                return(View(viewModel));
            }

            ContactIdentityResult registration = null;

            viewModel.Address.BillingDefault  = true;
            viewModel.Address.ShippingDefault = true;
            viewModel.Address.Email           = viewModel.Email;

            var customerAddress = CustomerAddress.CreateInstance();

            _addressBookService.MapToAddress(viewModel.Address, customerAddress);

            var user = new SiteUser
            {
                UserName           = viewModel.Email,
                Email              = viewModel.Email,
                Password           = viewModel.Password,
                FirstName          = viewModel.Address.FirstName,
                LastName           = viewModel.Address.LastName,
                RegistrationSource = "Registration page",
                NewsLetter         = viewModel.Newsletter,
                Addresses          = new List <CustomerAddress>(new[] { customerAddress }),
                IsApproved         = true
            };

            registration = await UserService.RegisterAccount(user);

            if (registration.Result.Succeeded)
            {
                var returnUrl = GetSafeReturnUrl(Request.UrlReferrer);
                return(Json(new { ReturnUrl = returnUrl }, JsonRequestBehavior.DenyGet));
            }

            _addressBookService.LoadAddress(viewModel.Address);

            AddErrors(registration.Result.Errors);

            return(PartialView("RegisterAccount", viewModel));
        }
Ejemplo n.º 4
0
        public virtual async Task <ContactIdentityResult> RegisterAccount(SiteUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            ContactIdentityResult contactResult = null;
            IdentityResult        result        = null;
            CustomerContact       contact       = null;

            if (String.IsNullOrEmpty(user.Password))
            {
                throw new MissingFieldException("Password");
            }

            if (String.IsNullOrEmpty(user.Email))
            {
                throw new MissingFieldException("Email");
            }

            if (_userManager.FindByEmail(user.Email) != null)
            {
                result = new IdentityResult(_localizationService.GetString("/Registration/Form/Error/UsedEmail"));
            }
            else
            {
                result = await _userManager.CreateAsync(user, user.Password);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    contact = CreateCustomerContact(user);
                }
            }

            contactResult = new ContactIdentityResult(result, contact);

            return(contactResult);
        }