Example #1
0
        public IActionResult ChangePassword(ChangePassword Model)
        {
            int IDUSER = int.Parse(HttpContext.Request.Headers["Id"]);

            try
            {
                string pass = USUsersService.GetMD5(Model.OldPassword);
                Model.NewPassword = Model.NewPassword.Trim();
                Model.RePassword  = Model.RePassword.Trim();
                Boolean StrongPass = USUsersService.ValidateStrongPassword(Model.NewPassword);
                if (Model.Id == IDUSER)
                {
                    if (StrongPass)
                    {
                        if (Model.NewPassword == Model.RePassword)
                        {
                            USUsers item = USUsersService.CheckPassword(IDUSER, pass);
                            if (item != null && item.Password == pass)
                            {
                                string new_pass = USUsersService.GetMD5(Model.NewPassword);
                                var    result   = USUsersService.ChangePassword(IDUSER, new_pass);
                                TempData["MessageSuccess"] = "Thay đổi Mật khẩu thành công";
                            }
                            else
                            {
                                TempData["MessageError"] = "Mật khẩu cũ không chính xác";
                            }
                        }
                        else
                        {
                            TempData["MessageError"] = "Mật khẩu mới và mật khẩu Nhập lại không giống nhau";
                        }
                    }
                    else
                    {
                        TempData["MessageError"] = "Mật khẩu quá đơn giản. Độ dài Mật khẩu phải lới hơn 6, có các ký tự đặc biệt";
                    }
                }
                else
                {
                    TempData["MessageError"] = "Thay đổi Mật khẩu Không thành công";
                }
            }
            catch (Exception e)
            {
                TempData["MessageError"] = e.Message;
            }
            return(View(new ChangePassword()));
        }
Example #2
0
        public ActionResult SaveItem(USUsers model)
        {
            string       ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            int          IdDC           = Int32.Parse(MyModels.Decode(model.Ids, API.Models.Settings.SecretId + ControllerName).ToString());
            USUsersModel data           = new USUsersModel()
            {
                Item = model
            };

            if (ModelState.IsValid)
            {
                if (model.Id == IdDC)
                {
                    if (model.Id == 0)
                    {
                        if (model.Password == null || model.Password == null)
                        {
                            model.Password = "******";
                        }
                        model.Password = USUsersService.GetMD5(model.Password);
                    }
                    dynamic DataSave = USUsersService.SaveItem(model);
                    if (model.Id > 0)
                    {
                        TempData["MessageSuccess"] = "Cập nhật thành công";
                    }
                    else
                    {
                        TempData["MessageSuccess"] = "Thêm mới thành công";
                    }
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                data.ListItemsGroups = USGroupsService.GetListSelectItems();
                data.ListItemsStatus = USUsersService.GetStatusSelectItems();
                data.ListDMCoQuan    = DMCoQuanService.GetListByLoaiCoQuan(0, 1);
                data.ListDMChucVu    = DMChucVuService.GetListSelectItems();
            }
            return(View(data));
        }
Example #3
0
        public ActionResult RessetPassword(string Id)
        {
            string  ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            USUsers item           = new USUsers()
            {
                Id = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString())
            };

            try
            {
                if (item.Id > 0)
                {
                    item.CreatedBy  = int.Parse(HttpContext.Request.Headers["Id"]);
                    item.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]);
                    item.Password   = USUsersService.GetMD5("Abc@123");
                    dynamic DataDelete = USUsersService.ChangePassword(item.Id, item.Password);
                    string  Msg        = "Cập nhật mật khẩu thành công. Mật khẩu mặc định là <strong>" + "Abc@123" + "<strong>";
                    return(Json(new MsgSuccess()
                    {
                        Msg = Msg
                    }));
                }
                else
                {
                    string Msg = "Cập nhật mật khẩu Không thành công. Xin vui lòng làm lại";
                    return(Json(new MsgError()
                    {
                        Msg = Msg
                    }));
                }
            }
            catch
            {
                string Msg = "Cập nhật mật khẩu Không thành công. Xin vui lòng làm lại.";
                return(Json(new MsgError()
                {
                    Msg = Msg
                }));
            }
        }