public ActionResult Login(LoginViewModel viewModel) { user = db.Users.FirstOrDefault(u => u.Email == viewModel.Username && u.Password == viewModel.Password); if (user != null) { FormsAuthentication.SetAuthCookie(viewModel.Username, true); return(RedirectToAction("Index", "Home")); } else { return(View(viewModel)); } }
public ActionResult Login(LoginViewModel viewModel) { if (ModelState.IsValid) { using (CryptowalletDbContext ctx = new CryptowalletDbContext()) { CryptowalletDb.Domain.User user = ctx.Users.FirstOrDefault(u => u.Email == viewModel.Username && u.Password == viewModel.Password); if (user != null) { FormsAuthentication.SetAuthCookie(viewModel.Username, true); return(RedirectToAction("Profil", "BankAccounts")); } else { ModelState.AddModelError("", "Incorrect user or password"); return(View(viewModel)); } } } else { return(View(viewModel)); } }