Esempio n. 1
0
        /// <summary>
        /// 新增文章类型
        /// </summary>
        /// <param name="newtypename"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public ActionResult NewAddType(string newtypename)
        {
            JSData jsdata = new JSData();

            #region 数据验证
            if (null == BLLSession.UserInfoSessioin)
                jsdata.Messg = "您还未登录~";
            else if (string.IsNullOrEmpty(newtypename))
                jsdata.Messg = "类型不能为空~";

            if (!string.IsNullOrEmpty(jsdata.Messg))
            {
                jsdata.State = EnumState.失败;
                return Json(jsdata);
            }
            #endregion

            int userid = BLLSession.UserInfoSessioin.Id;
            BLL.BlogTypesBLL bll = new BlogTypesBLL();
            bll.Add(
                new ModelDB.BlogTypes()
                {
                    TypeName = newtypename,
                    UsersId = userid,
                    IsDel = false
                }
                );

            if (bll.save() > 0)//保存
            {
                BLL.Common.CacheData.GetAllType(true);//更新缓存
                jsdata.State = EnumState.成功;
                jsdata.Messg = "新增成功~";

            }
            else
            {
                jsdata.State = EnumState.失败;
                jsdata.Messg = "新增失败~";
            }
            return Json(jsdata);
        }
Esempio n. 2
0
        public string Release()
        {
            JSData jsdata = new JSData();

            var content = Request.Form["content"];//正文内容
            var title = Request.Form["title"];//标题
            var oldtag = Request.Form["oldtag"];//旧的标签
            var newtag = Request.Form["newtag"];//新的标签
            var types = Request.Form["chk_type"];//文章类型
            var isshowhome = Request.Form["isshowhome"];//是否显示在主页
            var isshowmyhome = Request.Form["isshowmyhome"];//是否显示在个人主页
            var blogid = Request.Form["blogid"];//

            int numblogid = -1;
            int.TryParse(blogid, out numblogid);

            #region 数据验证
            if (null == BLL.Common.BLLSession.UserInfoSessioin)
                jsdata.Messg = "您还未登录~";
            else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock)
                jsdata.Messg = "您的账户已经被锁定,请联系管理员~";
            else if (string.IsNullOrEmpty(content))
                jsdata.Messg = "内容不能为空~";
            else if (content.Length >= 80000)
                jsdata.Messg = "发布内容过多~";
            else if (string.IsNullOrEmpty(title))
                jsdata.Messg = "标题不能为空~";
            else if (title.Length >= 100)
                jsdata.Messg = "标题过长~";

            if (!string.IsNullOrEmpty(jsdata.Messg))
            {
                jsdata.State = EnumState.失败;
                return jsdata.ToJson();
            }
            #endregion

            BLL.BlogsBLL blogbll = new BLL.BlogsBLL();
            var blogtemp = blogbll.GetList(t => t.Id == numblogid, isAsNoTracking: false).FirstOrDefault();
            var userid = numblogid > 0 ? blogtemp.UsersId : BLLSession.UserInfoSessioin.Id;//如果numblogid大于〇证明 是编辑修改
            var sessionuserid = BLLSession.UserInfoSessioin.Id;

            //获取得 文章 类型集合 对象
            var typelist = new List<int>();
            foreach (string type in types.Split(',').ToList())
            {
                if (!string.IsNullOrEmpty(type))
                    typelist.Add(int.Parse(type));
            }
            // types.Split(',').ToList().ForEach(t => typelist.Add(int.Parse(t)));
            var myBlogTypes = new BLL.BlogTypesBLL().GetList(t => typelist.Contains(t.Id), isAsNoTracking: false).ToList();

            //获取得 文章 tag标签集合 对象
            //old
            var oldtaglist = oldtag.Split(',').ToList();
            var myOldTagTypes = new BLL.BlogTagsBLL().GetList(t => t.UsersId == userid && oldtaglist.Contains(t.TagName), isAsNoTracking: false).ToList();
            //new
            var newtaglist = newtag.Split(',').ToList();
            AddTag(newtaglist, userid);//保存到数据库
            var myNweTagTypes = new BLL.BlogTagsBLL().GetList(t => t.UsersId == userid && newtaglist.Contains(t.TagName), isAsNoTracking: false).ToList();
            myNweTagTypes.ForEach(t => myOldTagTypes.Add(t));

            //ModelDB.Blogs blogtemp = new ModelDB.Blogs();
            if (numblogid > 0)  //如果有 blogid 则修改
            {
                //blog = blogbll.GetList(t => t.Id == numblogid, isAsNoTracking: false).FirstOrDefault();
                if (sessionuserid == blogtemp.UsersId || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户
                {
                    blogtemp.BlogContent = content;
                    blogtemp.BlogTitle = title;
                    //blog.BlogUpTime = DateTime.Now;
                    //blog.BlogCreateTime = DateTime.Now;
                    blogtemp.IsShowMyHome = isshowmyhome == "true";
                    blogtemp.IsShowHome = isshowhome == "true";
                    blogtemp.BlogTypes.Clear();//更新之前要清空      不如会存在主外键约束异常
                    blogtemp.BlogTypes = myBlogTypes;
                    blogtemp.BlogTags.Clear();
                    blogtemp.BlogTags = myOldTagTypes;
                    blogtemp.IsDel = false;
                    blogtemp.IsForwarding = false;
                    jsdata.Messg = "修改成功~";
                }
                else
                {
                    jsdata.Messg = "您没有编辑此博文的权限~";
                    jsdata.JSurl = "/";
                    jsdata.State = EnumState.失败;
                    return jsdata.ToJson();
                }
            }
            else  //否则 新增
            {
                var blogfirst = blogbll.GetList(t => t.UsersId == sessionuserid).OrderByDescending(t => t.Id).FirstOrDefault();
                //var blogtitle = blogtemp.BlogTitle;
                //if (blogfirst != null)
                //    blogtitle = blogtemp.BlogTitle;
                if (null != blogfirst && blogfirst.BlogTitle == title)
                {
                    jsdata.Messg = "不能同时发表两篇一样标题的文章~";
                }
                else
                {
                    blogtemp = new ModelDB.Blogs()
                     {
                         UsersId = sessionuserid,
                         BlogContent = content,
                         BlogTitle = title,
                         BlogUpTime = DateTime.Now,
                         BlogCreateTime = DateTime.Now,
                         IsShowMyHome = isshowmyhome == "true",
                         IsShowHome = isshowhome == "true",
                         BlogTypes = myBlogTypes,
                         BlogTags = myOldTagTypes,
                         IsDel = false,
                         IsForwarding = false
                     };
                    blogbll.Add(blogtemp);
                    jsdata.Messg = "发布成功~";
                }
            }

            //
            if (blogbll.save(false) > 0)
            {
                #region 添加 或 修改搜索索引
                try
                {
                    var newtagList = string.Empty;
                    blogtemp.BlogTags.Where(t => true).ToList().ForEach(t => newtagList += t.TagName + " ");
                    var newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.Id + ".html";
                    SearchResult search = new SearchResult()
                    {
                        flag = blogtemp.UsersId,
                        id = blogtemp.Id,
                        title = blogtemp.BlogTitle,
                        clickQuantity = 0,
                        blogTag = newtagList,
                        content = Blogs.Common.Helper.MyHtmlHelper.GetHtmlText(blogtemp.BlogContent),
                        url = newblogurl
                    };
                    SafetyWriteHelper<SearchResult>.logWrite(search, PanGuLuceneHelper.instance.CreateIndex);
                }
                catch (Exception)
                { }
                #endregion

                jsdata.State = EnumState.成功;
                jsdata.JSurl = "/" + CacheData.GetAllUserInfo().Where(t => t.Id == blogtemp.UsersId).First().UserName + "/" + blogtemp.Id + ".html";
                return jsdata.ToJson();
            }

            jsdata.Messg = string.IsNullOrEmpty(jsdata.Messg) ? "操作失败~" : jsdata.Messg;
            jsdata.State = EnumState.失败;
            return jsdata.ToJson();
        }
Esempio n. 3
0
        /// <summary>
        /// 编辑文章类型
        /// </summary>
        /// <param name="typename"></param>
        /// <param name="typeid"></param>
        /// <returns></returns>
        public ActionResult EditType(string typename, int typeid)
        {
            JSData jsdata = new JSData();

            #region 数据验证
            if (null == BLLSession.UserInfoSessioin)
                jsdata.Messg = "您还未登录~";
            else if (string.IsNullOrEmpty(typename))
                jsdata.Messg = "类型不能为空~";
            else if (null == typeid)
                jsdata.Messg = "未取到文章ID~";
            if (!string.IsNullOrEmpty(jsdata.Messg))
            {
                jsdata.State = EnumState.失败;
                return Json(jsdata);
            }
            #endregion

            BLL.BlogTypesBLL bll = new BlogTypesBLL();
            var blogtype = new ModelDB.BlogTypes()
            {
                Id = typeid,
                TypeName = typename
            };
            bll.Up(blogtype, "TypeName");

            if (bll.save() > 0)//保存
            {
                BLL.Common.CacheData.GetAllType(true);//更新缓存
                jsdata.State = EnumState.成功;
                // jsdata.Messg = "修改成功~";
            }
            else
            {
                jsdata.State = EnumState.失败;
                jsdata.Messg = "操作失败~";
            }
            return Json(jsdata);
        }
Esempio n. 4
0
        public JsonResult Regis(BlogUsersSet blog)
        {
            JsonResult jsonresult = new JsonResult();
            var json = new Common.CustomModel.JSData();

            #region 1.数据检验
            if (CacheData.GetAllUserInfo(true).Where(t => t.UserMail == blog.UserMail).Count() > 0)
                json.Messg = "此邮箱已经被注册~换个邮箱吧~";
            else if (CacheData.GetAllUserInfo().Where(t => t.UserName == blog.UserName).Count() > 0)
                json.Messg = "此用户名已经存在~";
            if (!string.IsNullOrEmpty(json.Messg))
            {
                json.State = EnumState.失败;
                jsonresult.Data = json;
                return jsonresult;
            }
            #endregion

            Blogs.ModelDB.BlogUsersSet user = new ModelDB.BlogUsersSet()
            {
                UserName = blog.UserName,
                UserPass = blog.UserPass,
                UserMail = blog.UserMail,
                UserNickname = blog.UserNickname,
                IsLock = true,
                UserInfo = new UserInfo()
            };
            Session[tempUserinfo] = user;
            JSData jsdata;

            #region 2.邮件发送失败
            if (!GetActivate(out jsdata)) //
            {
                jsdata.State = EnumState.失败;
                jsdata.Messg = jsdata.Messg + " ~请重新输入邮箱~";
            }
            #endregion

            #region 3.邮件发送成功
            else
            {

                BLL.BlogUsersSetBLL userBll = new BLL.BlogUsersSetBLL();
                userBll.Add(user);
                //在保存前 再做次验证
                if (GetDataHelper.GetAllUser().Where(t => t.UserName == blog.UserName || t.UserMail == blog.UserMail).Count() > 0)
                {
                    json.Messg = "此用户名后邮箱已经存在~";
                    json.State = EnumState.失败;
                    jsonresult.Data = json;
                    return jsonresult;
                }
                else
                    userBll.save();

                //验证是否注册成功 (并重新加载缓存信息)
                if (CacheData.GetAllUserInfo(true).Where(t => t.UserName == blog.UserName && t.UserPass == blog.UserPass).Count() > 0)
                {
                    BLLSession.UserInfoSessioin = user;
                }
                else
                {
                    json = new JSData()
                    {
                        Messg = "注册失败",
                        State = EnumState.失败
                    };
                    jsonresult.Data = json;
                    return jsonresult;
                }
            }
            #endregion

            jsonresult.Data = jsdata;
            return jsonresult;
        }
Esempio n. 5
0
        public JsonResult Login(BlogUsersSet user, string ischeck)
        {
            JSData objJson = new JSData();
            //var listUser = CacheData.GetAllUserInfo().Where(t => (t.UserName == user.UserName || t.UserMail == user.UserName) && t.UserPass == user.UserPass.MD5().MD5());
            var pass = user.UserPass.MD5().MD5();
            var listUser = GetDataHelper.GetAllUser(t => t.UserInfo).Where(t => (t.UserName == user.UserName || t.UserMail == user.UserName) && t.UserPass == pass);

            if (listUser.Count() > 0)
            {
                Session[tempUserinfo] = listUser.FirstOrDefault();

                #region 1.验证邮箱是否有效  无效则跳转到邮箱验证页面
                if (listUser.Where(t => t.UserMail == "无效" || string.IsNullOrEmpty(t.UserMail)).Count() > 0)
                {
                    objJson.State = EnumState.失败;
                    objJson.Messg = "检测到你注册的邮箱无效~请输入正确的邮箱~";
                    objJson.JSurl = "/UserManage/EmailValidation";
                }
                #endregion

                #region 2.用户是否是激活状态 否:发送激活码 并跳转到激活页面
                else if (listUser.Where(t => t.IsLock == true).Count() > 0)
                {
                    //邮件发送激活码
                    //JSData jsdata;
                    GetActivate(out objJson);
                    //return Json(jsdata);
                }
                #endregion

                #region 3.登录成功
                else
                {
                    //  var objuser = GetDataHelper.GetAllUser(t => t.UserInfo).Where(t => t.UserName == lodname.Trim() && t.UserPass == lodpass.Trim().MD5().MD5() && t.IsLock == false).FirstOrDefault();

                    BLLSession.UserInfoSessioin = listUser.FirstOrDefault();  //Messg = "登录成功",  //不给提示     直接跳转
                    objJson.State = EnumState.正常重定向;
                    if (!string.IsNullOrEmpty(Request.QueryString["href"]))
                        objJson.JSurl = Request.QueryString["href"];
                    else
                        objJson.JSurl = "/";
                    if (ischeck == "on")
                    {
                        //Helper.CookiesHelper.AddCookie("hib_name", user.UserName);
                        //Helper.CookiesHelper.AddCookie("hib_pass", user.UserPass);

                        HttpCookie Cookie = CookiesHelper.GetCookie("userInfo");
                        if (Cookie == null)
                        {
                            Cookie = new HttpCookie("userInfo");
                            Cookie.Values.Add("userName", user.UserName);
                            Cookie.Values.Add("userPass", user.UserPass);
                            //设置Cookie过期时间
                            Cookie.Expires = DateTime.Now.AddDays(365);
                            CookiesHelper.AddCookie(Cookie);
                        }
                        else
                        {
                            if (!Cookie.Values["userName"].Equals(user.UserName))
                                CookiesHelper.SetCookie("userInfo", "userName", user.UserName);
                            if (!Cookie.Values["userPass"].Equals(user.UserPass))
                                CookiesHelper.SetCookie("userInfo", "userPass", user.UserPass);
                        }
                    }
                    else
                    {
                        Helper.CookiesHelper.RemoveCookie("userInfo");
                    }
                }
                #endregion
            }
            else
            {
                objJson.Messg = "用户名或密码错误~";
                objJson.State = EnumState.失败;
            }
            return Json(objJson); //json;
        }
Esempio n. 6
0
        /// <summary>
        /// 获取激活码 (邮件发送成功 默认跳转到激活页面)
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="mail">邮箱地址</param>
        /// <returns></returns>
        public bool GetActivate(out JSData jsdata)
        {
            var json = new Common.CustomModel.JSData();

            #region 1.验证是否正常途径访问获取激活码 方法
            if (null == Session[tempUserinfo])
            {
                json.State = EnumState.失败; //json.Messg = "请您通过正常途径访问激活页面~";
                json.JSurl = "/";
                jsdata = json;
                return false;
            }
            #endregion

            Session[jihuoma] = new Random().Next(999999999).ToString();

            #region 2.发送邮件 如果邮件发送成功    默认跳转到 激活页面
            Helper.EmailHelper email = new Helper.EmailHelper()
            {
                mailPwd = s_mailPwd,
                host = s_host,
                mailFrom = s_mailFrom,
                mailSubject = "[嗨-博客]激活码",
                mailBody = "欢迎激活 “嗨-博客”</br></br>您注册的的帐号:" + ((ModelDB.BlogUsersSet)Session[tempUserinfo]).UserName +
                " 激活码:" + Session[jihuoma].ToString(),
                mailToArray = new string[] { ((ModelDB.BlogUsersSet)Session[tempUserinfo]).UserMail }
            };

            try
            {
                email.Send();
                json.State = EnumState.正常重定向;
                json.Messg = "激活码已经发送邮箱~请注意查收~";
                json.JSurl = "/UserManage/Activate";
                jsdata = json;
                return true;
            }
            catch (Exception ex)
            {
                json.State = EnumState.失败;
                json.Messg = ex.Message;
                jsdata = json;
                return false;
            }

            #endregion
        }
Esempio n. 7
0
        public JsonResult EmailValidation(string UserMail)
        {
            var email = UserMail;

            JsonResult jsonRe = new JsonResult();

            JSData jsdata = new JSData();

            if (null == Session[tempUserinfo])
            {
                jsdata.State = EnumState.失败;
                jsdata.JSurl = "/UserManage/Login";
            }
            else if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(email.Trim()))
            {
                jsdata.Messg = "邮箱不能为空~";
                jsdata.State = EnumState.失败;
            }
            else if (BLL.Common.CacheData.GetAllUserInfo().Where(t => t.UserMail == email.Trim()).Count() >= 1)
            {
                jsdata.Messg = "此邮箱已被占用~";
                jsdata.State = EnumState.失败;
            }
            else// if (null != Session[tempUserinfo])
            {
                var userobj = (ModelDB.BlogUsersSet)Session[tempUserinfo];
                userobj.UserMail = email;//z
                GetActivate(out jsdata);
                // return jsdata.ToJson();
            }
            jsonRe.Data = jsdata;
            return jsonRe;
        }