예제 #1
0
        //用户信息
        public ActionResult UserInfo()
        {
            ViewBag.ClientID = ConfigurationManager.AppSettings["client_id"];
            //开发用OAuth跳转至changetolocalhost.com,修改changetolocalhost.com为localhost:2221完成本地OAuth登录
#if Debug
            ViewBag.Domain = "changetolocalhost.com";
#endif
#if Release
            ViewBag.Domain = "objnull.com";
#endif
            if (CurrentUser != null)
            {
                ViewBag.User     = CurrentUser;
                ViewBag.MsgCount = MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_CMsg + CurrentUser.ID)
                                   + MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_RMsg + CurrentUser.ID) + MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_SysMsg + CurrentUser.ID);
                if (string.IsNullOrEmpty(HttpContext.ReadCookie("LastLogin")))
                {
                    NullUser user = NullUserDataSvc.GetByID(CurrentUser.ID);
                    user.LastLoginDate = DateTime.Now;
                    user.LastLoginIP   = HttpContext.Request.UserHostAddress;
                    NullUserDataSvc.Update(user);
                    HttpContext.WriteCookie("LastLogin", DateTime.Now.ToString(), DateTime.Now.AddDays(1).Date);
                }
            }
            return(PartialView());
        }
예제 #2
0
        public ActionResult UserPage(int pageSize, int pageNum = 1, string condition = "")
        {
            int totalCount;

            if (string.IsNullOrEmpty(condition))
            {
                ViewBag.UserList = NullUserDataSvc.GetPagedEntitys(ref pageNum, pageSize, u => true, u => u.InsertDate, true, out totalCount).ToList();
            }
            else
            {
                Guid id = Guid.Empty;
                if (Guid.TryParse(condition, out id))
                {
                    ViewBag.UserList = NullUserDataSvc.GetPagedEntitys(ref pageNum, pageSize, u => u.ID == id, u => u.InsertDate, true, out totalCount).ToList();
                }
                else
                {
                    ViewBag.UserList = NullUserDataSvc.GetPagedEntitys(ref pageNum, pageSize, u => u.GitHubLogin.Contains(condition), u => u.InsertDate, true, out totalCount).ToList();
                }
            }
            ViewBag.TotalCount    = totalCount;
            ViewBag.CurrentPage   = pageNum;
            ViewBag.DisabledUsers = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers);
            return(View());
        }
예제 #3
0
        //个人主页
        public ActionResult UserProfile(string id = null)
        {
            Guid     userID = id == null ? CurrentUser.ID : Guid.Parse(id);
            NullUser user   = NullUserDataSvc.GetByID(userID);

            ViewBag.User = user;

            ViewBag.Login = CurrentUser != null;
            ViewBag.Owner = ViewBag.Login ? userID == CurrentUser.ID : false;
            if (ViewBag.Login)
            {
                NullUser cuser = NullUserDataSvc.GetByID(CurrentUser.ID);
                ViewBag.Token   = cuser.GitHubAccessToken;
                ViewBag.ShowPro = false;
                string key = MyRedisKeys.Pre_UserRecord + CurrentUser.ID;
                IEnumerable <UserRecord> userRecords = MyRedisDB.GetSet <UserRecord>(key);
                if (userRecords.Count() == 0)
                {
                    ViewBag.ShowPro = true;
                }
                else if (userRecords.Where(r => r.ObjID == userID && r.type == (int)EnumRecordType.点赞).Count() == 0)
                {
                    ViewBag.ShowPro = true;
                }
            }

            return(View());
        }
예제 #4
0
        //用户加赞
        public void ProUser(Guid id)
        {
            NullUser user = NullUserDataSvc.GetByID(id);

            user.ProCount += 1;
            NullUserDataSvc.Update(user);
        }
예제 #5
0
        //更新账号
        public ActionResult UpdateInfo()
        {
            NullUser user = NullUserDataSvc.GetByID(CurrentUser.ID);

            if (UpdateUserInfo("github", user.GitHubAccessToken))
            {
                return(Json(new { msg = "done" }));
            }
            else
            {
                return(Json(new { msg = "error" }));
            }
        }
예제 #6
0
 //用户信息
 public ActionResult UserInfo()
 {
     if (CurrentUser != null)
     {
         ViewBag.User     = CurrentUser;
         ViewBag.MsgCount = MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_CMsg + CurrentUser.ID)
                            + MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_RMsg + CurrentUser.ID) + MyRedisDB.RedisDB.SetLength(MyRedisKeys.Pre_SysMsg + CurrentUser.ID);
         if (string.IsNullOrEmpty(HttpContext.ReadCookie("LastLogin")))
         {
             NullUser user = NullUserDataSvc.GetByID(CurrentUser.ID);
             user.LastLoginDate = DateTime.Now;
             user.LastLoginIP   = HttpContext.Request.UserHostAddress;
             NullUserDataSvc.Update(user);
             HttpContext.WriteCookie("LastLogin", DateTime.Now.ToString(), DateTime.Now.AddDays(1).Date);
         }
     }
     return(PartialView());
 }
예제 #7
0
        public ActionResult SetEmail(string email)
        {
            NullUser user = NullUserDataSvc.GetByID(CurrentUser.ID);

            if (string.IsNullOrEmpty(email))
            {
                user.Email = email;
                NullUserDataSvc.Update(user);
                return(Json(new { msg = "done" }));
            }
            if (email.Length > 100)
            {
                return(Json(new { msg = "邮箱最多100个字符" }));
            }
            Regex re = new Regex(@"[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?");

            if (!re.IsMatch(email))
            {
                return(Json(new { msg = "邮箱格式不正确" }));
            }
            user.Email = email;
            NullUserDataSvc.Update(user);
            return(Json(new { msg = "done" }));
        }
예제 #8
0
        //添加用户或更新用户信息
        public bool UpdateUserInfo(string loginType, string token)
        {
            if (loginType == "github")
            {
                GitHubUser githubUser = GitHub.GetGitHubUser(token);
                if (githubUser.id == 0)
                {
                    return(false);
                }
                NullUser user = NullUserDataSvc.GetByCondition(u => u.GitHubID == githubUser.id).FirstOrDefault();
                if (user == null)
                {
                    user                   = new NullUser();
                    user.LoginType         = "github";
                    user.GitHubAccessToken = token;
                    user.Name              = githubUser.name;
                    user.AvatarUrl         = githubUser.avatar_url;
                    user.GitHubLogin       = githubUser.login;
                    user.GitHubID          = githubUser.id;
                    user.Role              = (int)EnumUserRole.普通;
                    user.Email             = githubUser.email;
                    user.FollowingCount    = githubUser.following;
                    user.FollowerCount     = githubUser.followers;
                    NullUserDataSvc.Add(user);

                    //用关注人数小于500的机器人账号关注普通用户
                    if (user.Email == null || (user.Email != null && !user.Email.EndsWith("objnull.com")))
                    {
                        List <NullUser> robots = NullUserDataSvc.GetByCondition(u => u.Email.EndsWith("objnull.com") && u.GitHubLogin.Contains("robot")).ToList();
                        //检查是否已关注
                        bool         followed = false;
                        GitHubClient github   = new GitHubClient(new ProductHeaderValue("objnulldotcom"));
                        foreach (NullUser robot in robots)
                        {
                            github.Credentials = new Credentials(robot.GitHubAccessToken);
                            if (github.User.Followers.IsFollowing(robot.GitHubLogin, user.GitHubLogin).Result)
                            {
                                followed = true;
                                break;
                            }
                        }
                        //关注
                        if (!followed)
                        {
                            NullUser frobot = robots.Where(r => r.FollowingCount < 500).First();

                            github.Credentials = new Credentials(frobot.GitHubAccessToken);
                            github.User.Get(frobot.GitHubLogin);
                            github.User.Followers.Follow(user.GitHubLogin);
                            frobot.FollowingCount += 1;
                            NullUserDataSvc.Update(frobot);
                        }
                    }

                    if (string.IsNullOrEmpty(user.Email))
                    {
                        SysMsg msg = new SysMsg();
                        msg.Date  = DateTime.Now;
                        msg.Title = "您还未设置邮箱";
                        msg.Msg   = "请到<a href=\"/Home/UserProfile\">我的主页</a>设置或修改<a href=\"https://github.com/settings/profile\" target=\"_blank\">GitHub</a>邮箱显示后更新账号。";
                        string key = MyRedisKeys.Pre_SysMsg + user.ID;
                        MyRedisDB.SetAdd(key, msg);
                    }
                }
                else
                {
                    user.Name              = githubUser.name;
                    user.AvatarUrl         = githubUser.avatar_url;
                    user.GitHubID          = githubUser.id;
                    user.GitHubLogin       = githubUser.login;
                    user.GitHubAccessToken = token;
                    user.Email             = githubUser.email;
                    user.FollowingCount    = githubUser.following;
                    user.FollowerCount     = githubUser.followers;
                    NullUserDataSvc.Update(user);
                }

                HttpContext.WriteCookie("UID", user.ID.ToString(), DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("UName", HttpUtility.UrlEncode(githubUser.name), DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("UAvatar", githubUser.avatar_url, DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("LoginType", user.LoginType, DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("GLogin", githubUser.login, DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("SKEY", Utils.RijndaelEncrypt(user.ID.ToString()), DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("Role", Utils.RijndaelEncrypt(user.ID.ToString() + ";" + user.Role.ToString()), DateTime.Now.AddYears(3));
            }
            return(true);
        }
예제 #9
0
        //添加用户或更新用户信息
        public bool UpdateUserInfo(string loginType, string token)
        {
            if (loginType == "github")
            {
                GitHubUser githubUser = GitHub.GetGitHubUser(token);
                if (githubUser.id == 0)
                {
                    return(false);
                }
                NullUser user = NullUserDataSvc.GetByCondition(u => u.GitHubID == githubUser.id).FirstOrDefault();
                if (user == null)
                {
                    user                   = new NullUser();
                    user.LoginType         = "github";
                    user.GitHubAccessToken = token;
                    user.Name              = githubUser.name;
                    user.AvatarUrl         = githubUser.avatar_url;
                    user.GitHubLogin       = githubUser.login;
                    user.GitHubID          = githubUser.id;
                    user.Role              = (int)EnumUserRole.普通;
                    user.Email             = githubUser.email;
                    NullUserDataSvc.Add(user);

                    if (string.IsNullOrEmpty(user.Email))
                    {
                        SysMsg msg = new SysMsg();
                        msg.Date  = DateTime.Now;
                        msg.Title = "您还未设置邮箱";
                        msg.Msg   = "请到<a href=\"/Home/UserProfile\">我的主页</a>设置或修改<a href=\"https://github.com/settings/profile\" target=\"_blank\">GitHub</a>邮箱显示后更新账号。";
                        string key = MyRedisKeys.Pre_SysMsg + user.ID;
                        MyRedisDB.SetAdd(key, msg);
                    }
                    //添加一篇newbee
                    //NewBee nb = new NewBee();
                    //nb.OwnerID = user.ID;
                    //nb.Title = "大家好,我是" + (string.IsNullOrEmpty(user.Name) ? user.GitHubLogin : user.Name) + ",很高兴加入象空。";
                    //nb.FloorCount = 1;
                    //nb.LastFloorDate = DateTime.Now;
                    //NewBeeDataSvc.Add(nb);

                    //NewBeeFloor nbf = new NewBeeFloor();
                    //nbf.MDText = "我刚刚加入象空,点击查看更多关于我的信息,如果你有兴趣可以关注我的GitHub。";
                    //nbf.MDValue = "<p>我刚刚加入象空,点击查看更多关于我的信息,如果你有兴趣可以关注我的GitHub。</p>";
                    //nbf.NewBeeID = nb.ID;
                    //nbf.Order = 1;
                    //nbf.OwnerID = user.ID;
                    //NewBeeFloorDataSvc.Add(nbf);
                }
                else
                {
                    user.Name              = githubUser.name;
                    user.AvatarUrl         = githubUser.avatar_url;
                    user.GitHubID          = githubUser.id;
                    user.GitHubLogin       = githubUser.login;
                    user.GitHubAccessToken = token;
                    user.Email             = githubUser.email;
                    NullUserDataSvc.Update(user);
                }

                HttpContext.WriteCookie("UID", user.ID.ToString(), DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("UName", githubUser.name, DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("UAvatar", githubUser.avatar_url, DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("LoginType", user.LoginType, DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("GLogin", githubUser.login, DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("SKEY", Utils.RijndaelEncrypt(user.ID.ToString()), DateTime.Now.AddYears(3));
                HttpContext.WriteCookie("Role", Utils.RijndaelEncrypt(user.ID.ToString() + ";" + user.Role.ToString()), DateTime.Now.AddYears(3));
            }
            return(true);
        }