public ActionResult Login(User user) { var returnUrl = TempData["ReturnUrl"]; if (ModelState.IsValid) { if (UserManagement.IsValid(user.Username, user.Password)) { var validUser = UserManagement.GetValidUserList().Single(x => x.UserName == user.Username); FormsAuthentication.SetAuthCookie(user.Username, user.RememberMe); Session["User"] = new UserLoginDto { Username = user.Username, Id = validUser.Id, IsAdmin = validUser.IsAdmin}; if (validUser.IsAdmin) { return RedirectToAction("Dashboard", "Admin"); } if (returnUrl != null && !string.IsNullOrEmpty(returnUrl.ToString())) { return Redirect(returnUrl.ToString()); } return RedirectToAction("ProductView", "Product"); } if (!UserManagement.IsValidUsername(user.Username)) { ModelState.AddModelError("Username", "This username cannot be found."); } else { ModelState.AddModelError("Password", "Password is incorrect!"); } TempData["ReturnUrl"] = returnUrl; } return View(user); }
public ActionResult Login(User user) { if (ModelState.IsValid) { if (UserManagement.isValid(user.Username, user.Password)) { if (UserManagement.IsAdmin(user.Username, user.Password)) { FormsAuthentication.SetAuthCookie(user.Username, user.RememberMe); Session["User"] = new UserLoginDTO { Username = user.Username }; return RedirectToAction("AdminPage", "User"); } FormsAuthentication.SetAuthCookie(user.Username, user.RememberMe); Session["User"] = new UserLoginDTO { Username = user.Username }; return RedirectToAction("CustomerPage", "User"); } ModelState.AddModelError("General", "Password is incorrect!"); } return View(user); }