/// <summary>
        /// (无效邮箱)重新绑定邮箱  邮箱发送成功 默认跳转到激活页面
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JSData EmailValidation(string UserMail)
        {
            JSData jsdata = new JSData();

            jsdata.State = EnumState.失败;

            if (null == Session[tempUserinfo])
            {
                jsdata.JSurl = "/UserManage/Login";
            }
            else if (string.IsNullOrEmpty(UserMail) || string.IsNullOrEmpty(UserMail.Trim()))
            {
                jsdata.Messg = "邮箱不能为空~";
            }
            else if (GetDataHelper.GetAllUser().Where(t => t.UserMail == UserMail.Trim()).Count() >= 1)
            {
                jsdata.Messg = "此邮箱已被占用~";
            }
            else
            {
                var userobj = (BlogUser)Session[tempUserinfo];
                userobj.UserMail = UserMail;
                GetActivate(ref jsdata);
            }
            return(jsdata);
        }
Esempio n. 2
0
        /// <summary>
        /// 公共数据存储(从数据缓存中取 如何以后数据量大的话 再考虑是否实时查询)
        /// </summary>
        /// <param name="dic"></param>
        /// <param name="name"></param>
        private void SetDic(Dictionary <string, object> dic, string name)
        {
            var user = GetDataHelper.GetAllUser().FirstOrDefault(t => t.UserName == name);

            //dic.Add("blogName", name);
            dic.Add(Constant.blogUser, user);
            dic.Add(Constant.userBlogTag, GetDataHelper.GetAllTag(user.Id).ToList());
            dic.Add(Constant.userBlogType, GetDataHelper.GetAllType().Where(t => t.BlogUser.Id == user.Id).ToList());
            dic.Add(Constant.SessionUser, BLL.Common.BLLSession.UserInfoSessioin);
        }
Esempio n. 3
0
 public ActionResult HiBlogEdit(string url, string isshowhome, string isshowmyhome, string userName, string blogTag)
 {
     try
     {
         var userinfo = GetDataHelper.GetAllUser().Where(t => t.UserName == userName).FirstOrDefault();
         PlugInUnitController.ForwardRealization(userinfo, blogTag, "", url, Request.Url.Host, isshowhome == "on", isshowmyhome == "on", true);
     }
     catch (Exception ex)
     {
         LogSave.ErrLogSave("", ex);
     }
     return(null);
 }
 /// <summary>
 /// 根据token获取登录用户
 /// 如果不存在 或过期 返回null
 /// [主要用在特性验证]
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static BlogUser GetLoginUser(string key)
 {
     if (!ToKens.Keys.Contains(key))
     {
         return(null);
     }
     if (ToKens[key].Time.AddHours(time) < DateTime.Now)
     {
         ToKens.Remove(key);
         return(null);
     }
     ToKens[key].Time = DateTime.Now;
     return(GetDataHelper.GetAllUser()
            .Where(t => t.UserName == ToKens[key].Name || t.UserMail == ToKens[key].Name).FirstOrDefault());
 }
Esempio n. 5
0
        public ActionResult Index(int?id)
        {
            //
            int total;

            Response.Cache.SetOmitVaryStar(true);
            id = id ?? 1;
            int idex = int.Parse(id.ToString());

            BLL.BaseBLL <BlogInfo> blog = new BLL.BaseBLL <BlogInfo>();
            var bloglist = blog.GetList <DateTime?>(idex, sizePage, out total, t => t.IsShowHome == true, false, t => t.BlogCreateTime, false)
                           .Select(t => new
            {
                Id             = t.Id,
                BlogTitle      = t.Title,
                BlogContent    = t.Content,
                UserName       = t.User.UserName,
                UserNickname   = t.User.UserNickname,
                BlogCreateTime = t.BlogCreateTime,
                BlogReadNum    = t.ReadNum,
                BlogCommentNum = t.CommentNum
            })
                           .ToList()
                           .Select(t => new BlogInfo()
            {
                Id             = t.Id,
                Title          = t.BlogTitle,
                Content        = MyHtmlHelper.GetHtmlText(t.BlogContent),
                BlogCreateTime = t.BlogCreateTime,
                User           = new BlogUser()
                {
                    UserName     = t.UserName,
                    UserNickname = t.UserNickname
                },
                ReadNum    = t.BlogReadNum,
                CommentNum = t.BlogCommentNum
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("blog", bloglist);
            dic.Add("users", GetDataHelper.GetAllUser().Where(t => t.IsLock == false).ToList());
            dic.Add("SessionUser", BLL.Common.BLLSession.UserInfoSessioin);
            dic.Add("total", total);
            return(View(dic));
        }
        /// <summary>
        /// 登录 返回token
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="userPas">密码</param>
        /// <returns></returns>
        public object GetLoginToken(string userName, string userPas)
        {
            RemoveToKen();
            userPas = userPas.MD5();
            //if ( GetDataHelper.GetAllUser().Count() <= 0)
            //    BLL.Common.CacheData.GetAllUserInfo(true);

            var userTemp = GetDataHelper.GetAllUser()
                           .Where(t => (t.UserName == userName || t.UserMail == userName) && t.UserPass == userPas && t.IsLock == false).FirstOrDefault();

            if (userTemp != null)
            {
                string toKenKey = Guid.NewGuid().ToString("N");
                if (ToKens.Keys.Contains(toKenKey))
                {
                    ToKens[toKenKey].Time = DateTime.Now;
                }
                else
                {
                    ToKens.Add(toKenKey, new ToKenModel()
                    {
                        Name = userName, Time = DateTime.Now
                    });
                }
                return(new
                {
                    state = 1,
                    msg = toKenKey,
                    userInfo = new BlogUser()
                    {
                        Id = userTemp.Id,
                        UserName = userTemp.UserName,
                        UserMail = userTemp.UserMail,
                        UserNickname = userTemp.UserNickname
                    }
                });
            }
            else
            {
                return new { state = 0, msg = "用户名或密码错误", userInfo = string.Empty }
            };
        }

        #endregion
    }
        public JsonResult ResetPass(BlogUsersSet blog)
        {
            JsonResult jsonRe = new JsonResult();
            var        pass   = blog.UserPass;
            var        email  = blog.UserMail;

            var objJson = new Common.CustomModel.JSData();

            #region 1.数据验证
            if (string.IsNullOrEmpty(pass.Trim()))
            {
                objJson.Messg = "新密码不能为空~";
            }
            if (string.IsNullOrEmpty(email.Trim()))
            {
                objJson.Messg = "邮箱不能为空~";
            }
            if (!string.IsNullOrEmpty(objJson.Messg))
            {
                objJson.State = EnumState.失败;
                jsonRe.Data   = objJson;
                return(jsonRe);
            }
            #endregion

            var obj = GetDataHelper.GetAllUser().Where(t => t.UserMail == email);
            if (null == obj || obj.Count() <= 0)
            {
                objJson.State = EnumState.失败;
                objJson.Messg = "您输入的邮箱不是注册时候的邮箱~";
                jsonRe.Data   = objJson;
            }
            else
            {
                Session[tempUserinfo] = obj.FirstOrDefault();
                var userobj = (ModelDB.BlogUsersSet)Session[tempUserinfo];
                userobj.UserPass = pass;//z
                GetActivate(out objJson);
                jsonRe.Data = objJson;
            }

            return(jsonRe);
        }
        /// <summary>
        /// 加载 Lucene.net 的搜索结果
        /// </summary>
        /// <returns></returns>
        public ActionResult ShowLuceneResult()
        {
            if (!Request.QueryString.AllKeys.Contains("key"))
            {
                return(null);
            }
            string key = Request.QueryString["key"];

            var zhankey  = key.Split(' ');//分割关键字
            var blogName = string.Empty;

            if (zhankey.Length >= 2)
            {
                var str = zhankey[0].Trim();
                if (str.Length > 6 && str.Substring(0, 5) == "blog:")
                {
                    blogName = str.Substring(5);//取得用户名
                }
            }

            string userid = Request.QueryString.AllKeys.Contains("userid") ? Request.QueryString["userid"] : "";

            //这里判断是否 用户名不为空  然后取得用户对应的 用户ID  (因为 我在做Lucene 是用用户id 来标记的)
            if (!string.IsNullOrEmpty(blogName))
            {
                key = key.Substring(key.IndexOf(' '));
                var userinfo = GetDataHelper.GetAllUser().Where(t => t.UserName == blogName).FirstOrDefault();
                if (null != userinfo)
                {
                    userid = userinfo.Id.ToString();
                }
            }

            string pIndex    = Request.QueryString.AllKeys.Contains("p") ? Request.QueryString["p"] : "";
            int    PageIndex = 1;

            int.TryParse(pIndex, out PageIndex);

            int PageSize   = 10;
            var searchlist = PanGuLuceneHelper.instance.Search(userid, key, PageIndex, PageSize);

            return(PartialView(searchlist));
        }
        /// <summary>
        /// 转发
        /// </summary>
        public void Forward()
        {
            Response.ContentType = "application/json";
            //GetSiteUrl();
            var    ResultValue = string.Empty;
            var    data        = Request.QueryString["mydata"];
            string callback    = Request.QueryString["callback"];
            JavaScriptSerializer        jss = new JavaScriptSerializer();
            Dictionary <string, string> dic = jss.Deserialize <Dictionary <string, string> >(data);
            var name     = dic["username"].Trim();
            var pass     = dic["password"].Trim();
            var userinfo = GetDataHelper.GetAllUser().Where(t => t.UserName == name && t.UserPass == pass.MD5().MD5()).FirstOrDefault();
            //object tyeList = null;
            var tag  = dic["tag"].Trim();
            var type = dic["type"].Trim();
            var url  = dic["url"].Trim();
            var json = ForwardRealization(userinfo, tag, type, url, Request.Url.Host, false, true);
            var call = callback + "('" + json + "')";

            Response.Write(call);
        }
Esempio n. 10
0
        /// <summary>
        /// 根据博客文章id 取相关评论  ()
        /// </summary>
        /// <param name="blogId"></param>
        public List <List <BlogComment> > GetComment(int blogId, int pageIndex, int order)
        {
            var isOrder = order == 0;
            int total;

            BLL.BaseBLL <BlogComment> com = new BaseBLL <BlogComment>();
            //IsInitial == true 父评论 (第一次数据库查询:查询30条父评论)
            List <int> disCom = com.GetList <int>(pageIndex, 30, out total, t => t.IsInitial == true && t.BlogInfo.Id == blogId, false, t => t.Id, isOrder).Select(t => t.Id).ToList();

            if (pageIndex > total)//已经没有评论信息了
            {
                return(null);
            }
            //第二次数据库查询:查询30条父评论 和30条父评论下的子评论
            var listCom = com.GetList(t => disCom.Contains(t.CommentID) || disCom.Contains(t.Id)).ToList();
            List <List <BlogComment> > ComObj = new List <List <BlogComment> >();
            var ini = listCom.Where(t => t.IsInitial == true).ToList();//这里就不查数据库了直接进行集合筛选

            if (isOrder)
            {
                ini = ini.OrderBy(t => t.CreationTime).ToList();
            }
            else
            {
                ini = ini.OrderByDescending(t => t.CreationTime).ToList();
            }
            //对评论进行分组(以父评论 分组)
            foreach (BlogComment item in ini)
            {
                item.BlogUser = GetDataHelper.GetAllUser().Where(t => t.Id == item.BlogUser.Id).FirstOrDefault();
                var userobj = GetDataHelper.GetAllUser().Where(t => t.Id == item.ReplyUserID).FirstOrDefault();
                if (null != userobj)
                {
                    item.ReplyUserName = string.IsNullOrEmpty(userobj.UserNickname) ? item.AnonymousName : userobj.UserNickname;
                }
                //添加 以父评论 为一分组 的评论
                ComObj.Add(GetCom(item, listCom));
            }
            return(ComObj);
        }
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <returns></returns>
        public JSData ResetPass(BlogUser blog)
        {
            var pass  = blog.UserPass;
            var email = blog.UserMail;

            var objJson = new JSData();

            #region 1.数据验证
            if (string.IsNullOrEmpty(pass.Trim()))
            {
                objJson.Messg = "新密码不能为空~";
            }
            if (string.IsNullOrEmpty(email.Trim()))
            {
                objJson.Messg = "邮箱不能为空~";
            }
            if (!string.IsNullOrEmpty(objJson.Messg))
            {
                objJson.State = EnumState.失败;
                return(objJson);
            }
            #endregion

            var obj = GetDataHelper.GetAllUser().Where(t => t.UserMail == email);
            if (null == obj || obj.Count() <= 0)
            {
                objJson.State = EnumState.失败;
                objJson.Messg = "您输入的邮箱不是注册时候的邮箱~";
            }
            else
            {
                Session[tempUserinfo] = obj.FirstOrDefault();
                var userobj = (BlogUser)Session[tempUserinfo];
                userobj.UserPass = pass;//z
                GetActivate(ref objJson);
            }

            return(objJson);
        }
        //static string siteUrl = string.Empty;// "blog.haojima.net";

        /// <summary>
        /// 站内搜索地址
        /// </summary>
        //public string GetSiteUrl()
        //{
        //    if (string.IsNullOrEmpty(siteUrl))
        //        siteUrl = Request.Url.Host;
        //    return siteUrl;
        //}

        /// <summary>
        /// 登录
        /// </summary>
        public void Login()
        {
            var    data     = Request.QueryString["mydata"];
            string callback = Request.QueryString["callback"];
            JavaScriptSerializer        jss = new JavaScriptSerializer();
            Dictionary <string, string> dic = jss.Deserialize <Dictionary <string, string> >(data);
            var    name     = dic["username"].Trim();
            var    pass     = dic["password"].Trim();
            var    userinfo = GetDataHelper.GetAllUser().Where(t => t.UserName == name && t.UserPass == pass.MD5().MD5()).FirstOrDefault();
            object tyeList  = null;

            if (userinfo != null)
            {
                tyeList = GetDataHelper.GetAllType().Where(t => t.BlogUser.Id == userinfo.Id).Select(t => new
                {
                    TypeName = t.TypeName,
                    Id       = t.Id
                }).ToList();
            }
            var cc = callback + "('" + tyeList.ToJson() + "')";

            Response.ContentType = "application/json";
            Response.Write(cc);
        }
        public string WriteContent()
        {
            #region 评论前先检查是否已经登录
            var AnonymousName = string.Empty;//匿名登录
            if (Request.Form.AllKeys.Contains("AnonymousName") && !string.IsNullOrEmpty(Request.Form["AnonymousName"]))
            {
                AnonymousName = Request.Form["AnonymousName"];
            }
            else if (null == BLLSession.UserInfoSessioin)
            {
                return(new JSData()
                {
                    Messg = "您还未登录~",
                    State = EnumState.异常或Session超时
                }.ToJson());
            }
            var sessionUser = BLLSession.UserInfoSessioin;

            //if (BLLSession.UserInfoSessioin.IsLock)
            //{
            //    return new JSData()
            //    {
            //        Messg = "您的账户已经被锁定,请联系管理员~",
            //        State = EnumState.失败
            //    }.ToJson();
            //}
            #endregion

            var BlogId      = int.Parse(Request.Form["BlogId"]);
            var UserId      = sessionUser.Id == 0 ? 1 : sessionUser.Id; //int.Parse(Request.Form["UserId"]);
            var CommentID   = int.Parse(Request.Form["CommentID"]);
            var Content     = Request.Form["Content"];
            var ReplyUserID = int.Parse(Request.Form["ReplyUser"]);

            if (Content.Length >= 1000)
            {
                return(new JSData()
                {
                    State = EnumState.失败
                }.ToJson());
            }

            var ReplyUserName = string.Empty;
            var User          = GetDataHelper.GetAllUser().Where(t => t.Id == ReplyUserID).FirstOrDefault();

            if (null != User)
            {
                ReplyUserName = string.IsNullOrEmpty(User.UserNickname) ? User.UserName : User.UserNickname;
            }

            BLL.BaseBLL <BlogComment> comment = new BLL.BaseBLL <BlogComment>();

            var user     = new BLL.BaseBLL <BlogUser>().GetList(t => t.Id == UserId, isAsNoTracking: false).FirstOrDefault();
            var bloginfo = new BLL.BaseBLL <BlogInfo>().GetList(t => t.Id == BlogId, isAsNoTracking: false).FirstOrDefault();
            comment.Insert(new BlogComment()
            {
                BlogUser      = user,
                BlogInfo      = bloginfo,
                Content       = Content,
                CommentID     = CommentID,
                ReplyUserID   = ReplyUserID,
                ReplyUserName = ReplyUserName,
                IsInitial     = CommentID == -1,
                AnonymousName = AnonymousName
            });

            BLL.BaseBLL <BlogInfo> blogbll = new BLL.BaseBLL <BlogInfo>();
            var blogmode = blogbll.GetList(t => t.Id == BlogId, isAsNoTracking: false).FirstOrDefault();
            if (null == blogmode.CommentNum)
            {
                blogmode.CommentNum = comment.GetList(t => t.BlogInfo.Id == BlogId).Count() + 1;
            }
            else
            {
                blogmode.CommentNum++;
            }

            blogbll.Up(blogmode);
            blogbll.save();

            comment.save();

            #region 评论邮件通知

            var         sessionName = string.IsNullOrEmpty(sessionUser.UserNickname) ? sessionUser.UserName : sessionUser.UserNickname;
            var         tempUser    = (User ?? blogmode.User);
            var         nickName    = string.IsNullOrEmpty(tempUser.UserNickname) ? tempUser.UserName : tempUser.UserNickname;
            var         blogUrl     = "http://" + Request.Url.Authority + "/" + blogmode.User.UserName + "/" + blogmode.Id + ".html";
            EmailHelper email       = new EmailHelper()
            {
                mailPwd     = s_mailPwd,
                host        = s_host,
                mailFrom    = s_mailFrom,
                mailSubject = "嗨-博客 消息提醒~",
                mailBody    = EmailHelper.tempBody(nickName, sessionName + "回复您:<br/>" + Content, "<a href='" + blogUrl + "' target='_blank'>" + blogUrl + "</a>", isShow: false),
                mailToArray = new string[] { tempUser.UserMail }
            };
            try
            {
                email.Send(t =>
                {
                    LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + User.UserMail + "\r\nBody:" + t.Body, "发送成功的邮件");
                },
                           t =>
                {
                    LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + User.UserMail + "\r\nBody:" + t.Body, "发送失败的邮件");
                }
                           );
            }
            catch (Exception)
            { }
            #endregion

            return(new JSData()
            {
                //这里发表成功    就不提示了。
                State = EnumState.成功
            }.ToJson());
        }
        /// <summary>
        /// 激活 (实际上是验证激活码后  修改用户信息:包括是否激活IsLock、邮箱地址、密码 )
        /// </summary>
        /// <returns></returns>
        public string Activate()
        {
            var json = new JSData();

            #region 1.判断是否从正常途径访问此页面 如果是的话 默认存在 Session[tempUserinfo]  2.如果是已经登录状态则直接无视 跳转

            if (null == Session[tempUserinfo])
            {
                json.State = EnumState.失败;//json.Messg = "请您通过正常途径访问激活页面~";
                json.JSurl = "/";
                return(json.ToJson());
            }
            if (BLLSession.UserInfoSessioin != null && !BLLSession.UserInfoSessioin.IsLock)
            {
                json.State = EnumState.失败; //json.Messg = "您都已经登录的还想获取激活码?别玩了~";
                json.JSurl = "/";
                return(json.ToJson());
            }
            #endregion

            var tempuser = ((BlogUser)HttpContext.Current.Session[tempUserinfo]);
            var activate = HttpContext.Current.Request.Form["txt_activate"];//激活码

            #region 2.验证激活码  (更新缓存 发送通知邮件 清空无用session)
            if (activate.Trim() == Session[jihuoma].ToString().Trim()) //验证激活码
            {
                BLL.BaseBLL <BlogUser> user = new BLL.BaseBLL <BlogUser>();
                var objuser          = user.GetList(t => t.Id == tempuser.Id, isAsNoTracking: false).FirstOrDefault();
                var isEffectiveEmail = !string.IsNullOrEmpty(objuser.UserMail) && objuser.UserMail != "无效";//是否是有效邮箱(迁移用户是无效邮箱)
                if (null != objuser)
                {
                    objuser.IsLock   = false;
                    objuser.UserPass = isEffectiveEmail ? tempuser.UserPass.MD5().MD5() : defaulPass.MD5().MD5();
                    objuser.UserMail = tempuser.UserMail;
                    if (objuser.BlogUserInfo == null)
                    {
                        objuser.BlogUserInfo = new BlogUserInfo()
                        {
                            BlogUpNum = 0
                        };
                    }
                }
                user.save();
                #region bug 记录
                //BlogUsers objuser = new BlogUsers();
                //objuser.Id = id;
                //objuser.IsLock = false;
                // user.Up(objuser, "IsLock");  //这个方法 正常情况用没问题,如果先添加   然后修改就有问题  (不能用)
                #endregion
                bool islock = GetDataHelper.GetAllUser().Where(t => t.Id == tempuser.Id).FirstOrDefault().IsLock;
                if (!islock)
                {
                    #region 发送邮件 告知 激活成功

                    var tempSessionUser      = (BlogUser)Session[tempUserinfo];
                    var nickName             = string.IsNullOrEmpty(tempSessionUser.UserNickname) ? tempSessionUser.UserName : tempSessionUser.UserName;
                    Helper.EmailHelper email = new Helper.EmailHelper()
                    {
                        mailPwd     = s_mailPwd,
                        host        = s_host,
                        mailFrom    = s_mailFrom,
                        mailSubject = "欢迎您注册 嗨-博客",
                        mailBody    = EmailHelper.tempBody(nickName, "欢迎注册 嗨-博客",
                                                           "您注册的的帐号:" + objuser.UserName + "   密码是:" + (isEffectiveEmail ? tempuser.UserPass : defaulPass), "请您妥善保管~"),
                        mailToArray = new string[] { tempSessionUser.UserMail }
                    };

                    try
                    {
                        email.Send(t =>
                        {
                            LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + tempSessionUser.UserMail + "\r\nBody:" + t.Body, "发送成功的邮件");
                        },
                                   t =>
                        {
                            LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + tempSessionUser.UserMail + "\r\nBody:" + t.Body, "发送失败的邮件");
                        }
                                   );
                    }
                    catch (Exception)
                    { }

                    #endregion

                    Session[jihuoma]      = null;
                    Session[tempUserinfo] = null;

                    BLLSession.UserInfoSessioin = objuser;
                    return(new JSData()
                    {
                        Messg = "恭喜您~激活成功~",
                        State = EnumState.正常重定向,
                        JSurl = "/"
                    }.ToJson());
                }
                else
                {
                    return(new JSData()
                    {
                        Messg = "激活失败,请联系管理员~",
                        State = EnumState.失败
                    }.ToJson());
                }
            }
            #endregion

            return(new JSData()
            {
                Messg = "您输入的激活码错误,你可以重新激活~",
                State = EnumState.失败
            }.ToJson());
        }
Esempio n. 15
0
        public string Configure(ConfigureInput input)
        {
            var IsShowCSS = input.IsShowCSS == "on";
            var IsDisCSS  = input.IsDisCSS == "on";

            if (BLLSession.UserInfoSessioin == null)
            {
                return("您还没有登录 不能修改~");
            }
            try
            {
                //==============================================================================================================
                //遗留问题:
                //如下:如果 userinfobll.Up(BLLSession.UserInfoSessioin.BlogUserInfo)两次的话 报异常:[一个实体对象不能由多个 IEntityChangeTracker 实例引用]
                //那么 我只能 new一个新的对象 修改  然后 同时 BLLSession.UserInfoSessioin.BlogUserInfo里面的属性,不然 其他地方访问的话 是没有修改过来的值
                //==============================================================================================================
                var userinftemp = new BlogUserInfo(); //BLLSession.UserInfoSessioin.BlogUserInfo;
                BLL.BaseBLL <BlogUserInfo> userinfobll = new BaseBLL <BlogUserInfo>();
                if (input.TerminalType == "PC")       //如果是PC端
                {
                    userinftemp.IsShowCSS =
                        BLLSession.UserInfoSessioin.BlogUserInfo.IsShowCSS = IsShowCSS;
                    userinftemp.IsDisCSS =
                        BLLSession.UserInfoSessioin.BlogUserInfo.IsDisCSS = IsDisCSS;
                    userinftemp.Id =
                        BLLSession.UserInfoSessioin.BlogUserInfo.Id;
                    userinfobll.Updata(userinftemp, "IsShowCSS", "IsDisCSS");//"IsShowHTML",, "IsShowJS"
                }
                else
                {
                    userinftemp.IsShowMCSS =
                        BLLSession.UserInfoSessioin.BlogUserInfo.IsShowMCSS = IsShowCSS;
                    userinftemp.IsDisMCSS =
                        BLLSession.UserInfoSessioin.BlogUserInfo.IsDisMCSS = IsDisCSS;
                    userinftemp.Id =
                        BLLSession.UserInfoSessioin.BlogUserInfo.Id;
                    userinfobll.Updata(userinftemp, "IsShowMCSS", "IsDisMCSS");
                }

                GetDataHelper.GetAllUser().FirstOrDefault(t => t.Id == BLLSession.UserInfoSessioin.Id).BlogUserInfo
                    = BLLSession.UserInfoSessioin.BlogUserInfo;

                userinfobll.save();

                string path = FileHelper.defaultpath + "/MyConfigure/" + BLLSession.UserInfoSessioin.UserName + "/";
                FileHelper.CreatePath(path);
                if (input.conf_css.Length >= 40000 ||
                    input.conf_tail_html.Length >= 40000 ||
                    input.conf_first_html.Length >= 40000 ||
                    input.conf_side_html.Length >= 40000 ||
                    input.conf_js.Length >= 40000)
                {
                    return("您修改的内容字符过多~");
                }

                if (input.TerminalType == "PC")//如果是PC端
                {
                    FileHelper.SaveFile(path, "conf.css", input.conf_css);
                    FileHelper.SaveFile(path, "conf_side.txt", input.conf_side_html);
                    FileHelper.SaveFile(path, "conf_first.txt", input.conf_first_html);
                    FileHelper.SaveFile(path, "conf_tail.txt", input.conf_tail_html);
                    FileHelper.SaveFile(path, "conf.js", input.conf_js);
                }
                else
                {
                    FileHelper.SaveFile(path, "Mconf.css", input.conf_css);
                    FileHelper.SaveFile(path, "Mconf_side.txt", input.conf_side_html);
                    FileHelper.SaveFile(path, "Mconf_first.txt", input.conf_first_html);
                    FileHelper.SaveFile(path, "Mconf_tail.txt", input.conf_tail_html);
                    FileHelper.SaveFile(path, "Mconf.js", input.conf_js);
                }


                return("修改成功~");
            }
            catch (Exception ex)
            {
                LogSave.ErrLogSave("自定义样式出错", ex);
                return("修改失败~");
            }
        }
        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);
        }
        public JSData Login(BlogUser user, string ischeck)
        {
            JSData objJson  = new JSData();
            var    pass     = user.UserPass.MD5().MD5();
            var    listUser = GetDataHelper.GetAllUser(t => t.BlogUserInfo).Where(t => (t.UserName == user.UserName || t.UserMail == user.UserName) && t.UserPass == pass);

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

                //验证邮箱是否有效  无效则跳转到邮箱验证页面
                if (listUser.Where(t => t.UserMail == "无效" || string.IsNullOrEmpty(t.UserMail)).Count() > 0)
                {
                    objJson.State = EnumState.失败;
                    objJson.Messg = "检测到你注册的邮箱无效~请输入正确的邮箱~";
                    objJson.JSurl = "/UserManage/EmailValidation";
                }
                else if (listUser.Where(t => t.IsLock == true).Count() > 0)//用户是否是激活状态 否:发送激活码 并跳转到激活页面
                {
                    GetActivate(ref objJson);
                }
                else//登录成功
                {
                    #region 登录成功
                    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")
                    {
                        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(objJson);
        }
Esempio n. 18
0
        /// <summary>
        /// 提交内容的编辑或修改
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public JSData ReleasePost(ReleaseInput input)
        {
            JSData jsdata = new JSData();

            #region 数据验证
            if (null == BLL.Common.BLLSession.UserInfoSessioin)
            {
                jsdata.Messg = "您还未登录~";
            }
            else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock)
            {
                jsdata.Messg = "您的账户未激活,暂只能评论。~";
            }
            else if (string.IsNullOrEmpty(input.Content))
            {
                jsdata.Messg = "内容不能为空~";
            }

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

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

            //获取得 文章 类型集合 对象
            var typelist = new List <int>();
            if (!string.IsNullOrEmpty(input.Chk_type))
            {
                foreach (string type in input.Chk_type.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.BaseBLL <BlogType>().GetList(t => typelist.Contains(t.Id), isAsNoTracking: false).ToList();

            //获取得 文章 tag标签集合 对象
            //old
            var oldtaglist    = string.IsNullOrEmpty(input.Oldtag) ? new List <string>() : input.Oldtag.Split(',').ToList();
            var myOldTagTypes = new BLL.BaseBLL <BlogTag>().GetList(t => t.BlogUser.Id == userid && oldtaglist.Contains(t.TagName), isAsNoTracking: false).ToList();
            //new
            var newtaglist = input.Newtag.GetValueOrEmpty().Split(',').ToList();
            AddTag(newtaglist, userid);//保存到数据库
            var myNweTagTypes = new BLL.BaseBLL <BlogTag>().GetList(t => t.BlogUser.Id == userid && newtaglist.Contains(t.TagName), isAsNoTracking: false).ToList();
            myNweTagTypes.ForEach(t => myOldTagTypes.Add(t));


            if (input.Blogid > 0)                                                                       //如果有 blogid 则修改
            {
                if (sessionuserid == blogtemp.User.Id || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户
                {
                    blogtemp.Content      = input.Content;
                    blogtemp.Title        = input.Title;
                    blogtemp.IsShowMyHome = input.Isshowmyhome;
                    blogtemp.IsShowHome   = input.Isshowhome;
                    blogtemp.Types.Clear();//更新之前要清空      不如会存在主外键约束异常
                    blogtemp.Types = myBlogTypes;
                    blogtemp.Tags.Clear();
                    blogtemp.Tags         = myOldTagTypes;
                    blogtemp.IsDelte      = false;
                    blogtemp.IsForwarding = false;
                    jsdata.Messg          = "修改成功~";
                }
                else
                {
                    jsdata.Messg = "您没有编辑此博文的权限~";
                    jsdata.JSurl = "/";
                    jsdata.State = EnumState.失败;
                    return(jsdata);
                }
            }
            else  //否则 新增
            {
                var blogfirst = blogbll.GetList(t => t.User.Id == sessionuserid).OrderByDescending(t => t.Id).FirstOrDefault();

                if (null != blogfirst && blogfirst.Title == input.Title)
                {
                    jsdata.Messg = "不能同时发表两篇一样标题的文章~";
                }
                else
                {
                    var bloguser = new BLL.BaseBLL <BlogUser>().GetList(t => t.Id == BLLSession.UserInfoSessioin.Id, isAsNoTracking: false).FirstOrDefault();

                    blogtemp = new BlogInfo()
                    {
                        User           = bloguser,
                        Content        = input.Content,
                        Title          = input.Title,
                        BlogUpTime     = DateTime.Now,
                        BlogCreateTime = DateTime.Now,
                        IsShowMyHome   = input.Isshowmyhome,
                        IsShowHome     = input.Isshowhome,
                        Types          = myBlogTypes,
                        Tags           = myOldTagTypes,
                        IsDelte        = false,
                        IsForwarding   = false
                    };
                    blogbll.Insert(blogtemp);
                    jsdata.Messg = "发布成功~";
                }
            }

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

                jsdata.State = EnumState.成功;
                jsdata.JSurl = "/" + GetDataHelper.GetAllUser().Where(t => t.Id == blogtemp.User.Id).First().UserName + "/" + blogtemp.Id + ".html";
                return(jsdata);
            }

            jsdata.Messg = string.IsNullOrEmpty(jsdata.Messg) ? "操作失败~" : jsdata.Messg;
            jsdata.State = EnumState.失败;
            return(jsdata);
        }
        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;
        }
        /// <summary>
        /// 迁移cnblog评论
        /// </summary>
        /// <param name="BlogsId">嗨博客 博客id</param>
        /// <param name="BlogUsersId">嗨博客  评论博客用户id(因为迁移评论者 没有id 所以都默认为1)</param>
        /// <param name="postId">cnblog 博客id</param>int BlogUsersId = 1,
        /// <param name="blogApp">cnblog 博客用户名</param>
        public string testJumonyParser(int BlogsId = 1, string postId = "4368417", string blogApp = "zhaopei")
        {
            bool isNext = true;
            int  i      = 0;

            var BlogUsersId = 1;

            BLL.BlogUsersSetBLL userbll = new BlogUsersSetBLL();
            var usertemp = GetDataHelper.GetAllUser().Where(t => t.UserName == " ").FirstOrDefault();

            if (null == usertemp)
            {
                var user = new Blogs.ModelDB.BlogUsersSet()
                {
                    UserName   = "******",
                    UserPass   = "******",
                    IsDel      = false,
                    IsLock     = false,
                    UserMail   = "无效",
                    CreateTime = DateTime.Now,
                    UserInfo   = new ModelDB.UserInfo()
                };
                userbll.Add(user);
                userbll.save(false);
                BlogUsersId = user.Id;
            }
            else
            {
                BlogUsersId = usertemp.Id;
            }

            //List<BlogCommentSet> blogcommen = new List<BlogCommentSet>();
            BlogCommentSetBLL blogcommenbll = new BlogCommentSetBLL();

            while (isNext)
            {
                i++;
                var url        = "http://www.cnblogs.com/mvc/blog/GetComments.aspx?postId=" + postId + "&blogApp=" + blogApp + "&pageIndex=" + i;
                var jumony     = new JumonyParser();
                var htmlSource = jumony.LoadDocument(url).InnerHtml();

                JavaScriptSerializer _jsSerializer = new JavaScriptSerializer();
                CnBlogComments       comm          = _jsSerializer.Deserialize <CnBlogComments>(htmlSource);
                var commentsHtml = jumony.Parse(comm.commentsHtml);
                var pager        = commentsHtml.Find("div.pager").FirstOrDefault();
                if (null != pager)
                {
                    var Next = pager.Find("*").LastOrDefault().InnerText();
                    if (Next != "Next >")
                    {
                        isNext = false;
                    }
                }
                else
                {
                    isNext = false;
                }

                var listComment = commentsHtml.Find("div.feedbackItem").ToList();
                foreach (var item in listComment)
                {
                    var commentDataNode = item.Find("div.feedbackListSubtitle span.comment_date").FirstOrDefault();  //
                    var commentData     = DateTime.Parse(commentDataNode.InnerText());
                    var commentUserNode = item.Find("div.feedbackListSubtitle a[target='_blank']").FirstOrDefault();
                    var commentUser     = commentUserNode.InnerText();
                    var Content         = item.Find("div.blog_comment_body").FirstOrDefault().InnerText();

                    blogcommenbll.Add(
                        new BlogCommentSet()
                    {
                        BlogsId       = BlogsId,
                        CommentID     = -1,
                        IsDel         = false,
                        Content       = Content,
                        CreateTime    = commentData,
                        ReplyUserName = commentUser,
                        BlogUsersId   = BlogUsersId,
                        IsInitial     = true
                    }
                        );
                }
            }

            try
            {
                blogcommenbll.save(false);
            }
            catch (Exception)
            { }
            return("ok");
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <returns></returns>
        public JSData Regis(BlogUser blog)
        {
            var json = new JSData();

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

            BlogUser user = new BlogUser()
            {
                UserName     = blog.UserName,
                UserPass     = blog.UserPass,
                UserMail     = blog.UserMail,
                UserNickname = blog.UserNickname,
                IsLock       = true,
                BlogUserInfo = new BlogUserInfo()
            };
            HttpContext.Current.Session[tempUserinfo] = user;
            JSData jsdata = new JSData();

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

            #region 3.邮件发送成功
            else
            {
                BLL.BaseBLL <BlogUser> userBll = new BLL.BaseBLL <BlogUser>();
                userBll.Insert(user);
                //在保存前 再做次验证
                if (GetDataHelper.GetAllUser().Where(t => t.UserName == blog.UserName || t.UserMail == blog.UserMail).Count() > 0)
                {
                    json.Messg = "此用户名后邮箱已经存在~";
                    json.State = EnumState.失败;
                    return(json);
                }
                else
                {
                    userBll.save();
                }

                //验证是否注册成功 (并重新加载缓存信息)
                if (GetDataHelper.GetAllUser().Where(t => t.UserName == blog.UserName && t.UserPass == blog.UserPass).Count() > 0)
                {
                    BLLSession.UserInfoSessioin = user;
                    json.JSurl = "/UserManage/Activate";
                    json.Messg = "请查收邮件,完成账号激活~";
                }
                else
                {
                    json.Messg = "注册失败";
                    json.State = EnumState.失败;
                    return(json);
                }
            }
            #endregion

            return(json);
        }