public ActionResult CheckLogin(string username, string pwd, string remember) { //Lưu trang hiện tại để khi đăng nhập thành công có thể đến //string currenturl = AdminBaseController.strControlerCurrent; //ViewBag.Url = currenturl; NguoiDung obj = getObjByUser(username); if (obj.Id > 0) { if (obj.MatKhau.Equals(QuanTri.ToMD5(pwd))) { //Đăng nhập thành công Session.Add(ConstantData.USER_SESSION, obj); if (Convert.ToBoolean(remember)) { HttpCookie cookie = new HttpCookie(ConstantData.USER_COOKIES); cookie[ConstantData.USERNAME_COOKIES] = obj.TenDangNhap; cookie[ConstantData.PASSWORD_COOKIES] = pwd; cookie.Expires = DateTime.Now.AddDays(100); Response.Cookies.Add(cookie); } //Lưu nhật kí hệ thống QuanTri.SaveLog("Người dùng " + username + " đã đăng nhập", "Đăng nhập", (int)CommonAdmin.ConstantCommon.Action.Login); return(Json(new { error = false, message = "Đăng nhập thành công" })); } return(Json(new { error = true, message = "Mật khẩu không chính xác" })); } return(Json(new { error = true, message = "Tài khoản không chính xác" })); }
public JsonResult DoiMatKhau(string pwdhientai, string pwd1) { var objuser = (NguoiDung)Session[CommonAdmin.ConstantData.USER_SESSION]; if (objuser.MatKhau.Equals(QuanTri.ToMD5(pwdhientai))) { NguoiDung obj = DataProvider.Entities.NguoiDungs.Find(objuser.Id); obj.MatKhau = QuanTri.ToMD5(pwd1); DataProvider.Entities.SaveChanges(); return(Json(new JsonPostBack("Đổi mật khẩu thành công", true), JsonRequestBehavior.AllowGet)); } return(Json(new JsonPostBack("Mật khẩu hiện tại không chính xác", false), JsonRequestBehavior.AllowGet)); }
public JsonResult Add() { try { int id = int.Parse(Request["isInsert"]); string username = Request["username"]; string pwd = Request["pwd"]; string emdil = Request["email"]; string sdt = Request["sdt"]; string diaChi = Request["diachi"]; int gate = 0; if (!string.IsNullOrEmpty(Request["gate"])) { gate = Convert.ToInt32(Request["gate"]); } int vaitroud = 0; if (!string.IsNullOrEmpty(Request["vaitroid"])) { vaitroud = Convert.ToInt32(Request["vaitroid"]); } string name = Request["name"]; if (id < 0) //Add { if (getObjByUser(username).Id > 0) //Nếu tài khoản đã tồn tại { return(Json(new JsonPostBack("Tên tài khoản đã tồn tại. Vui lòng nhập tên tài khoản khác", false), JsonRequestBehavior.AllowGet)); } NguoiDung obj = new NguoiDung(); obj.TenDangNhap = username; obj.NgayTao = DateTime.Now; obj.MatKhau = QuanTri.ToMD5(pwd); obj.Email = emdil; obj.DienThoai = sdt; obj.DiaChi = diaChi; obj.VaiTroId = vaitroud; obj.HoTen = name; DataProvider.Entities.NguoiDungs.Add(obj); DataProvider.Entities.SaveChanges(); return(Json(new JsonPostBack("Thêm mới thành công", true), JsonRequestBehavior.AllowGet)); } else //Edit { NguoiDung obj = DataProvider.Entities.NguoiDungs.Find(id); if (obj.Id > 0) { //Nếu tên tài khoản thay đổi if (obj.TenDangNhap != username) { //if username đã tồn tại => Erorr if (getObjByUser(username).Id > 0) { return(Json(new JsonPostBack("Tên tài khoản đã tồn tại. Vui lòng nhập tên tài khoản khác", false), JsonRequestBehavior.AllowGet)); } else { //Kiểm tra nếu mật khẩu thay đổi thì mã hóa md5 if (!(string.Compare(pwd, "Coder!(((23") == 0)) { obj.MatKhau = QuanTri.ToMD5(pwd); } obj.TenDangNhap = username; obj.Email = emdil; obj.DienThoai = sdt; obj.DiaChi = diaChi; obj.VaiTroId = vaitroud; obj.HoTen = name; DataProvider.Entities.SaveChanges(); return(Json(new JsonPostBack("Cập nhật thành công", true), JsonRequestBehavior.AllowGet)); } } else //Tài khoản không đổi { if (!(string.Compare(pwd, "Coder!(((23") == 0)) { obj.MatKhau = QuanTri.ToMD5(pwd); } obj.TenDangNhap = username; obj.Email = emdil; obj.DienThoai = sdt; obj.DiaChi = diaChi; obj.VaiTroId = vaitroud; obj.HoTen = name; DataProvider.Entities.SaveChanges(); return(Json(new JsonPostBack("Cập nhật thành công", true), JsonRequestBehavior.AllowGet)); } } else { return(Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý", false), JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { return(Json(new JsonPostBack("Xảy ra lỗi trong quá trình xử lý. Chi tiết: " + ex.Message, false), JsonRequestBehavior.AllowGet)); } }