public ActionResult Register(RegisterViewModel user) { //if (user.ConfirmPassword != user.Password) // ModelState.AddModelError("", "Passwords are not equal."); if (repository.Customers.Any(x=>x.EmailAddress == user.UserName)) ModelState.AddModelError("UserName", "User with such e-mail already exist."); if (ModelState.IsValid) { if (AddUser(user)) { return RedirectToAction("LogOn"); } ModelState.AddModelError("", "Error saving new user."); } return View(user); }
private bool AddUser(RegisterViewModel user) { Customer newuser = new Customer(); newuser.FirstName = user.FirstName; newuser.LastName = user.LastName; newuser.EmailAddress = user.UserName; var pass = StringUtils.getSaltHash(user.Password); newuser.PasswordHash = pass.SingleOrDefault(x => x.Key == "hash").Value; newuser.PasswordSalt = pass.SingleOrDefault(x => x.Key == "salt").Value; newuser.NameStyle = false; try { repository.Save(newuser); return true; } catch (Exception ex) { return false; } }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action( "ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Подтверждение учетной записи", "Ваш Ник: " + model.UserName + "<br/>" + "Ваш пароль: " + model.Password + "<br/><hr/>" + "Подтвердите вашу учетную запись, щелкнув <a href=\"" + callbackUrl + "\">здесь</a><br/>" + "Или скопируйте в браузер эту ссылку: " + callbackUrl); return View("DisplayEmail"); } AddErrors(result); } // Появление этого сообщения означает наличие ошибки; повторное отображение формы return View(model); }