public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { using (this._context) { var salt = _saltGenerator.GenerateSaltValue(24); var password = _passwordSalter.SaltPassword(model.Password, salt); var user = new User { Email = model.Email, Password = password, Salt = salt }; this._context.Users.Add(user); this._context.SaveChanges(); var loginModel = new LoginModel { Password = model.Password, UserName = model.Email }; return Login(loginModel, "/"); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult SignUp(SignUpUser model) { try { if (this.TryValidateModel(model)) { if (model.ConfirmPassword == model.Password) { Models.User user = new User() { Email = model.Email, PasswordHash = this.PasswordHashProvider.CreateHash(model.Password) }; if (this.UserRepository.GetUser(user.Email) == null) { this.UserRepository.Save(user); this.AuthentificationService.SignIn(user.Email, model.Password, false); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError(String.Empty, Models.UserResources.EmailHasBeenTaken); } } else { ModelState.AddModelError(String.Empty, Models.UserResources.PasswordsMustMatch); } } } catch (Exception e) { Log.Error(e, "Error in SignUp"); ModelState.AddModelError(String.Empty, Models.UserResources.CommonRegistrationError); } return View("SignUp"); }