public ActionResult Login(FormCollection f, string returnUrl) { // if (ModelState.IsValid) // { // using (KLShopEntities7 entities = new KLShopEntities7()) // { string username = f["user"]; string password = f["pass"]; // svuser.Login(username, password); // bool userValid = entities.Users.Any(user => user.IDUser == username && user.PassUser == password); // User tìm trong database //---------------------------------------- bool userVaild = svuser.Login(username, password); if (userVaild) { Session["User"] = username; /* User usr = db.Users.First(p => p.IDUser.Trim() == username); * string quye = usr.Quyen.Value.ToString(); * * System.Web.HttpContext.Current.Session["Quyen"] = quye;*/ // quyen1 = Session["User"].ToString(); // var sanpham = (from p in db.Users where p.IDUser.StartsWith(username) select p).ToList(); FormsAuthentication.SetAuthCookie(username, true); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { ViewBag.Err = "<script language=javascript>alert('Sai thông tin đăng nhập!');</script>"; return(RedirectToAction("Index", "SanPham")); } } else { ViewBag.Error = "<script language=javascript>alert('Tên đăng nhập hoặc mật khẩu không đúng');</script>"; ViewBag.Err = "<script language=javascript>alert('Sai thông tin đăng nhập!');</script>"; return(RedirectToAction("Index", "SanPham")); } //------------------------------------------- // } // } return(RedirectToAction("Index", "SanPham")); // return View(f); }
public bool Login(bool isAdmin, string username, string password) { try { return(serviceUser.Login(isAdmin, username, password)); } catch { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Connection Error! Database Server Manager Unreacheable!"); Console.ForegroundColor = ConsoleColor.DarkCyan; } return(false); }