public void Register_Post_ReturnsViewIfRegistrationFails() { // Arrange AccountController controller = GetAccountController(); RegisterModel model = new RegisterModel() { UserName = "******", Email = "goodEmail", Password = "******", ConfirmPassword = "******" }; // Act ActionResult result = controller.Register(model); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); ViewResult viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual("Username already exists. Please enter a different user name.", controller.ModelState[""].Errors[0].ErrorMessage); Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
public void Register_Post_ReturnsRedirectOnSuccess() { // Arrange AccountController controller = GetAccountController(); RegisterModel model = new RegisterModel() { UserName = "******", Email = "goodEmail", Password = "******", ConfirmPassword = "******" }; // Act ActionResult result = controller.Register(model); // Assert Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("Home", redirectResult.RouteValues["controller"]); Assert.AreEqual("Index", redirectResult.RouteValues["action"]); }
public void Register_Post_ReturnsViewIfModelStateIsInvalid() { // Arrange AccountController controller = GetAccountController(); RegisterModel model = new RegisterModel() { UserName = "******", Email = "goodEmail", Password = "******", ConfirmPassword = "******" }; controller.ModelState.AddModelError("", "Dummy error message."); // Act ActionResult result = controller.Register(model); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); ViewResult viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); }
public ActionResult JsonRegister(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); return Json(new { success = true }); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed return Json(new { errors = GetErrorsFromModelState() }); }
public ActionResult Register(RegisterModel model) { string message = ""; if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus); //if the registration process was successful, //add the newly registered user to your Customers and subscribe him to the Selected Plan if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); try { //get your Site data through Billing Gateway var mySite = _dynabicBillingGateway.Sites.GetSiteBySubdomain(Config.MySiteSubdomain); //get the selected plan var selectedPlan = _dynabicBillingGateway.Products.GetProductById(model.Plans.SelectedPlan.ToString()); //generate a random Customer Reference Id //CustomerReferenceId does not permit the usage of any other special characters except "-" and //it isn't allowed to begin or end with this character nor it can be consecutive Random r = new Random(); long value = (long)((r.NextDouble() * 2.0 - 1.0) * long.MaxValue); string newCustomerReferenceId = string.Format("{0}-{1}", mySite.Id, Math.Abs(value)); //create a new CustomerRequest CustomerRequest newCustomer = new CustomerRequest() { //this fields are required FirstName = model.UserName, LastName = model.UserName, Email = model.Email, ReferenceId = newCustomerReferenceId }; //create a new Subscription Request SubscriptionRequest newSubscription = new SubscriptionRequest() { Customer = newCustomer, ProductId = selectedPlan.Id, ProductPricingPlanId = selectedPlan.PricingPlans[0].Id, }; //if the Credit Card is required at Signup //create a new Credit Card Request and add it to your Subscription //isCreditCardAtSignupRequired may be "No", "Yes", "YesOptional" if (selectedPlan.isCreditCardAtSignupRequired != BoolOptional.No) { CreditCardRequest newCreditCard = new CreditCardRequest() { Cvv = model.CreditCard.Cvv, ExpirationDate = model.CreditCard.ExpirationDate, FirstNameOnCard = model.CreditCard.FirstNameOnCard, LastNameOnCard = model.CreditCard.LastNameOnCard, Number = model.CreditCard.Number }; newSubscription.CreditCard = newCreditCard; } //if the Billing Address is required at Signup //create a new Billing Address Request and add it to your Subscription //isBillingAddressAtSignupRequired may be "No", "Yes", "YesOptional" if (selectedPlan.isBillingAddressAtSignupRequired != BoolOptional.No) { AddressRequest billingAddress = new AddressRequest() { Address1 = model.BillingAddress.BillingAddress1, City = model.BillingAddress.BillingCity, Country = model.BillingAddress.BillingCountry, StateProvince = model.BillingAddress.BillingProvince, ZipPostalCode = model.BillingAddress.BillingZipPostalCode, FirstName = model.BillingAddress.BillingFirstName, LastName = model.BillingAddress.BillingLastName }; newSubscription.BillingAddress = billingAddress; } //subscribe the newly created Customer to selected Plan _dynabicBillingGateway.Subscription.AddSubscription(mySite.Subdomain, newSubscription); //create a User Profile and save some data that we may need later ProfileCommon profile = ProfileCommon.GetUserProfile(model.UserName); profile.CurrentPlanId = model.Plans.SelectedPlan; profile.CustomerReferenceId = newCustomerReferenceId; //redirect to Home page return RedirectToAction("Index", "Home"); } catch (Exception) { message = "Something went wrong. Please try again later."; } } else { message = ErrorCodeToString(createStatus); } } //provide an error message in case something went wrong model.PageMessage = new PageMessageModel { Type = PageMessageModel.MessageType.Error, Message = message }; model.Plans.MyPlans = model.Plans.GetAllPlans(_dynabicBillingGateway); // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email); if (createStatus == MembershipCreateStatus.Success) { FormsService.SignIn(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form ViewBag.PasswordLength = MembershipService.MinPasswordLength; return View(model); }
public ActionResult Register() { RegisterModel model = new RegisterModel(_dynabicBillingGateway); model.CreditCard.ExpirationDate = DateTime.Now; model.PageMessage = TempData["PageMessage"] as PageMessageModel ?? new PageMessageModel(); return View(model); // return ContextDependentView(); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Intento de registrar al usuario MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email); if (createStatus == MembershipCreateStatus.Success) { FormsService.SignIn(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); } } // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario ViewData["PasswordLength"] = MembershipService.MinPasswordLength; return View(model); }
public ActionResult JsonRegister(RegisterModel model, string returnUrl) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); InitiateDatabaseForNewUser(model.UserName); FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false); return Json(new { success = true, redirect = returnUrl }); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed return Json(new { errors = GetErrorsFromModelState() }); }
public void Register_Post_ReturnsViewIfRegistrationFails() { // Disponer AccountController controller = GetAccountController(); RegisterModel model = new RegisterModel() { UserName = "******", Email = "goodEmail", Password = "******", ConfirmPassword = "******" }; // Actuar ActionResult result = controller.Register(model); // Declarar Assert.IsInstanceOfType(result, typeof(ViewResult)); ViewResult viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual("The user name does already exist, please try another user name.", controller.ModelState[""].Errors[0].ErrorMessage); Assert.AreEqual(10, viewResult.ViewData["PasswordLength"]); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { try { // _users.Add(UserFactory.Create(model.UserName, model.FirstName, model.LastName, model.Sex)); WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); var user = _users.GetByName(model.UserName); if (user != null) { TempData["userId"] = user.Id; return RedirectToAction("Index", "Home"); } } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // Появление этого сообщения означает наличие ошибки; повторное отображение формы return View(model); }