Пример #1
0
        public ActionResult ResetPassword(ResetPasswordViewModel model)
        {
            try
            {
                UserDto   dto = new UserDto();
                Message   msg = new Message();
                DataTable dt  = CMSService.SelectOne("User", "CMSUser", "UserId=" + model.UserId);

                foreach (DataRow dr in dt.Rows)
                {
                    dto = UserMapping.getDTO(dr);
                    dto.UserPassword = CommonTools.ToMd5(model.UserPassword);
                }
                string JsonString = JsonHelper.JsonSerializerBySingleData(dto);
                msg = CMSService.Update("User", JsonString);
                msg.MessageStatus = "Success";
                msg.MessageInfo   = "密码修改成功了";
                ViewBag.Status    = msg.MessageStatus;
                // TODO: Add delete logic here

                return(RedirectTo("/User/Index", msg.MessageInfo));
            }

            catch
            {
                Message msg = new Message();
                msg.MessageStatus = "Error";
                msg.MessageInfo   = "操作出错了";
                ViewBag.Status    = msg.MessageStatus;
                ViewBag.msg       = msg.MessageInfo;
                return(View());
            }
        }
Пример #2
0
        public ActionResult PartialInfo(string username)
        {
            UserViewModel model = new UserViewModel();
            DataTable     dt    = CMSService.SelectOne("User", "CMSUser", "UserName='******'");

            foreach (DataRow dr in dt.Rows)
            {
                UserDto dto = new UserDto();
                dto                    = UserMapping.getDTO(dr);
                model.UserId           = dto.UserId;
                model.UserName         = dto.UserName;
                model.UserRoles        = MyService.RolesIdToRolesName(dto.UserRoles);
                model.UserEmail        = dto.UserEmail;
                model.UserTelephone    = dto.UserTelephone;
                model.UserStatus       = dto.UserStatus;
                model.UserRegisterTime = dto.UserRegisterTime;
                model.UserRealName     = dto.UserRealName;
                model.UserSex          = dto.UserSex;
                model.UserBirthday     = dto.UserBirthday.ToShortDateString();
                if (String.IsNullOrEmpty(dto.UserImg))
                {
                    model.UserImg = "/UserImg/Img/default_48.jpg";
                }
                else
                {
                    model.UserImg = dto.UserImg + "_48.jpg";
                }
            }
            ViewData["Sex"] = MyService.GetSexSelectList();
            return(View(model));
        }
Пример #3
0
        // 返回用户对应的角色, 在实际中, 可以从SQL数据库中读取用户的角色信息
        private string GetRole(string UserName)
        {
            if (string.IsNullOrEmpty(UserName))
            {
                return("游客");
            }
            else
            {
                UserDto   dto = new UserDto();
                DataTable dt  = CMSService.SelectOne("User", "CMSUser", "UserName='******'");
                foreach (DataRow dataRow in dt.Rows)
                {
                    dto = UserMapping.getDTO(dataRow);
                }


                string   userRoles = "";
                string   roleName  = "";
                string   s         = dto.UserRoles;
                string[] sArray    = s.Split(',');
                foreach (string i in sArray)
                {
                    DataTable dataTable = CMSService.SelectOne("Role", "CMSRole", "RoleId=" + int.Parse(i));
                    foreach (DataRow dataRow in dataTable.Rows)
                    {
                        RoleDto roleDto = new RoleDto();
                        roleDto  = RoleMapping.getDTO(dataRow);
                        roleName = roleDto.RoleName;
                    }
                    userRoles = userRoles + roleName + ",";
                    userRoles = userRoles.Substring(0, userRoles.Length - 1);
                }
                return(userRoles);
            }
        }
Пример #4
0
        public static string UserIdToName(string strWhere)
        {
            UserDto   dto = new UserDto();
            DataTable dt  = CMSService.SelectOne("User", "CMSUser", strWhere);

            foreach (DataRow dr in dt.Rows)
            {
                dto = UserMapping.getDTO(dr);
            }
            return(dto.UserName);
        }
Пример #5
0
        public static List <UserDto> GetUserList(string strwhere)
        {
            List <UserDto> UserList = new List <UserDto>();
            DataTable      dt       = CMSService.SelectSome("User", "CMSUser", strwhere);

            foreach (DataRow dr in dt.Rows)
            {
                UserDto dto = UserMapping.getDTO(dr);
                UserList.Add(dto);
            }
            return(UserList);
        }
Пример #6
0
        public ActionResult UserLogin(UserLoginViewModel model)
        {
            string    strwhere = "UserName='******' and UserPassword='******'";
            DataTable dt       = CMSService.SelectOne("User", "CMSUser", strwhere);

            if (dt.Rows.Count > 0)
            {
                UserDto dto = new UserDto();
                foreach (DataRow dr in dt.Rows)
                {
                    dto = UserMapping.getDTO(dr);
                }
                if (!dto.UserStatus)
                {
                    return(RedirectToAction("Login", "Login", new { ac = "StatusError" }));
                }
                else
                {
                    HttpCookie cookie = new HttpCookie("User");
                    cookie.Value = dto.UserName;
                    System.Web.HttpContext.Current.Response.Cookies.Add(cookie);

                    HttpCookie cookieid = new HttpCookie("UserId");
                    cookieid.Value = dto.UserId.ToString();
                    System.Web.HttpContext.Current.Response.Cookies.Add(cookieid);

                    HttpCookie cookieImg = new HttpCookie("UserImg");
                    string     urlImg    = "";
                    if (String.IsNullOrEmpty(dto.UserImg))
                    {
                        urlImg = "/UserImg/Img/default_48.jpg";
                    }
                    else
                    {
                        urlImg = dto.UserImg.ToString() + "_48.jpg";
                    }
                    cookieImg.Value = urlImg;
                    System.Web.HttpContext.Current.Response.Cookies.Add(cookieImg);

                    System.Web.HttpContext.Current.Session["UserId"] = dto.UserId;
                    FormsAuthentication.SetAuthCookie(dto.UserName, false);

                    return(Redirect("/Home/Index"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Login", new { ac = "LoginError" }));
            }
        }
        public JsonResult ValidateUserEmail(string UserEmail)
        {
            var       result  = false;
            UserDto   userDto = new UserDto();
            DataTable dt      = CMSService.SelectOne("User", "CMSUser", "UserEmail='" + UserEmail + "'");

            foreach (DataRow dr in dt.Rows)
            {
                userDto = UserMapping.getDTO(dr);
            }

            result = !(userDto.UserId > 0);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #8
0
        public ActionResult PartialEditUserInfo(string id)
        {
            EditUserInfoViewModel model = new EditUserInfoViewModel();
            DataTable             dt    = CMSService.SelectOne("User", "CMSUser", "UserId=" + id);

            foreach (DataRow dr in dt.Rows)
            {
                UserDto dto = new UserDto();
                dto                = UserMapping.getDTO(dr);
                model.UserId       = dto.UserId;
                model.UserName     = dto.UserName;
                model.UserRealName = dto.UserRealName;
                model.UserSex      = dto.UserSex;
                model.UserBirthday = dto.UserBirthday.ToShortDateString();
            }
            ViewData["Sex"] = MyService.GetSexSelectList();
            return(View(model));
        }
Пример #9
0
        public ActionResult EditUserInfo(EditUserInfoViewModel model)
        {
            UserDto   dto = new UserDto();
            DataTable dt  = CMSService.SelectOne("User", "CMSUser", "UserId=" + model.UserId);

            foreach (DataRow dr in dt.Rows)
            {
                dto = UserMapping.getDTO(dr);
                //  dto.UserRoles = Request.Form["UserRoles"];
                dto.UserBirthday = DateTime.Parse(model.UserBirthday);
                dto.UserRealName = model.UserRealName;
                dto.UserSex      = model.UserSex;
            }
            string  JsonString = JsonHelper.JsonSerializerBySingleData(dto);
            Message msg        = CMSService.Update("User", JsonString);

            // TODO: Add update logic here

            return(RedirectToAction("UserInfo"));
        }
Пример #10
0
        public ActionResult PartialEditUserImg(string id)
        {
            string    imgurl = "";
            UserDto   dto    = new UserDto();
            DataTable dt     = CMSService.SelectOne("User", "CMSUser", "UserId=" + id);

            foreach (DataRow dr in dt.Rows)
            {
                dto = UserMapping.getDTO(dr);
            }
            if (string.IsNullOrEmpty(dto.UserImg))
            {
                imgurl = "/UserImg/Img/default";
            }
            else
            {
                imgurl = dto.UserImg;
            }
            ViewBag.userImg = imgurl + "_48.jpg";
            ViewBag.userid  = id;

            return(View());
        }
Пример #11
0
        //用户列表
        public static List <SelectListItem> GetUserSelectList(string strwhere)
        {
            DataTable             dt    = CMSService.SelectSome("User", "CMSUser", strwhere);
            List <SelectListItem> items = new List <SelectListItem>();

            foreach (DataRow dr in dt.Rows)
            {
                UserDto dto      = UserMapping.getDTO(dr);
                string  username = "";
                if (String.IsNullOrEmpty(dto.UserRealName))
                {
                    username = dto.UserName;
                }
                else
                {
                    username = dto.UserRealName;
                }
                items.Add(new SelectListItem {
                    Text = username, Value = dto.UserId.ToString()
                });
            }
            return(items);
        }
Пример #12
0
        // 显示用户列表页

        public ActionResult Index(int?p, int?roleId)
        {
            int   RoleId = roleId ?? 0;
            Pager pager  = new Pager();

            pager.table      = "CMSUser";
            pager.strwhere   = "1=1";
            pager.PageSize   = 10;
            pager.PageNo     = p ?? 1;
            pager.FieldKey   = "UserId";
            pager.FiledOrder = "UserId Desc";
            if (RoleId > 0)
            {
                pager.strwhere = pager.strwhere + " and charindex('" + RoleId + "',UserRoles)>0";
            }

            pager = CMSService.SelectAll("User", pager);


            List <UserDto> list = new List <UserDto>();

            foreach (DataRow dr in pager.EntityDataTable.Rows)
            {
                UserDto dto = UserMapping.getDTO(dr);
                dto.UserRoles = MyService.RolesIdToRolesName(dto.UserRoles);
                list.Add(dto);
            }
            pager.Entity = list.AsQueryable();

            ViewBag.PageNo      = p ?? 1;
            ViewBag.PageCount   = pager.PageCount;
            ViewBag.RecordCount = pager.Amount;
            ViewBag.Message     = pager.Amount;
            ViewData["Roles"]   = MyService.GetRolesList("1=1");

            return(View(pager.Entity));
        }
Пример #13
0
        // 编辑权限
        public ActionResult EditRoles(int id)
        {
            EditUserRolesViewModel model = new EditUserRolesViewModel();
            DataTable dt = CMSService.SelectOne("User", "CMSUser", "UserId=" + id);

            foreach (DataRow dr in dt.Rows)
            {
                UserDto dto = new UserDto();
                dto             = UserMapping.getDTO(dr);
                model.UserId    = dto.UserId;
                model.UserName  = dto.UserName;
                model.UserRoles = dto.UserRoles;
            }
            DataTable      RoleDt    = CMSService.SelectSome("Role", "CMSRole", "1=1");
            List <RoleDto> ListRoles = new List <RoleDto>();

            foreach (DataRow dr in RoleDt.Rows)
            {
                RoleDto roleDto = RoleMapping.getDTO(dr);
                ListRoles.Add(roleDto);
            }
            ViewData["ListRoles"] = ListRoles;
            return(View(model));
        }