public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { // Add the user to the MySQL DB Person newUser = new Person(model.FirstName, model.LastName, model.Email, model.Password); DBAccessor dba = new DBAccessor(); dba.AddNewUser(newUser); // Set the appropriate cookies FormsAuthentication.SetAuthCookie(model.Email, false /* createPersistentCookie */); HttpCookie cookie = new HttpCookie(AppConstants.COOKIE_NAME, model.FirstName + " " + model.LastName); cookie.Expires = DateTime.Now.AddDays(1000); this.ControllerContext.HttpContext.Response.Cookies.Add(cookie); if (model.ReturnTo == null) { return RedirectToAction("Index", "Home"); } else { return Redirect(model.ReturnTo); } } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }
// // GET: /Account/Register public ActionResult Register() { String returnTo = Request.QueryString["returnTo"]; RegisterModel model = new RegisterModel(); model.ReturnTo = returnTo; return View(); }