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 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 #4
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>
        /// 注册
        /// </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");
        }