예제 #1
0
        public static UserDto getDTO(DataRow dr)
        {
            UserDto userDto = new UserDto();

                userDto.UserId = int.Parse(dr["UserId"].ToString());
                userDto.UserPassword = dr["UserPassword"].ToString();
                userDto.UserName = dr["UserName"].ToString();
                userDto.UserRoles = dr["UserRoles"].ToString();
                userDto.UserEmail = dr["UserEmail"].ToString();
                userDto.UserTelephone = dr["UserTelephone"].ToString();
                userDto.UserStatus = bool.Parse(dr["UserStatus"].ToString());
                userDto.UserRegisterTime = DateTime.Parse(dr["UserRegisterTime"].ToString());
                userDto.UserSex = dr["UserSex"].ToString();
                userDto.UserRealName = dr["UserRealName"].ToString();
                userDto.UserImg = dr["UserImg"].ToString();
                userDto.UserBirthday = DateTime.Parse(dr["UserBirthday"].ToString());

                return userDto;
        }
예제 #2
0
        public ActionResult EditEmail(UserEmailViewModel model)
        {
            try
            {
                UserDto dto = new UserDto();
                Message msg = new Message();
                DataTable dt = CMSService.SelectOne("User", "CMSUser", "UserName!='" + model.UserName + "' and UserEmail='" + model.UserEmail + "'");
                if (dt.Rows.Count > 0)
                {

                    msg.MessageStatus = "Error";
                    msg.MessageInfo = "此邮箱已经被其他用户占用。";
                    ViewBag.Status = msg.MessageStatus;
                    ViewBag.msg = msg.MessageInfo;
                    return View("UserInfo");
                }
                else
                {

                    msg = CMSService.UpdateFieldOneByOne("User", "CMSUser", "UserName='******'", "UserEmail", model.UserEmail);
                    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("UserInfo");
            }
        }
예제 #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 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();
            }
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
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();
        }
예제 #8
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");
        }
예제 #9
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);
        }
예제 #10
0
        public ActionResult EditPassword(EditPasswordViewModel model)
        {
            try
            {
                UserDto dto = new UserDto();
                Message msg = new Message();
                DataTable dt = CMSService.SelectOne("User", "CMSUser", "UserPassword='******' and UserId=" + model.UserId);
                if (dt.Rows.Count == 0)
                {

                    msg.MessageStatus = "Error";
                    msg.MessageInfo = "原密码错误";
                    ViewBag.Status = msg.MessageStatus;
                    ViewBag.msg = msg.MessageInfo;
                    return View("UserInfo");
                }
                else
                {

                    msg = CMSService.UpdateFieldOneByOne("User", "CMSUser", "UserPassword='******' and UserId=" + model.UserId, "UserPassword",  CommonTools.ToMd5(model.UserPassword));

                    msg.MessageStatus = "Success";
                    msg.MessageInfo = "密码修改成功了";
                    ViewBag.Status = msg.MessageStatus;
                    // TODO: Add delete logic here

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

            }
            catch
            {
                Message msg = new Message();
                msg.MessageStatus = "Error";
                msg.MessageInfo = "操作出错了";
                ViewBag.Status = msg.MessageStatus;
                ViewBag.msg = msg.MessageInfo;
                return View("UserInfo");
            }
        }
예제 #11
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;
        }
예제 #12
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" });
            }
        }