Ejemplo n.º 1
0
        public ActionResult ChangePass(user usr, FormCollection c)
        {
            ViewBag.Message = null;
            ViewBag.Error = null;
            if (ModelState.IsValid)
            {
                string ID = usr.email;
                string PASS = usr.secret;
                string oldsecret = GetMd5Hash(ID + c["oldpass"]);
                string abc = db.users.Where(x => x.email == ID).Select(y => y.mat_khau).First();

                if (oldsecret == abc)
                {
                    usr.mat_khau = GetMd5Hash(ID + PASS);
                    db.Entry(usr).State = EntityState.Modified;
                    db.SaveChanges();
                    ViewBag.Message = "Đổi mật khẩu thành công!";
                    return View();
                }

                ViewBag.Error = "Mật khẩu cũ chưa chính xác!";
                return View(usr);
            }
            return View(usr);
        }
Ejemplo n.º 2
0
        public ActionResult Create(user usr, FormCollection collection)
        {
            ViewBag.Lectures = new SelectList(db.users.Where(user => user.id_chuc_vu == 1), "id", "ho_ten", usr.ma_GVHD);
            ViewBag.Group = new SelectList(db.nhoms, "id", "ten_nhom", usr.ma_nhom);
            ViewBag.Error = null;
            ViewBag.Success = null;
            ModelState["secret"].Errors.Clear();
            ModelState["ConfirmPassword"].Errors.Clear(); // ignore confirm password
            if (ModelState.IsValid)
            {
                string email = usr.email;
                bool check = true;
                try
                {
                    string _email = db.users.Where(a => a.email == email).Select(x => x.email).Single();
                    check = false;
                }
                catch
                {
                }

                if (!check)  // kiem tra email ton tai ko
                {
                    ViewBag.Error = "Email đã tồn tại";
                    usr.mat_khau = null;
                    usr.ConfirmPassword = null;
                    return View(usr);
                }
                else
                {
                    usr.secret = usr.ConfirmPassword = "******";
                    int usrId = db.users.Max(_usr => _usr.id);
                    usr.id = usrId + 1;
                    usr.id_chuc_vu = 2;
                    string pos = db.chuc_vu.Where(position => position.id == usr.id_chuc_vu).Select(position => position.mo_ta).FirstOrDefault().ToString();
                    string userGroup = db.nhoms.Where(_grp => _grp.id == usr.ma_nhom).Select(grp => grp.ten_nhom).FirstOrDefault();
                    string id = usr.email;
                    // string passwd = usr.mat_khau;
                    usr.mat_khau = GetMd5Hash(id + "123456");   // ma hoa pass
                    usr.avatar = "/Images/mem.png";
                    usr.trang_thai = 1;
                    usr.ma_GVHD = Convert.ToInt16(Session["USER_ID"]);
                    db.users.Add(usr);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Trace.TraceInformation("Property: {0} Error: {1}",
                                                        validationError.PropertyName,
                                                        validationError.ErrorMessage);
                            }
                        }
                    }

                    //Create folder
                    var folder = Server.MapPath("~/Uploads/" + userGroup + "/" + pos + "/" + usr.email);
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }
                    var folder1 = Server.MapPath("~/Uploads/" + userGroup + "/" + pos + "/" + usr.email + "/Videos");
                    if (!Directory.Exists(folder1))
                    {
                        Directory.CreateDirectory(folder1);
                    }
                    var folder2 = Server.MapPath("~/Uploads/" + userGroup + "/" + pos + "/" + usr.email + "/Images");
                    if (!Directory.Exists(folder2))
                    {
                        Directory.CreateDirectory(folder2);
                    }

                    ModelState.Clear();
                    usr = null;
                    ViewBag.Success = "Tạo mới tài khoản thành công!";
                    return View(usr);
                }
            }
            return View(usr);
        }
Ejemplo n.º 3
0
 public ActionResult Login(FormCollection collection, user user, string url)
 {
     if (ModelState.IsValid && user.mat_khau != null)
     {
         var user_check = db.users.Where(x => x.ma_nguoi_dung == user.ma_nguoi_dung).FirstOrDefault();
         if (GetMd5Hash(user.ma_nguoi_dung + user.mat_khau) == user_check.mat_khau)
         {
             Session["ho_ten"] = user_check.ho_ten;
         }
     }
     //return View(url);
     return RedirectToAction("Index", "Home");
 }
Ejemplo n.º 4
0
 public ActionResult Edit(user user)
 {
     ViewBag.ma_nhom = new SelectList(db.nhoms, "id", "ten_nhom", user.ma_nhom);
     ViewBag.id_chuc_vu = new SelectList(db.chuc_vu, "id", "mo_ta", user.id_chuc_vu);
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Details", "UserManager", new { id = user.id });
     }
     return View(user);
 }
Ejemplo n.º 5
0
 public ActionResult Search(user usr)
 {
     ViewBag.listSearch = new SelectList(db.users, "id", "ho_ten", usr.ho_ten);
     return PartialView("Search");
 }
Ejemplo n.º 6
0
        public ActionResult Login(FormCollection collection, user _usr)
        {
            //  return View();
            string passwd = collection["password"];
            string id = collection["email"];
            string hash = GetMd5Hash(id + passwd);

            DateTime t = DateTime.Now;
            bool validEmail = db.users.Any(userID => userID.email == id);
            _usr = db.users.Where(userID => userID.email == id).SingleOrDefault();

            if (!validEmail)
            {
                ViewBag.Message = "Sai email hoặc mật khẩu, vui lòng thử lại";
                return View();
            }

            string secret = _usr.mat_khau;
            MD5 md5Hash = MD5.Create();
            if (secret.Equals(hash)) // Login success
            {
                var usrInfo = db.users.Where(usrEmail => usrEmail.email == id)
                                 .Single();
                Session["USER_NAME"] = usrInfo.ma_nguoi_dung;
                Session["LOGO"] = usrInfo.avatar;
                Session["USER_EMAIL"] = id;
                Session["USER_ID"] = usrInfo.id;
                Session["GROUPNAME"] = db.nhoms.Where(grp => grp.id == usrInfo.ma_nhom).Select(grp => grp.ten_nhom).SingleOrDefault();
                Session["GROUPID"] = usrInfo.ma_nhom;
                Session["POS_ID"] = usrInfo.id_chuc_vu;
                Session["LECTURE_ID"] = usrInfo.ma_GVHD;
                if (ModelState.IsValid)
                {
                    _usr.thoi_gian_dang_nhap_truoc = DateTime.Now;
                    db.Entry(_usr).State = EntityState.Modified;
                    db.SaveChanges();
                }
                FormsAuthentication.SetAuthCookie(id, false); // Lay Role trong CustomRoleProvider.cs
                return RedirectToAction("Index", "Home"); //chuyen sang trang Index cua controllers Home.
                //}
            }
            else
            {
                ViewBag.Message = "Sai email hoặc mật khẩu, vui lòng thử lại";
                return View();
            }
        }
Ejemplo n.º 7
0
 public ActionResult Edit(user usr, FormCollection collection)
 {
     if (ModelState.IsValid)
     {
         if (usr.id == (int)Session["USER_ID"])
         {
             Session["USER_NAME"] = usr.ma_nguoi_dung;
             Session["LOGO"] = usr.avatar;
         }
         usr.avatar = collection["avatar"];
         db.Entry(usr).State = EntityState.Modified;
         db.SaveChanges();
     }
     //ViewBag.agent_id = new SelectList(db.agents, "agent_id", "agent_name", smt_user.agent_id);
     return RedirectToAction("Details", new { id = usr.id });
 }