// GET: DangNhap public ActionResult Index() { HttpCookie ck_tentaikhoan = Request.Cookies.Get("Tentaikhoan"); HttpCookie ck_matkhau = Request.Cookies.Get("Matkhau"); HttpCookie ck_luumatkhau = Request.Cookies.Get("LuuMatkhau"); if (ck_luumatkhau == null) { HttpCookie LuuMatkhau = RemmemberMe.CreateCookie("LuuMatkhau", "false"); Response.Cookies.Add(LuuMatkhau); ck_luumatkhau = Request.Cookies.Get("LuuMatkhau"); } TaikhoanModel target = new TaikhoanModel(); if (ck_luumatkhau.Value == "false") { HttpCookie Tentaikhoan = RemmemberMe.CreateCookie("Tentaikhoan", ""); Request.Cookies.Add(Tentaikhoan); HttpCookie Matkhau = RemmemberMe.CreateCookie("Matkhau", ""); Request.Cookies.Add(Matkhau); HttpCookie LuuMatkhau = RemmemberMe.CreateCookie("LuuMatkhau", ""); Request.Cookies.Add(LuuMatkhau); target.UserName = ""; target.Password = ""; target.RememberMe = false; } else { target.UserName = ck_tentaikhoan.Value; target.Password = ck_matkhau.Value; target.RememberMe = true; } return(View(target)); }
public ActionResult Index(TaikhoanModel collection) { if (ModelState.IsValid) { var dao = new TaiKhoanDao(); var res = dao.login(collection.UserName, Encryptor.Encrypt(collection.Password, collection.UserName)); if (res == 1) { if (collection.RememberMe) { HttpCookie Tentaikhoan = RemmemberMe.CreateCookie("Tentaikhoan", collection.UserName); Response.Cookies.Add(Tentaikhoan); HttpCookie Matkhau = RemmemberMe.CreateCookie("Matkhau", collection.Password); Response.Cookies.Add(Matkhau); HttpCookie LuuMatkhau = RemmemberMe.CreateCookie("LuuMatkhau", "true"); Response.Cookies.Add(LuuMatkhau); } else { HttpCookie LuuMatkhau = RemmemberMe.CreateCookie("LuuMatkhau", "false"); Response.Cookies.Add(LuuMatkhau); } var user = dao.GetById(collection.UserName); var usersession = new TaiKhoanLogin(); usersession.UserName = user.Tentaikhoan; Session.Add(CommonConstants.USER_SESSION, usersession); return(RedirectToAction("Index", "Admin/Home")); } else if (res == -1) { ModelState.AddModelError("", "Tên đăng nhập không tồn tại"); } else if (res == 0) { ModelState.AddModelError("", "Mật khẩu không đúng"); } else if (res == 2) { ModelState.AddModelError("", "Tài khoản đã bị khóa"); } } return(View(collection)); }
public ActionResult Create(TaikhoanModel model) { if (ModelState.IsValid) { var KT = new TaiKhoanFunction(); if (KT.CheckUsername(model.username)) { ModelState.AddModelError("", "Tài khoản đã tồn tại"); } else if (KT.CheckMail(model.mail)) { ModelState.AddModelError("", "Email đã tồn tại"); } else { var user = new TheThuVien(); user.username = model.username; user.password = model.password; user.tentk = model.tentk; user.sdt = model.phone; user.diachi = model.diachi; user.mail = model.mail; user.Ngaytaothe = DateTime.Now; user.Trangthai = true; user.Ngayhethan = DateTime.Now.AddYears(2); var result = KT.Insert(user); if (result > 0) { ViewBag.Success = "Đăng kí thành công !!!"; model = new TaikhoanModel(); } else { ModelState.AddModelError("", "Đăng kí không thành công"); } } } return(View(model)); }
public TaikhoanController() { tk = new TaikhoanModel(); }