public ActionResult ChangePassword(ChangePassword pwdForm)
        {
            UserModel userModel = new UserModel();
            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);

            userInfo.Password = userModel.PasswordEncrypt(pwdForm.NewPassword);
            userModel.Save();

            userModel.SignOut();

            return RedirectToAction("Login");
        }
        public ActionResult ChangeUserInfo(bool gender, string birthDay)
        {
            try
            {
                if (!User.Identity.IsAuthenticated)
                    return Json(new { key = 0, value = "用户不合法!" }, JsonRequestBehavior.AllowGet);

                UserModel userModel = new UserModel();
                var userInfo = userModel.GetUserInfo(User.Identity.Name);
                userInfo.Gender = gender;
                userInfo.Birthday = DateTime.Parse(birthDay);
                userModel.Save();
                return Json(new { key = 1, value = "修改成功!" }, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json(new { key = 0, value = "网站内部错误!请刷新页面重试。" }, JsonRequestBehavior.AllowGet);
            }
        }
        public ActionResult GetMsgContent(int id)
        {
            UserModel userModel = new UserModel();
            UserMessage msg = userModel.GetUserMessage(id);
            if (msg == null)
                return Json(new { key = 0, value = "该信息不存在!" }, JsonRequestBehavior.AllowGet);

            //如果该条信息没有被读过,则此时将其标记为已读
            if (!msg.Readed)
            {
                msg.Readed = true;
                userModel.Save();
            }
            return Json(new { key = 1, title = msg.MsgTitle, createTime = msg.CreateTime.ToString("yyyy/M/d HH:mm:ss"), content = msg.MsgContent }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult FindPassword(FindPassword formValues)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("index");

            if (ModelState.IsValid)
            {
                var emailReg = new System.Text.RegularExpressions.Regex("^(\\w)+(\\.\\w+)*@[\\w\\d]+((\\.\\w+)+)$");
                if (formValues.UserEmail == null || !emailReg.IsMatch(formValues.UserEmail))
                {
                    ModelState.AddModelError("UserEmail", "邮箱格式不正确");
                    return View(formValues);
                }
                else if (Session["ValidateCode"] == null
                   || formValues.ValidateCode == null
                   || formValues.ValidateCode.ToLower() != Session["ValidateCode"].ToString().ToLower())
                {
                    ModelState.AddModelError("ValidateCode", "验证码错误");
                    return View(formValues);
                }

                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(formValues.UserEmail);
                string newPwd = ImageValidate.CreateCode(6);//生生6位数的随机密码
                userInfo.Password = userModel.PasswordEncrypt(newPwd);
                userModel.Save();
                //发送新密码
                ZsfProject.Tools.SendEmail.ResetPassword(formValues.UserEmail, newPwd);
            }

            return RedirectToAction("FindPassword", new { step = 2 });
        }
        public ActionResult CropUserPhoto(string imgPath, float zoomRatio, float cropX, float cropY, int cropW, int cropH)
        {
            string fileName = "";
            string filePath = "";
            using (Image logo = Image.FromFile(Server.MapPath(imgPath)))
            {
                //根据缩放比例,剪切原图中对应的区域
                RectangleF cropRec = new RectangleF(cropX / zoomRatio, cropY / zoomRatio, cropW / zoomRatio, cropH / zoomRatio);
                //将剪切后的图片填充到该矩形内
                Rectangle fillRec = new Rectangle(0, 0, cropW, cropH);

                using (Bitmap logoBit = new Bitmap(cropW, cropH))
                {
                    using (Graphics g = Graphics.FromImage(logoBit))
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        g.DrawImage(logo, fillRec, cropRec, GraphicsUnit.Pixel);

                        UserModel userModel = new UserModel();
                        UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
                        string fileExtension = Path.GetExtension(imgPath);

                        filePath = Path.GetDirectoryName(Server.MapPath("~/Contents/UserPhotos/"));
                        fileName = (10200 + userInfo.Id) + fileExtension;
                        string fileFullPath = filePath + "\\" + fileName;

                        if (System.IO.File.Exists(fileFullPath))
                        {
                            try
                            {
                                System.IO.File.Delete(fileFullPath);
                            }
                            catch
                            {//如果删除不成功,就以随机的GUID来命名文件
                                fileName = Guid.NewGuid().ToString() + fileExtension;
                                fileFullPath = filePath + "\\" + fileName;
                            }
                        }
                        userInfo.Photo = "/Contents/UserPhotos/" + fileName;
                        userModel.Save();

                        logoBit.Save(fileFullPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                }
            }

            return Json(new { key = 1, value = "/Contents/UserPhotos/" + fileName }, JsonRequestBehavior.AllowGet);
        }
        public int ChangeUserServiceArea(int areaId)
        {
            string areaName = "";

            if (User.Identity.IsAuthenticated)
            {
                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);
                UserDefaultArea defaultArea;
                if (userInfo.UserDefaultArea.Count == 0)
                {
                    defaultArea = new UserDefaultArea();
                    defaultArea.UserId = userInfo.Id;
                    defaultArea.AreaId = areaId;
                    userModel.Add(defaultArea);
                }
                else
                {
                    defaultArea = userModel.GetUserDefaultArea(userInfo.Id);
                    defaultArea.AreaId = areaId;
                    userModel.Save();
                }
                areaName = defaultArea.ServiceArea.Value;
            }
            else
            {
                BaseDataModel baseModel = new BaseDataModel();
                areaName =  baseModel.GetServiceArea(areaId).Value;
            }

            System.Web.HttpCookie areaCookie = new System.Web.HttpCookie("udefaultarea");
            areaCookie.Domain = BaseDataModel.CookieDomain;
            areaCookie.Values["Id"] = areaId.ToString();
            areaCookie.Values["Name"] = HttpUtility.UrlEncode(areaName);
            areaCookie.Expires = DateTime.Now.AddYears(1);
            Response.Cookies.Set(areaCookie);
            return 1;
        }