public ActionResult Registration(RegisterModel regModel) { bool anyUser = userService.IsUserExist(regModel.ToBllUser()); if (anyUser) { ModelState.AddModelError("", "User with this address already registered."); return View(regModel); } if (ModelState.IsValid) { var membershipUser = ((GalleryMembershipProvider)Membership.Provider) .CreateUser(regModel.Login, regModel.Password, regModel.Email, regModel.FirstName, regModel.LastName, regModel.BirthDate); if (membershipUser != null) { FormsAuthentication.SetAuthCookie(regModel.Login, false); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Error registration."); } } return View(regModel); }
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 Register(RegisterModel model) { if (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 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 (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) { BindCountry(); if (ModelState.IsValid) { // Attempt to register the user try { string result = WebSecurity.CreateUserAndAccount(model.Email, model.Password, new { FirstName = model.FirstName, LastName = model.LastName, Country = model.Country, City = model.City, Gender = model.Gender, DOB = model.DOB, Nationality = model.Nationality }, true); Roles.AddUserToRole(model.Email, "User"); //Send Email string body = string.Empty; using ( StreamReader reader = new StreamReader(Server.MapPath("~/content/template/AccountConfirmationTemplate.html"))) { body = reader.ReadToEnd(); } body = body.Replace("{NAME}", model.FirstName + ' ' + model.LastName); body = body.Replace("{HREF}", Request.Url.Host + "/Account/Verify?cid=" + result); Notifications.Send(model.Email, "", "", "Registration Confirmation", body, true); return RedirectToAction("Confirmation", "Account"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } else { ModelState.AddModelError("", "Error submitting data."); } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Intento de registrar al usuario 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)); } } // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario ViewData["PasswordLength"] = MembershipService.MinPasswordLength; return View(model); }