public ActionResult Login(LoginModel model) { int responseCode = 0; var hashPassword = Helper.Commons.MD5Hash(model.Password); var result = dataAccess.LoginHome(model.UserName, hashPassword); if (result == 1) // dang nhap thanh cong { var userInfo = dataAccess.GetUserInfoLogging(model.UserName); var userSession = new UserLoginModel(); userSession.Username = userInfo.Username; userSession.UserID = userInfo.User_ID; userSession.Email = userInfo.Email; userSession.Department = userInfo.DEPARTMENT.Dep_Name; userSession.Role = userInfo.ROLE.Role_Name; userSession.RoleID = userInfo.ROLE.Role_ID; userSession.Department_ID = userInfo.DEPARTMENT.Dep_ID; Session.Add(Helper.Commons.USER_SEESION, userSession); //return RedirectToAction("Index", "Home"); responseCode = 1; } else if (result == -1) { //ModelState.AddModelError("", "Username / Password is not correct"); responseCode = -1; } else if (result == -3) { //ModelState.AddModelError("", "Account dose not access to page. Not permission."); responseCode = -3; } else if (result == 0) { //ModelState.AddModelError("", "Account not exists!"); responseCode = 0; } else { //ModelState.AddModelError("", "Loggin not success! System error."); responseCode = -2; } return(Json(responseCode, JsonRequestBehavior.AllowGet)); }
public ActionResult LoginAdmin(LoginModel model) { int responseCode = 0; var hashPassword = Helper.Commons.MD5Hash(model.Password); var result = dataAccess.LoginAdmin(model.UserName, hashPassword); if (result == 1) // dang nhap thanh cong { var userInfo = dataAccess.GetUserInfoLogging(model.UserName); var userSession = new UserLoginModel(); userSession.Username = userInfo.Username; userSession.UserID = userInfo.User_ID; userSession.Email = userInfo.Email; userSession.Department = userInfo.DEPARTMENT.Dep_Name; userSession.Role = userInfo.ROLE.Role_Name; userSession.Department_ID = userInfo.DEPARTMENT.Dep_ID; Session.Add(Helper.Commons.USER_SEESION_ADMIN, userSession); responseCode = 1; } else if (result == -1) { responseCode = -1; } else if (result == -3) { responseCode = -3; } else if (result == 0) { responseCode = 0; } else { responseCode = -2; } return(Json(responseCode, JsonRequestBehavior.AllowGet)); }