Ejemplo n.º 1
0
        public async Task <ItemCollection> Get()
        {
            var twitchUser = await sessionInfoProvider.GetTwitchUserAsync(HttpContext.Session);

            if (twitchUser == null)
            {
                var authToken = GetAuthToken();
                try
                {
                    AssertAuthTokenValidity(authToken);
                }
                catch (NullReferenceException)
                {
                    return(new ItemCollection());
                }
            }

            if (itemManager == null)
            {
                return(new ItemCollection());
            }

            var itemCollection = itemManager.GetAllItems();

            return(itemCollection);
        }
Ejemplo n.º 2
0
        public async Task <bool> UpdateSyntyAppearanceAsync(string userId, SyntyAppearance appearance)
        {
            userId = CleanupUserId(userId); // we get a weird input sent from the client. This shouldnt
                                            // be fixed here, but as a temporary bugfix
            var twitchUserSession = await sessionInfoProvider.GetTwitchUserAsync(HttpContext.Session);

            if (twitchUserSession != null)
            {
                return(playerManager.UpdateAppearance(userId, appearance));
            }

            var authToken = GetAuthToken();

            if (authToken != null)
            {
                return(playerManager.UpdateAppearance(authToken, userId, appearance));
            }

            return(playerManager.UpdateAppearance(AssertGetSessionToken(), userId, appearance));
        }
Ejemplo n.º 3
0
        public async Task <SessionInfo> SetAccessToken(string token)
        {
            var session = this.HttpContext.Session;
            var result  = await sessionInfoProvider.SetTwitchTokenAsync(session, token);

            var user = await sessionInfoProvider.GetTwitchUserAsync(session, token);

            if (user != null)
            {
                playerManager.CreatePlayerIfNotExists(user.Id, user.Login);
            }
            return(result);
        }
Ejemplo n.º 4
0
        private async Task AssertAdminAccessAsync()
        {
            var authToken = GetAuthToken();

            if (authToken != null)
            {
                AssertAdminAuthToken(authToken);
                return;
            }

            var twitchUser = await sessionInfoProvider.GetTwitchUserAsync(HttpContext.Session);

            AssertAdminTwitchUser(twitchUser);
        }
Ejemplo n.º 5
0
        private async Task <Player> GetPlayerAsync()
        {
            var twitchUser = await sessionInfoProvider.GetTwitchUserAsync(HttpContext.Session);

            if (twitchUser != null)
            {
                return(await playerManager.GetGlobalPlayerAsync(twitchUser.Id));
            }

            var sessionToken = GetSessionToken();

            if (sessionToken == null || sessionToken.Expired || string.IsNullOrEmpty(sessionToken.AuthToken))
            {
                var auth = GetAuthToken();
                if (auth != null && !auth.Expired)
                {
                    return(await playerManager.GetGlobalPlayerAsync(auth.UserId));
                }

                return(null);
            }

            return(await playerManager.GetPlayerAsync(sessionToken));
        }