public ActionResult Register(RegisterModel model, bool captchaValid) { if (!captchaValid) ModelState.AddModelError("", "The captcha provided is incorrect."); string[] bannedEmailDomains = ConfigurationManager.AppSettings["EmailVerifyBannedDomains"].Split(','); if (bannedEmailDomains.Any(d => model.Email.EndsWith(d))) ModelState.AddModelError("", "We are having a problem sending e-mail to your e-mail provider. Many free e-mail services are insufficient to receive the OklahomaFurs.com account verification e-mail. Please try using an alternate e-mail address."); IPHostEntry entry; try { entry = Dns.GetHostEntry(model.Email.Split('@')[1]); if (entry == null || entry.AddressList == null || entry.AddressList.Length == 0) ModelState.AddModelError("", "We are having a problem sending e-mail to your e-mail provider. Are you sure you provided a valid e-mail address?"); } catch (Exception) { ModelState.AddModelError("", "We are having a problem sending e-mail to your e-mail provider. Are you sure you provided a valid e-mail address?"); } if (ModelState.IsValid) { bool goOn = true; if (!(!string.IsNullOrWhiteSpace(model.UserName) && Regex.IsMatch(model.UserName, "^[A-Za-z0-9']{4,20}$"))) { ModelState.AddModelError("", "The username must contain only alphanumeric characters and be between 4 and 20 characters."); goOn = false; } DateTime? birthDate = null; if (!string.IsNullOrEmpty(model.BirthDate)) { DateTime bd; if (!DateTime.TryParse(model.BirthDate, out bd)) { ModelState.AddModelError("", "Invalid birth date format"); goOn = false; } else { birthDate = new DateTime?(bd); } } MembershipCreateStatus createStatus = MembershipCreateStatus.ProviderError; if (goOn) { createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email, model.SecurityQuestion, model.SecurityAnswer, birthDate, model.FirstName, model.MiddleName, model.LastName, model.HomePhone, model.MobilePhone, model.Address1, model.Address2, model.Address3, model.City, model.State, model.ZipCode, model.Country); } if (createStatus == MembershipCreateStatus.Success) { User user = Context.Users.Where(a => a.Name == model.UserName).Single(); SendVerificationEmail(user); return View("AwaitingEmailVerification", null, model.Email); } ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus)); } ViewData["PasswordLength"] = MembershipService.MinPasswordLength; return View("Register", model); }
// ************************************** // URL: /Account/Register // ************************************** public ActionResult Register() { ViewData["PasswordLength"] = MembershipService.MinPasswordLength; var model = new RegisterModel(); return View("Register", model); }