public ActionResult SignUp(SignupUser model) { if (ModelState.IsValid) { var anyUser = _userRepository.GetAll().Any(p => p.Email.Equals(model.Email)); if (anyUser) { return View(); } Regex rgx = new Regex("^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$"); if (!rgx.IsMatch(model.Email)) { return View(); } anyUser = _userRepository.GetAll().Any(p => p.FullName.Equals(model.FullName)); if (anyUser) { return View(); } if (!model.Password.Equals(model.ConfirmPassword)) { return View(); } using (MD5 md5Hash = MD5.Create()) { string hash_pass = CryptMD5.GetMd5Hash(md5Hash, model.Password); _userRepository.Insert(new User { FullName = model.FullName, Email = model.Email, Password = hash_pass }); _userRepository.SaveChanges(); } LoginUser login = new LoginUser() { Email = model.Email, Password = model.Password, RememberMe = true }; Login(login, ""); } return View(); }
public ActionResult Login(LoginUser model, string returnUrl) { if (ModelState.IsValid) { var user = _investContext.Auth.Login(model.Email, model.Password, model.RememberMe); if (user != null) { if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "Имя пользователя или пароль является не корректным."); } } return View(model); }