public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { if (this.userRepo.Exists(model.Username)) { ModelState.AddModelError( string.Empty, "User name already exists. Please enter a different user name."); } // Attempt to register the user var user = this.userRepo.Create(model.Username, model.Password, model.EmailAddress); if (this.features.RequireActivation) { // Send email validation message. var activation = this.accountActivationService.BeginActivation(user); this.accountMailer().ActivationEmail(user, activation).Deliver(); return this.RedirectToAction("AwaitingAccountActivation", new { username = model.Username }); } user.Activate(); FormsAuthentication.SetAuthCookie(model.Username, false); return this.RedirectToAction("Index", "Home"); } // If we got this far, something failed, redisplay form return this.View(model); }