public IActionResult Login(UserModel user) { if (user.fUsername != null && user.fPassword != null) { UserDBModel db = new UserDBModel(); UserModel luser = db.UserLogin(user.fUsername, user.fPassword); if (luser.fUsername != null) { Response.Cookies.Append("user", luser.fUsername); Response.Cookies.Append("userID", luser.fID); if (db.AdminChecking(luser.fUsername, luser.fPassword)) { string id = luser.fID; return(Redirect(@"../Admin/Index/?id=" + id)); } return(Redirect("../Home/Index/?id=" + luser.fID)); } else { ModelState.AddModelError("", "Wrong username or password"); } } else { ModelState.AddModelError("", "should not empty username or password"); } return(RedirectToAction("../User/Login/")); }
public void LoginTest() { UserDBModel db = new UserDBModel(); string email = "*****@*****.**"; string password = "******"; UserModel um = db.UserLogin(email, password); Assert.AreEqual(um.fUsername, email); Assert.AreEqual(um.fPassword, password); }