public JsonResult Register(RegisterUserInputModel inputModel) { try { Assert.ArgumentNotNull(inputModel, "RegisterInputModel"); RegisterBaseJsonResult result = new RegisterBaseJsonResult(); this.ValidateModel(result); if (result.HasErrors) { return Json(result, JsonRequestBehavior.AllowGet); } var response = this.AccountManager.RegisterUser(this.CurrentStorefront, inputModel); if (response.ServiceProviderResult.Success && response.Result != null) { var isLoggedIn = this.AccountManager.Login(CurrentStorefront, CurrentVisitorContext, response.Result.UserName, inputModel.Password, false); if (isLoggedIn) { result.Initialize(response.Result); } else { result.SetErrors(new List<string> { StorefrontManager.GetSystemMessage("CouldNotCreatedUser") }); } } else { result.SetErrors(response.ServiceProviderResult); } return Json(result); } catch (Exception e) { CommerceLog.Current.Error("Register", this, e); return Json(new BaseJsonResult("Register", e), JsonRequestBehavior.AllowGet); } }
/// <summary> /// Registers the user. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="inputModel">The input model.</param> /// <returns> /// The manager result where the user is returned as the Result. /// </returns> public virtual ManagerResponse<CreateUserResult, CommerceUser> RegisterUser([NotNull] CommerceStorefront storefront, RegisterUserInputModel inputModel) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(inputModel, "inputModel"); Assert.ArgumentNotNullOrEmpty(inputModel.UserName, "inputModel.UserName"); Assert.ArgumentNotNullOrEmpty(inputModel.Password, "inputModel.Password"); CreateUserResult result; // Attempt to register the user try { var request = new CreateUserRequest(inputModel.UserName, inputModel.Password, inputModel.UserName, storefront.ShopName); result = this.CustomerServiceProvider.CreateUser(request); if (!result.Success) { Helpers.LogSystemMessages(result.SystemMessages, result); } else if (result.Success && result.CommerceUser == null && result.SystemMessages.Count() == 0) { // 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 = StorefrontManager.GetSystemMessage("UserAlreadyExists") }); } } catch (MembershipCreateUserException e) { result = new CreateUserResult { Success = false }; result.SystemMessages.Add(new Commerce.Services.SystemMessage { Message = ErrorCodeToString(e.StatusCode) }); } return new ManagerResponse<CreateUserResult, CommerceUser>(result, result.CommerceUser); }
/// <summary> /// Registers the user. /// </summary> /// <param name="storefront">The storefront.</param> /// <param name="inputModel">The input model.</param> /// <returns> /// The manager result where the user is returned as the Result. /// </returns> public virtual ManagerResponse<CreateUserResult, CommerceUser> RegisterUser([NotNull] CommerceStorefront storefront, RegisterUserInputModel inputModel) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(inputModel, "inputModel"); Assert.ArgumentNotNullOrEmpty(inputModel.UserName, "inputModel.UserName"); Assert.ArgumentNotNullOrEmpty(inputModel.Password, "inputModel.Password"); CreateUserResult result; // Attempt to register the user try { var request = new CreateUserRequest(inputModel.UserName, inputModel.Password, inputModel.UserName, storefront.ShopName); result = this.CustomerServiceProvider.CreateUser(request); if (!result.Success) { Helpers.LogSystemMessages(result.SystemMessages, result); } } catch (MembershipCreateUserException e) { result = new CreateUserResult { Success = false }; result.SystemMessages.Add(new Commerce.Services.SystemMessage { Message = ErrorCodeToString(e.StatusCode) }); } return new ManagerResponse<CreateUserResult, CommerceUser>(result, result.CommerceUser); }