public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var dao = new AccountDao(); var result = dao.Login(model.UserName, Encryptor.MD5Hash(model.Password)); if (result == 1) { var user = dao.GetByMaTK(model.UserName); var userSession = new UserLogin(); userSession.MaTK = user.MaTK; userSession.UserName = user.UserName; Session.Add(CommonConstants.USER_SESSION, userSession); return(RedirectToAction("Index", "User")); } else if (result == -1) { ModelState.AddModelError("", "Tài Khoản Đã Bị Khóa"); } else if (result == -2) { ModelState.AddModelError("", "Sai Mật Khẩu"); } else { ModelState.AddModelError("", "Tài Khoản Không Tồn Tại"); } } return(View("Index")); }
public ActionResult Create(Account model) { if (ModelState.IsValid) { var dao = new AccountDao(); //kiem tra nguoi dung ton tai //true neu ton tai , tra ve lai trang Create if (dao.GetByMaTK(model.UserName) != null) { SetAlert("ten nguoi dung ton tai moi nhap ten khac", "warning"); return(RedirectToAction("Create", "User")); } else { //kiem tra pass rong // true neu pass k rong if (!string.IsNullOrEmpty(model.Password)) { var md5 = Encrypt.Encryptor.MD5Hash(model.Password); model.Password = md5; var result = new AccountDao().Create(model); if (result) { SetAlert("tao tai khoan thanh cong", "success"); } else { SetAlert("Da co loi xay ra", "error"); } } else { SetAlert("ban chua nhap password", "error"); return(RedirectToAction("Create", "User")); } return(RedirectToAction("Index")); } } return(View()); }