public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // 尝试注册用户 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)); } } // 如果我们进行到这一步时某个地方出错,则重新显示表单 return View(model); }
public ActionResult Register(RegisterModel model) { if (this.ModelState.IsValid) { var newEmail = model.Email.Replace('.', '~'); var response = MvcApp.HttpRequest.GetHttpRequest("jsonRegister/" + model.UserName + "-" + model.Password + "-" + newEmail); var createStatus = JsonConvert.DeserializeAnonymousType(response, new { JsonRegisterNewUserResult = "" }); bool status; Boolean.TryParse(createStatus.JsonRegisterNewUserResult, out status); if (status) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return this.RedirectToAction("Index", "Home"); } string message = createStatus.JsonRegisterNewUserResult == "Nickname" ? "Користувач з таким іменем вже зареєстрований." : "Користувач з такою скринькою вже зареєстрований"; this.ModelState.AddModelError("", message); } return this.View(model); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Попытка зарегистрировать пользователя 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)); } } // Появление этого сообщения означает наличие ошибки; повторное отображение формы 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 ViewData["PasswordLength"] = MembershipService.MinPasswordLength; return View(model); }
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 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) { 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 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 (this.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 this.RedirectToAction("Index", "Home"); } else { this.ModelState.AddModelError(string.Empty, ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }