public ActionResult Register(RegisterModel model) { try { string captchaKey = ConfigurationManager.AppSettings["ReCaptchaPrivateKey"]; if (ReCaptcha.Validate(privateKey: captchaKey)) { if (ModelState.IsValid) { MembershipCreateStatus createStatus = BizMgr.CreateUser(model.City, model.Email, model.FirstName, model.LastName, model.Password, model.RegionID); if (createStatus == MembershipCreateStatus.Success) { model.SuccessMessage = string.Format(BizMgr.ReadResourceValue("Email", "RegistrationSuccessMessage"), model.Email); model.City = string.Empty; model.ConfirmPassword = string.Empty; model.Email = string.Empty; model.FirstName = string.Empty; model.LastName = string.Empty; model.Password = string.Empty; } else { ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); ViewBag.PasswordFormat = AccountValidation.PasswordFormatMessage; } } } else { ModelState.AddModelError("Captcha", "You did not enter the Captcha values correctly. Please try again."); ViewBag.PasswordFormat = AccountValidation.PasswordFormatMessage; } } catch (Exception ex) { LogController.LogError(ex, LogEntryType.NormalError, "", "", "", "Email=" + model.Email); } model.Regions = GetRegions(0); return View(model); }
// ************************************** // URL: /Account/Register // ************************************** public ActionResult Register() { RegisterModel rg = new RegisterModel(); rg.Regions = GetRegions(0); rg.RegionID = 0; return View(rg); }
public void Register_Post_ReturnsViewIfModelStateIsInvalid() { // Arrange AccountController controller = GetAccountController(); RegisterModel model = new RegisterModel() { LastName = "someUser", 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.ViewBag.PasswordLength"]); }
public void Register_Post_ReturnsViewIfRegistrationFails() { // Arrange AccountController controller = GetAccountController(); RegisterModel model = new RegisterModel() { LastName = "duplicateUser", 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.ViewBag.PasswordLength"]); }
public void Register_Post_ReturnsRedirectOnSuccess() { // Arrange AccountController controller = GetAccountController(); RegisterModel model = new RegisterModel() { LastName = "someUser", 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"]); }