Exemplo n.º 1
0
        /// <summary>
        /// 创建提醒消息
        /// </summary>
        /// <param name="receiveid"></param>
        /// <param name="content"></param>
        /// <param name=""></param>
        public static void CreateNotify(string receiveid, string content, string senderid = AdminId)
        {
            var msg = new SiteMessage()
            {
                Content   = content,
                IsHandle  = false,
                MsgType   = NotifyType,
                ReceiveID = receiveid,
                SenderID  = senderid
            };

            InsertSiteMessage(msg);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建接受拒绝消息
        /// </summary>
        /// <param name="receiveid"></param>
        /// <param name="content"></param>
        /// <param name="YesUrl"></param>
        /// <param name="NoUrl"></param>
        /// <param name="senderid"></param>
        public static void CreateYesNo(string receiveid, string content, string YesUrl, string NoUrl, string senderid = AdminId)
        {
            var msg = new SiteMessage()
            {
                Content   = content,
                IsHandle  = false,
                MsgType   = YesNoType,
                ReceiveID = receiveid,
                SenderID  = senderid,
                AcceptURL = YesUrl,
                RefuseURL = NoUrl
            };

            InsertSiteMessage(msg);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 收录到主题
        /// </summary>
        /// <param name="topicId"></param>
        /// <param name="articleId"></param>
        /// <returns></returns>
        public static bool PutToTopic(string topicOwnerid, string articleId)
        {
            IMongoQuery OwnerQuery = Query.EQ(nameof(Topic.OwnerId), topicOwnerid);
            var         topic      = MongoDbRepository.GetFirstRec <Topic>(OwnerQuery);

            if (topic == null)
            {
                return(false);
            }
            if (IsExist(topic.Sn, articleId))
            {
                return(false);
            }
            //是否能够被收录
            var article = Article.GetArticleBySn(articleId);

            if (!article.IsTopicable)
            {
                return(false);
            }
            if (article.IsNeedTopicApproval)
            {
                var topicarticle = new TopicArticle()
                {
                    ArticleID     = articleId,
                    TopicID       = topic.Sn,
                    PublishStatus = ApproveStatus.Pending
                };
                InsertTopicArticle(topicarticle);
                var user       = UserInfo.GetUserInfoBySn(topicOwnerid);
                var parm       = "TopicOwnerId=" + topicOwnerid + "&ArticleId=" + articleId;
                var articleurl = "<a href = '/Article/Index?ArticleId=" + article.Sn + "'>" + article.Title + "</a>";
                var topicurl   = "<a href = '/Author/TopicPage?accountid=" + topicOwnerid + "'>" + topic.Title + "</a>";
                SiteMessage.CreateYesNo(article.OwnerId, "[" + user.NickName + "]请求收录您的文章:[" + articleurl + "]到他的专题" + topicurl, "/Author/AcceptTopic?" + parm, "/Author/RefuseTopic?" + parm, topicOwnerid);
            }
            else
            {
                var topicarticle = new TopicArticle()
                {
                    ArticleID     = articleId,
                    TopicID       = topic.Sn,
                    PublishStatus = ApproveStatus.Accept
                };
                InsertTopicArticle(topicarticle);
            }
            return(true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 修改消息
 /// </summary>
 /// <param name="OldSiteMessage"></param>
 public static void UpdateSiteMessage(SiteMessage OldSiteMessage)
 {
     MongoDbRepository.UpdateRec(OldSiteMessage);
 }
Exemplo n.º 5
0
 /// <summary>
 /// 删除消息
 /// </summary>
 /// <param name="DropSiteMessage"></param>
 public static void DropSiteMessage(SiteMessage DropSiteMessage)
 {
     MongoDbRepository.DeleteRec(DropSiteMessage);
 }
Exemplo n.º 6
0
 /// <summary>
 /// 插入消息
 /// </summary>
 /// <param name="Newsitemessage"></param>
 /// <returns>序列号</returns>
 public static string InsertSiteMessage(SiteMessage NewSiteMessage)
 {
     return(MongoDbRepository.InsertRec(NewSiteMessage));
 }
Exemplo n.º 7
0
        /// <summary>
        /// 获得用户信息
        /// </summary>
        /// <param name="qqOauthInfo"></param>
        /// <param name="openID"></param>
        /// <returns></returns>
        public static UserInfo GetUserInfo(QQOauthInfo qqOauthInfo, string openID)
        {
            string urlGetInfo  = string.Format(@"https://graph.qq.com/user/get_user_info?access_token={0}&oauth_consumer_key={1}&openid={2}", qqOauthInfo.AccessToken, appID, openID);
            string resUserInfo = GetUrlResponse(urlGetInfo, Encoding.UTF8);

            InfraStructure.Log.InfoLog.Log("SYSTEM", "GetUserInfo", "GetUserInfo", resUserInfo);
            dynamic   obj     = JsonConvert.DeserializeObject(resUserInfo);
            QQAccount qqlogin = new QQAccount()
            {
                nickname = obj.nickname,
                //使用40*40的QQ头像图片作为标准头像
                figureurl  = obj.figureurl_qq_1,
                gender     = obj.gender,
                OpenID     = openID,
                LastAccess = DateTime.Now
            };
            var qqAccount = GetQQAccountByOpenId(qqlogin.OpenID);

            if (qqAccount == null)
            {
                //没有该用户,添加
                var      qqId     = InsertQQAccount(qqlogin);
                UserInfo userinfo = new UserInfo()
                {
                    RegisterAccountID = qqId,
                    TopicList         = new List <string>(),
                    TagList           = new List <string>(),
                    RegisterMethod    = QQ,
                    NickName          = qqlogin.nickname,
                    Avatar_url        = qqlogin.figureurl,
                    Privilege         = UserType.Normal,
                    ContainTag        = string.Empty,
                    AntiTag           = string.Empty,
                    Catalog           = new List <string>(),
                    Level             = new List <ArticleLevel>()
                };
                var userinfoId = UserInfo.InsertUserInfo(userinfo);
                if (userinfoId == 1.ToString(SnFormat))
                {
                    //第一个用户是管理员(该代码仅仅被执行一次)
                    userinfo.Privilege = UserType.Admin;
                    UserInfo.UpdateUserInfo(userinfo);
                }
                //更新UserInfoID
                qqlogin.UserInfoID = userinfoId;
                UpdateQQAccount(qqlogin);

                //Welcome
                var articleurl = "<a href = '/Article/Index?ArticleId=00000006'>网站使用方法</a>";
                SiteMessage.CreateNotify(userinfoId, "欢迎加入CodeSnippet.info,请阅读[" + articleurl + "]");
                return(userinfo);
            }
            else
            {
                //用新的信息替换旧的信息
                qqAccount.figureurl = qqlogin.figureurl;
                qqAccount.nickname  = qqlogin.nickname;
                UpdateQQAccount(qqAccount);

                var userinfo = GetUserInfoByRegMethodInnerId(qqAccount.Sn);
                userinfo.Avatar_url = qqlogin.figureurl;
                userinfo.NickName   = qqlogin.nickname;

                //防御性代码
                if (userinfo.TagList == null)
                {
                    userinfo.TagList = new List <string>();
                }
                if (userinfo.TopicList == null)
                {
                    userinfo.TopicList = new List <string>();
                }
                if (userinfo.Catalog == null)
                {
                    userinfo.Catalog = new List <string>();
                }
                if (userinfo.Level == null)
                {
                    userinfo.Level = new List <ArticleLevel>();
                }
                if (userinfo.ContainTag == null)
                {
                    userinfo.ContainTag = string.Empty;
                }
                if (userinfo.AntiTag == null)
                {
                    userinfo.AntiTag = string.Empty;
                }

                UserInfo.UpdateUserInfo(userinfo);
                return(userinfo);
            }
        }
        /// <summary>
        /// 获得用户
        /// </summary>
        /// <param name="Code"></param>
        /// <returns></returns>
        public static UserInfo GetUserInfo(string Code)
        {
            var gitlogin = GetGithubAccount(Code);
            //获得GitAccount
            GithubAccount gitAccount = GetGitAccountByLogin(gitlogin.Login);

            if (gitAccount == null)
            {
                //没有该用户,添加
                var      GitId    = InsertGithubAccount(gitlogin);
                UserInfo userinfo = new UserInfo()
                {
                    RegisterAccountID = GitId,
                    TopicList         = new List <string>(),
                    TagList           = new List <string>(),
                    //具有50个追随者的普通是特约作者
                    Privilege      = gitlogin.Followers >= 50 ? UserType.Author : UserType.Normal,
                    RegisterMethod = Github,
                    NickName       = gitlogin.Name,
                    Avatar_url     = gitlogin.Avatar_url,
                    ContainTag     = string.Empty,
                    AntiTag        = string.Empty,
                    Catalog        = new List <string>(),
                    Level          = new List <ArticleLevel>()
                };
                var userinfoId = UserInfo.InsertUserInfo(userinfo);
                if (userinfoId == 1.ToString(SnFormat))
                {
                    //第一个用户是管理员(该代码仅仅被执行一次)
                    userinfo.Privilege = UserType.Admin;
                    UserInfo.UpdateUserInfo(userinfo);
                }
                //更新UserInfoID
                gitlogin.UserInfoID = userinfoId;
                UpdateGithubAccount(gitlogin);

                //Welcome
                var articleurl = "<a href = '/Article/Index?ArticleId=00000006'>网站使用方法</a>";
                SiteMessage.CreateNotify(userinfoId, "欢迎加入CodeSnippet.info,请阅读[" + articleurl + "]");
                return(userinfo);
            }
            else
            {
                //用新的信息替换旧的信息
                gitAccount.Avatar_url = gitlogin.Avatar_url;
                gitAccount.Blog       = gitlogin.Blog;
                gitAccount.Company    = gitlogin.Company;
                gitAccount.Email      = gitlogin.Email;
                gitAccount.Followers  = gitlogin.Followers;
                gitAccount.Following  = gitlogin.Following;
                gitAccount.Html_url   = gitlogin.Html_url;
                gitAccount.Location   = gitlogin.Location;
                gitAccount.Name       = gitlogin.Name;
                UpdateGithubAccount(gitAccount);
                var userinfo = GetUserInfoByRegMethodInnerId(gitAccount.Sn);
                //这里必须返回gitAccount,因为gitlogin没有UserInfoID
                userinfo.Avatar_url = gitlogin.Avatar_url;
                userinfo.NickName   = gitlogin.Name;

                //防御性代码
                if (userinfo.TagList == null)
                {
                    userinfo.TagList = new List <string>();
                }
                if (userinfo.TopicList == null)
                {
                    userinfo.TopicList = new List <string>();
                }
                if (userinfo.Catalog == null)
                {
                    userinfo.Catalog = new List <string>();
                }
                if (userinfo.Level == null)
                {
                    userinfo.Level = new List <ArticleLevel>();
                }
                if (userinfo.ContainTag == null)
                {
                    userinfo.ContainTag = string.Empty;
                }
                if (userinfo.AntiTag == null)
                {
                    userinfo.AntiTag = string.Empty;
                }

                //具有50个追随者的普通人是特约作者
                if (gitlogin.Followers >= 50)
                {
                    if (userinfo.Privilege == UserType.Normal)
                    {
                        userinfo.Privilege = UserType.Author;
                    }
                }
                UserInfo.UpdateUserInfo(userinfo);
                return(userinfo);
            }
        }