Ejemplo n.º 1
0
 /// <summary>
 /// 修改QQ帐户信息
 /// </summary>
 /// <param name="OldQQAccount"></param>
 public static void UpdateQQAccount(QQAccount OldQQAccount)
 {
     MongoDbRepository.UpdateRec(OldQQAccount);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 插入QQ帐户信息
 /// </summary>
 /// <param name="Newqqaccount"></param>
 /// <returns>序列号</returns>
 public static string InsertQQAccount(QQAccount NewQQAccount)
 {
     return(MongoDbRepository.InsertRec(NewQQAccount));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 删除QQ帐户信息
 /// </summary>
 /// <param name="DropQQAccount"></param>
 public static void DropQQAccount(QQAccount DropQQAccount)
 {
     MongoDbRepository.DeleteRec(DropQQAccount);
 }
Ejemplo n.º 4
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);
            }
        }