Beispiel #1
0
        public ActionResult Login(string username, string password, string rememberme)
        {
            HT_NguoiDung user = new HT_NguoiDung();

            if (string.IsNullOrEmpty(username))
            {
                ViewBag.error = "Vui lòng nhập mã người dùng";
            }
            else if (string.IsNullOrEmpty(password))
            {
                user.MaNguoiDung = username;
                ViewBag.error    = "Vui lòng nhập mật khẩu";
            }
            //else if (!IsValidRecaptcha(Request["g-recaptcha-response"]))
            //{
            //    user.MaNguoiDung = username;
            //    user.MatKhau = password;
            //    ViewBag.error = "Vui lòng xác thực không phải người máy";
            //}
            else
            {
                return(LuuTrangThaiDangNhap(username, password, rememberme));
            }
            return(View(user));
        }
Beispiel #2
0
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            string       maDV         = Session["MaDV"].ToString();
            HT_NguoiDung hT_NguoiDung = db.HT_NguoiDung.Find(id);

            if (hT_NguoiDung == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaDV    = new SelectList(db.DM_DONVI.Where(a => a.MA_DVIQLY.Contains(maDV)), "MA_DVIQLY", "TEN_DVIQLY", hT_NguoiDung.MaDV);
            ViewBag.IdNhom  = new SelectList(db.HT_Nhom.Where(a => a.MaDV == hT_NguoiDung.MaDV).OrderBy(a => a.Ten), "Id", "Ten", hT_NguoiDung.IdNhom);
            ViewBag.IdPhong = new SelectList(db.DM_PHONG.Where(a => a.MaDV == hT_NguoiDung.MaDV).OrderBy(a => a.Ten), "Id", "Ten", hT_NguoiDung.IdPhong);

            ViewBag.GioiTinh = Common.GioiTinh(hT_NguoiDung.GioiTinh);
            ViewBag.ChucVu   = new SelectList(db.HT_CHUCVU.OrderBy(a => a.Ten), "Id", "Ten", hT_NguoiDung.ChucVu);
            if (string.IsNullOrEmpty(hT_NguoiDung.AnhDaiDien))
            {
                hT_NguoiDung.AnhDaiDien = "avatar.png";
            }
            Session["avatar"]    = hT_NguoiDung.AnhDaiDien;
            hT_NguoiDung.MatKhau = "";
            return(View(hT_NguoiDung));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "oid,MaNguoiDung,MatKhau,HoTen,Email,AnhDaiDien,MaDV,IdNhom,IdPhong,GioiTinh,ChucVu,Active,BiDanh")] HT_NguoiDung hT_NguoiDung, HttpPostedFileBase photo)
        {
            string maDV = Session["MaDV"].ToString();

            ViewBag.MaDV     = new SelectList(db.DM_DONVI.Where(a => a.MA_DVIQLY.Contains(maDV)), "MA_DVIQLY", "TEN_DVIQLY");
            ViewBag.IdNhom   = new SelectList(db.HT_Nhom.Where(a => a.MaDV == maDV).OrderBy(a => a.Ten), "Id", "Ten");
            ViewBag.IdPhong  = new SelectList(db.DM_PHONG.Where(a => a.MaDV == maDV).OrderBy(a => a.Ten), "Id", "Ten");
            ViewBag.GioiTinh = Common.GioiTinh("");
            ViewBag.ChucVu   = new SelectList(db.HT_CHUCVU.OrderBy(a => a.Ten), "Id", "Ten", hT_NguoiDung.ChucVu);
            if (string.IsNullOrEmpty(hT_NguoiDung.MaNguoiDung))
            {
                TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Vui lòng điền mã người dùng</div> ";
                return(View(hT_NguoiDung));
            }
            List <HT_NguoiDung> nd = db.HT_NguoiDung.Where(a => a.MaNguoiDung == hT_NguoiDung.MaNguoiDung).ToList();

            if (nd.Count > 0)
            {
                TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Mã người dùng đã tồn tại</div> ";
                return(View(hT_NguoiDung));
            }
            if (string.IsNullOrEmpty(hT_NguoiDung.HoTen))
            {
                TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Vui lòng điền đầy đủ họ tên</div> ";
                return(View(hT_NguoiDung));
            }
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(hT_NguoiDung.MatKhau))
                {
                    TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Vui lòng nhập mật khẩu</div> ";
                    return(View(hT_NguoiDung));
                }
                hT_NguoiDung.oid     = Guid.NewGuid();
                hT_NguoiDung.MatKhau = Common.EncryptMD5(hT_NguoiDung.MatKhau);
                if (photo != null)
                {
                    var fileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                    hT_NguoiDung.AnhDaiDien = fileName;
                    UploadPhoto(fileName, photo);
                }
                else
                {
                    hT_NguoiDung.AnhDaiDien = "avatar.png";
                }
                Session["avatar"] = hT_NguoiDung.AnhDaiDien;
                db.HT_NguoiDung.Add(hT_NguoiDung);
                db.SaveChanges();
                HT_LichSuHoatDong ls = new HT_LichSuHoatDong(
                    this.ControllerContext.RouteData.Values["controller"].ToString()
                    , "CREATE"
                    , DateTime.Now, Session["username"]?.ToString()
                    , $" {this.ControllerContext.RouteData.Values["action"]?.ToString()} - {hT_NguoiDung.MaNguoiDung} ");
                db.HT_LichSuHoatDong.Add(ls);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(hT_NguoiDung));
        }
Beispiel #4
0
        public ActionResult Delete(Guid id)
        {
            HT_NguoiDung hT_NguoiDung = db.HT_NguoiDung.Find(id);

            db.HT_NguoiDung.Remove(hT_NguoiDung);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public ActionResult Login()
        {
            HT_NguoiDung nguoiDung = CheckCookie();

            if (nguoiDung != null)
            {
                //return View("Login", nguoiDung);
                return(LuuTrangThaiDangNhap(nguoiDung.MaNguoiDung, nguoiDung.MatKhau, "on"));
            }
            return(View());
        }
Beispiel #6
0
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HT_NguoiDung hT_NguoiDung = db.HT_NguoiDung.Find(id);

            hT_NguoiDung.MatKhau = Common.EncryptMD5(hT_NguoiDung.MatKhau);
            if (hT_NguoiDung == null)
            {
                return(HttpNotFound());
            }
            return(View(hT_NguoiDung));
        }
Beispiel #7
0
        public JsonResult DeletePhoto(string nguoiDung, string photoFileName)
        {
            if (photoFileName == "avatar.png")
            {
                TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Không thể xóa hình mặc định</div> ";
                return(Json("Ảnh mặc định"));
            }
            string fullPath = Request.MapPath("/Content/images/avatars/" + photoFileName);

            if (System.IO.File.Exists(fullPath))
            {
                System.IO.File.Delete(fullPath);
                HT_NguoiDung nd = db.HT_NguoiDung.Find(Guid.Parse(nguoiDung));
                nd.AnhDaiDien = "avatar.png";
                db.SaveChanges();
                Session["avatar"] = nd.AnhDaiDien;
            }
            return(Json("Deleted"));
        }
Beispiel #8
0
        public HT_NguoiDung CheckCookie()
        {
            HT_NguoiDung nguoiDung = null;
            string       userName = string.Empty, password = string.Empty;

            if (Response.Cookies["username"] != null)
            {
                userName = Request.Cookies["username"].Value;
            }
            if (Response.Cookies["password"] != null)
            {
                password = Request.Cookies["password"].Value;
            }
            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
            {
                nguoiDung = new HT_NguoiDung()
                {
                    MaNguoiDung = userName, MatKhau = password
                }
            }
            ;
            return(nguoiDung);
        }