public ActionResult A_Login(A_LoginViewModel alogin) { var result = db.Admins.Where(x => x.AID == alogin.AID && x.APassword == alogin.APassword).FirstOrDefault(); //驗證 if (result != null) //資料庫有資料(這個人) { //授權 // 建立使用者的登入資訊 ClaimsIdentity identity = new ClaimsIdentity(new[] { //加入使用者的相關資訊 new Claim(ClaimTypes.Name, result.AName), new Claim("AID", result.AID) }, "Cookies"); Request.GetOwinContext().Authentication.SignIn(identity); //授權(登入) return(RedirectToAction("Home_A", "Admins")); } else { ModelState.AddModelError("", "輸入的帳密可能有誤或是沒有註冊"); return(RedirectToAction("A_Login", "Home")); } }
public ActionResult Login(A_LoginViewModel LVM) { string pass = new Helpers().Encryption(LVM.PassWord); UserRepository LI = new UserRepository(); if (LI.Login(LVM.Email, pass)) { //var s = LI.GetAdminId(UName).ToString(); Session["UserId"] = "Admin"; return(RedirectToAction("Index")); } else { ViewBag.message = "نام کاربری یا رمز اشتباه است"; return(View()); } }