示例#1
0
        public async void OnGetAsync()
        {
            DateTime now       = DateTime.Now;
            string   githubId  = "";
            string   name      = "";
            string   username  = "";
            string   avatarUrl = "";

            foreach (Claim claim in User.Claims)
            {
                if (claim.Type == ClaimTypes.NameIdentifier)
                {
                    githubId = claim.Value;
                }
                else if (claim.Type == ClaimTypes.Name)
                {
                    name = claim.Value;
                }
                else if (claim.Type == "urn:github:login")
                {
                    username = claim.Value;
                }
                else if (claim.Type == "urn:github:avatar")
                {
                    avatarUrl = claim.Value;
                }
            }

            ThisUser = await _context.GetUserByGithubId(githubId);

            int userId;

            if (ThisUser != null)
            {
                userId = ThisUser.Id;
            }
            else
            {
                ThisUser = new User {
                    Username   = username,
                    Name       = name,
                    GithubId   = githubId,
                    CreateDate = now,
                    AvatarUrl  = avatarUrl
                };

                var dbResponse = _context.AddUser(ThisUser);
                await _context.SaveChangesAsync();

                userId = dbResponse.Entity.Id;
            }

            Bookmarks = await _context.GetBookmarksByUserIdAsync(userId);

            FavoriteBookmarks = await _context.GetFavoriteBookmarksByUserIdAsync(userId);

            FollowingBookmarks = await _context.GetBookmarksByFollowersAsync(userId);
        }
示例#2
0
        public async Task <IActionResult> OnGetAsync(int id)
        {
            string githubId = "";

            foreach (Claim claim in User.Claims)
            {
                if (claim.Type == ClaimTypes.NameIdentifier)
                {
                    githubId = claim.Value;
                }
            }

            ThisUser = await _context.GetUserByGithubId(githubId);

            if (id == 0 || (ThisUser != null && ThisUser.Id == id))
            {
                ViewingUser = ThisUser;
                id          = ThisUser.Id;
                Bookmarks   = await _context.GetBookmarksByUserIdAsync(id);

                FavoriteBookmarks = await _context.GetFavoriteBookmarksByUserIdAsync(id);
            }
            else
            {
                ViewingUser = await _context.GetUserAsync(id);

                Bookmarks = await _context.GetPublicBookmarksByUserIdAsync(id);

                FavoriteBookmarks = await _context.GetPublicFavoriteBookmarksByUserIdAsync(id);
            }

            ClippyMode = (ThisUser != null) ? ThisUser.ClippyMode : false;

            if (ViewingUser == null)
            {
                return(RedirectToPage("/Index"));
            }

            return(Page());
        }