Exemple #1
0
        /// <summary>
        /// 自定义 特殊页面 公共方法 (弃用)
        /// </summary>
        /// <param name="str"></param>
        /// <param name="messid"></param>
        private void Forum(string str, ref int messid)
        {
            #region 检测是否存在 admin 用户

            if (adminuserid <= 0)
            {
                BLL.BaseBLL <BlogUser> userbll = new BLL.BaseBLL <BlogUser>();
                var user = userbll.GetList(t => t.UserName == admin).FirstOrDefault();
                if (null == user)
                {
                    var usertemp = new BlogUser()
                    {
                        UserName     = admin,
                        UserPass     = "******".MD5().MD5(),
                        IsDelte      = false,
                        IsLock       = false,
                        UserNickname = "",
                        BlogUserInfo = new BlogUserInfo()
                    };
                    userbll.Insert(usertemp);
                    userbll.save(false);
                    adminuserid = usertemp.Id;
                }
                else
                {
                    adminuserid = user.Id;
                }
            }

            #endregion

            #region 是否存在 自定义 特殊页面 (返回 blogid)
            if (messid == 0)
            {
                BLL.BaseBLL <BlogInfo> blogbll = new BLL.BaseBLL <BlogInfo>();
                var blog = blogbll.GetList(t => t.Title == str).FirstOrDefault();
                if (null == blog)
                {
                    var blogtemp = new BlogInfo()
                    {
                        Id   = 0,
                        User = new BlogUser()
                        {
                            Id = adminuserid
                        },
                        IsDelte = false,
                        Title   = str
                    };
                    blogbll.Insert(blogtemp);
                    blogbll.save(false);
                    //GetDataHelper.GetAllUserInfo(true);//更新缓存
                    messid = blogtemp.Id;
                }
                else
                {
                    messid = blog.Id;
                }
            }
            #endregion
        }
        private void MyBegin()
        {
            try
            {
                //设置日志存放路径
                LogConfig.logFilePath = HttpContext.Current.Server.MapPath("~/") + @"\Log\";
                Blogs.Helper.FileHelper.defaultpath = HttpContext.Current.Server.MapPath("~/");

                BLL.BaseBLL <BlogUser> userbll = new BLL.BaseBLL <BlogUser>();
                var isbegin = userbll.GetList(t => true).Count() > 0;
                if (!isbegin)
                {
                    var user = new BlogUser()
                    {
                        UserName     = "******",
                        UserPass     = "******",
                        IsDelte      = false,
                        IsLock       = false,
                        UserMail     = "无效",
                        CreationTime = DateTime.Now,
                        BlogUserInfo = new BlogUserInfo()
                    };
                    userbll.Insert(user);
                    userbll.save(false);
                }

                DemoController.GetData();
            }
            catch (Exception) { }
        }
Exemple #3
0
        private void SaveReadNum(BlogInfo blogobj, string md5)
        {
            LogSave.TrackLogSave(GetUserDistinguish(Request, false), "ReadBlogLog");
            var isup = true;

            BLL.BaseBLL <BlogInfo> blogbll = new BLL.BaseBLL <BlogInfo>();
            var blogtemp = blogbll.GetList(t => t.Id == blogobj.Id, isAsNoTracking: false).FirstOrDefault();

            if (blogtemp.ReadNum == null)
            {
                blogtemp.ReadNum = 1;
            }
            else if (!IsRead(blogtemp, md5))
            {
                blogtemp.ReadNum++;
            }
            else
            {
                isup = false;
            }
            if (isup)
            {
                blogbll.save();
            }
        }
Exemple #4
0
 private int GetTagId(string tagname, string userName)
 {
     BLL.BaseBLL <BlogTag> blogtag = new BLL.BaseBLL <BlogTag>();
     try
     {
         var blogtagmode = blogtag.GetList(t => t.TagName == tagname);
         if (blogtagmode.Count() >= 1)
         {
             return(blogtagmode.FirstOrDefault().Id);
         }
         else
         {
             var tmepUserid = GetUserId(userName);
             var user       = new BLL.BaseBLL <BlogUser>().GetList(t => t.Id == tmepUserid, isAsNoTracking: false).FirstOrDefault();
             blogtag.Insert(new BlogTag()
             {
                 TagName  = tagname,
                 IsDelte  = false,
                 BlogUser = user// new BlogUser { Id = GetUserId(userName), IsLock = false, BlogUserInfo = new BlogUserInfo() },
             });
             blogtag.save();
             return(GetTagId(tagname, userName));
         }
     }
     catch (Exception ex)
     {
         throw;
         return(-1);
     }
 }
Exemple #5
0
        /// <summary>
        /// 自定义 特殊页面 公共方法
        /// </summary>
        /// <param name="str">BlogTitle名字</param>
        /// <param name="pageName">存在MyPageId的KEY名</param>
        private void Forum(string str, string pageName)
        {
            #region 检测是否存在 admin 用户
            BLL.BaseBLL <BlogUser> userbll = new BLL.BaseBLL <BlogUser>();
            if (adminuserid <= 0)
            {
                var user = userbll.GetList(t => t.UserName == admin).FirstOrDefault();
                if (null == user)
                {
                    var usertemp = new BlogUser()
                    {
                        UserName     = admin,
                        UserPass     = "******".MD5().MD5(),
                        IsDelte      = false,
                        IsLock       = false,
                        UserNickname = "",
                        UserMail     = "无效",
                        BlogUserInfo = new BlogUserInfo()
                    };
                    userbll.Insert(usertemp);
                    userbll.save(false);
                    adminuserid = usertemp.Id;
                }
                else
                {
                    adminuserid = user.Id;
                }
            }

            #endregion

            #region 是否存在 自定义 特殊页面 (返回 blogid)
            if (MyPageId[pageName] == 0)
            {
                BLL.BaseBLL <BlogInfo> blogbll = new BLL.BaseBLL <BlogInfo>();
                var blog = blogbll.GetList(t => t.Title == str).FirstOrDefault();
                if (null == blog)
                {
                    var bloguser = userbll.GetList(t => t.Id == adminuserid, isAsNoTracking: false).FirstOrDefault();
                    var blogtemp = new BlogInfo()
                    {
                        Id = 0,
                        //BlogUser = new BlogUser() { Id = adminuserid },
                        User    = bloguser,
                        IsDelte = false,
                        Title   = str
                    };
                    blogbll.Insert(blogtemp);
                    blogbll.save();
                    // CacheData.GetAllUserInfo(true);//更新缓存
                    MyPageId[pageName] = blogtemp.Id;
                }
                else
                {
                    MyPageId[pageName] = blog.Id;
                }
            }
            #endregion
        }
        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());
        }
        /// <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);
        }
        public string ThirdLoginCallback(string code, string loginType = "qq")
        {
            //第三步:获取开放平台授权令牌
            IOAuthClient oauthClient  = GetOAuthClient(loginType);
            AuthToken    accessToken  = oauthClient.GetAccessTokenByAuthorizationCode(code);
            dynamic      oauthProfile = oauthClient.User.GetUserInfo();

            if (accessToken != null && !string.IsNullOrEmpty(oauthClient.Token.User.OAuthId))
            {
                BLL.BaseBLL <BlogUserInfo> userInfo = new BLL.BaseBLL <BlogUserInfo>();
                var userInfoMode = userInfo.GetList(t => t.OAuthId == oauthClient.Token.User.OAuthId && t.OAuthName == loginType).FirstOrDefault();
                if (null == userInfoMode)
                {
                    BLL.BaseBLL <BlogUser> user = new BLL.BaseBLL <BlogUser>();
                    user.Insert(new BlogUser()
                    {
                        IsLock       = true,
                        UserMail     = "无效",
                        UserName     = oauthClient.Token.User.OAuthId + "_" + loginType,
                        UserNickname = oauthClient.Token.User.Nickname,
                        UserPass     = "******".MD5().MD5(),
                        IsDelte      = false,
                        BlogUserInfo = new BlogUserInfo()
                        {
                            OAuthId   = oauthClient.Token.User.OAuthId,
                            OAuthName = loginType,
                            BlogUpNum = 0,
                            IsDelte   = false
                        }
                    });
                    user.save(false);
                    userInfoMode = userInfo.GetList(t => t.OAuthId == oauthClient.Token.User.OAuthId && t.OAuthName == loginType).FirstOrDefault();
                    //BLL.Common.CacheData.GetAllUserInfo(true);
                }

                #region 设置cookie(等于设置了session,因为读session的时候会检测cookie)
                var        userTemp = userInfoMode.BlogUser;
                HttpCookie Cookie   = CookiesHelper.GetCookie("userInfo");
                if (Cookie == null)
                {
                    Cookie = new HttpCookie("userInfo");
                    Cookie.Values.Add("userName", userTemp.UserName);
                    Cookie.Values.Add("userPass", "pass");
                    //设置Cookie过期时间
                    Cookie.Expires = DateTime.Now.AddDays(365);
                    CookiesHelper.AddCookie(Cookie);
                }
                else
                {
                    if (!Cookie.Values["userName"].Equals(userTemp.UserName))
                    {
                        CookiesHelper.SetCookie("userInfo", "userName", userTemp.UserName);
                    }
                    if (!Cookie.Values["userPass"].Equals("pass"))
                    {
                        CookiesHelper.SetCookie("userInfo", "userPass", "pass");
                    }
                }
                //BLLSession.UserInfoSessioin = userInfoMode.BlogUser;
                #endregion

                return("ok");
            }
            return("no");
        }