public JsonResult ExtendedRegistration(RegistrationInputModel inputModel) { JsonResult result; try { Assert.ArgumentNotNull(inputModel, "RegistrationInputModel"); RegistrationBaseJsonResult registrationBaseJsonResult = new RegistrationBaseJsonResult(StorefrontContext, SitecoreContext); ValidateModel(registrationBaseJsonResult); if (registrationBaseJsonResult.HasErrors) { result = Json(registrationBaseJsonResult, JsonRequestBehavior.AllowGet); } else { ManagerResponse <CreateUserResult, CommerceUser> managerResponse = AccountManager.RegisterUser(StorefrontContext, UpdateUserName(inputModel.UserName), inputModel.Password, inputModel.UserName); if (managerResponse.ServiceProviderResult.Success && managerResponse.Result != null) { registrationBaseJsonResult.Initialize(managerResponse.Result); AccountManager.Login(StorefrontContext, VisitorContext, managerResponse.Result.UserName, inputModel.Password, false); AccountManager.UpdateUser(VisitorContext, inputModel.FirstName, inputModel.LastName, string.Empty, inputModel.UserName); } else { registrationBaseJsonResult.SetErrors(managerResponse.ServiceProviderResult); } result = Json(registrationBaseJsonResult); } } catch (Exception exception) { result = Json(new BaseJsonResult("Registration", exception, StorefrontContext, SitecoreContext), JsonRequestBehavior.AllowGet); } return(result); }
public JsonResult RegistrationCustom(RegistrationUserInputModelCustom inputModel) { try { Assert.ArgumentNotNull(inputModel, "RegistrationUserInputModel"); RegistrationBaseJsonResult registrationBaseJsonResult = new RegistrationBaseJsonResult(StorefrontContext, SitecoreContext); ValidateModel(registrationBaseJsonResult); if (registrationBaseJsonResult.HasErrors) { return(Json(registrationBaseJsonResult, JsonRequestBehavior.AllowGet)); } ManagerResponse <CreateUserResult, CommerceUser> managerResponse = CustomAccountManager.RegisterUserCustomer(StorefrontContext, UpdateUserName(inputModel.UserName), inputModel.Password, inputModel.UserName, inputModel.SecondaryEmail); if (managerResponse.ServiceProviderResult.Success && managerResponse.Result != null) { registrationBaseJsonResult.Initialize(managerResponse.Result); AccountManager.Login(StorefrontContext, VisitorContext, managerResponse.Result.UserName, inputModel.Password, false); } else { registrationBaseJsonResult.SetErrors(managerResponse.ServiceProviderResult); } return(Json(registrationBaseJsonResult)); } catch (Exception ex) { return(Json(new BaseJsonResult(nameof(Registration), ex, StorefrontContext, SitecoreContext), JsonRequestBehavior.AllowGet)); } }