public SignUpPostModel PrepareRegisterModel(SignUpPostModel model, bool excludeProperties, string overrideCustomCustomerAttributesXml = "", bool setDefaultValues = false) { if (model == null) { throw new ArgumentNullException(nameof(model)); } return(model); }
public IActionResult SignUp() { //check whether registration is allowed if (_customerSettings.UserRegistrationType == UserRegistrationType.Disabled) { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Disabled })); } var model = new SignUpPostModel(); model = _customerModelFactory.PrepareRegisterModel(model, false, setDefaultValues: true); return(View()); }
public IActionResult SignUp(SignUpPostModel model, string returnUrl, bool captchaValid) { //check whether registration is allowed if (_customerSettings.UserRegistrationType == UserRegistrationType.Disabled) { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Disabled })); } if (_workContext.CurrentCustomer.IsRegistered()) { //Already registered customer. _authenticationService.SignOut(); //raise logged out event _eventPublisher.Publish(new CustomerLoggedOutEvent(_workContext.CurrentCustomer)); //Save a new record _workContext.CurrentCustomer = _customerService.InsertGuestCustomer(); } var customer = _workContext.CurrentCustomer; //custom customer attributes //var customerAttributesXml = ParseCustomCustomerAttributes(model.Form); //var customerAttributeWarnings = _customerAttributeParser.GetAttributeWarnings(customerAttributesXml); //foreach (var error in customerAttributeWarnings) //{ // ModelState.AddModelError("", error); //} //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnRegistrationPage && !captchaValid) { ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService)); } if (ModelState.IsValid) { var isApproved = _customerSettings.UserRegistrationType == UserRegistrationType.Standard; var registrationRequest = new CustomerRegistrationRequest(customer, model.Email, model.Username, model.Password, _customerSettings.DefaultPasswordFormat, isApproved); var registrationResult = _customerRegistrationService.RegisterCustomer(registrationRequest); if (registrationResult.Success) { //login customer now if (isApproved) { _authenticationService.SignIn(customer, true); } //raise event _eventPublisher.Publish(new CustomerRegisteredEvent(customer)); switch (_customerSettings.UserRegistrationType) { case UserRegistrationType.EmailValidation: { //email validation message _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.AccountActivationToken, Guid.NewGuid().ToString()); //_workflowMessageService.SendCustomerEmailValidationMessage(customer, _workContext.WorkingLanguage.Id); //result return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation })); } case UserRegistrationType.AdminApproval: { return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval })); } case UserRegistrationType.Standard: { //send customer welcome message //_workflowMessageService.SendCustomerWelcomeMessage(customer, _workContext.WorkingLanguage.Id); var redirectUrl = Url.RouteUrl("RegisterResult", new { resultId = (int)UserRegistrationType.Standard }); if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl)) { redirectUrl = _webHelper.ModifyQueryString(redirectUrl, "returnurl=" + WebUtility.UrlEncode(returnUrl), null); } return(Redirect(redirectUrl)); } default: { return(RedirectToRoute("HomePage")); } } } //errors foreach (var error in registrationResult.Errors) { ModelState.AddModelError("", error); } } //If we got this far, something failed, redisplay form model = _customerModelFactory.PrepareRegisterModel(model, true, setDefaultValues: true); return(View(model)); }