public async Task <ActionResult <RoundDTO> > NextRound([FromHeader(Name = "PPAuthorization")] string authToken, string sessionKey)
        {
            if (!SecurityFilter.RequestIsValid(authToken, sessionKey, this.userStateManager))
            {
                return(this.Unauthorized());
            }

            var session = await this.sessionRepository.FindByKeyAsync(sessionKey);

            if (session == null)
            {
                return(this.NotFound());
            }

            var currentItem = SessionUtils.GetCurrentActiveItem(session.Items, session.Users.Count);

            if (!currentItem.HasValue)
            {
                return(this.BadRequest());
            }

            var newRound = this.sessionRepository.AddRoundToSessionItem(currentItem.ValueOrDefault().Id);

            return(newRound);
        }
        public async Task <ActionResult <ItemDTO> > NextItem([FromHeader(Name = "PPAuthorization")] string authToken, string sessionKey)
        {
            if (!SecurityFilter.RequestIsValid(authToken, sessionKey, this.userStateManager))
            {
                return(this.Unauthorized());
            }

            var session = await this.sessionRepository.FindByKeyAsync(sessionKey);

            if (session == null)
            {
                return(this.NotFound());
            }

            var nextItem = session.Items.FirstOrDefault(item => item.Rounds.Count == 0);

            // If there are no more items without any rounds, the session is complete
            // TODO: Generate summary when this happens
            if (nextItem == default(ItemDTO))
            {
                await this.summaryRepository.BuildSummary(session);

                return(this.BadRequest());
            }

            var newRound = this.sessionRepository.AddRoundToSessionItem(nextItem.Id);

            nextItem.Rounds.Add(newRound);
            return(nextItem);
        }
示例#3
0
        public void RequestIsValid_given_null_token_returns_false()
        {
            var cache        = new MemoryCache(new MemoryCacheOptions());
            var stateManager = new UserStateManager(cache);

            Assert.False(SecurityFilter.RequestIsValid(null, null, stateManager));
        }
示例#4
0
        public void RequestIsValid_given_invalid_token_returns_true()
        {
            var cache        = new MemoryCache(new MemoryCacheOptions());
            var stateManager = new UserStateManager(cache);

            Assert.False(SecurityFilter.RequestIsValid("invalidtoken123123", "ABC1234", stateManager));
        }
示例#5
0
        public void RequestIsValid_given_valid_token_returns_true()
        {
            var cache        = new MemoryCache(new MemoryCacheOptions());
            var stateManager = new UserStateManager(cache);

            var token = stateManager.CreateState(1, "ABC1234");

            Assert.True(SecurityFilter.RequestIsValid(token, "ABC1234", stateManager));
        }
        public ActionResult <UserState> WhoAmI([FromHeader(Name = "PPAuthorization")] string authToken, string sessionKey)
        {
            if (!SecurityFilter.RequestIsValid(authToken, sessionKey, this.userStateManager))
            {
                return(this.Unauthorized());
            }

            var state = this.userStateManager.GetState(authToken.Replace("Bearer ", string.Empty));

            return(state.ValueOrDefault());
        }
        public async Task <ActionResult <SessionDTO> > GetByKey([FromHeader(Name = "PPAuthorization")] string authToken, string sessionKey)
        {
            if (!SecurityFilter.RequestIsValid(authToken, sessionKey, this.userStateManager))
            {
                return(this.Unauthorized());
            }

            var session = await this.sessionRepository.FindByKeyAsync(sessionKey);

            if (session == null)
            {
                return(this.NotFound());
            }

            return(session);
        }
        public async Task <ActionResult> Vote([FromHeader(Name = "PPAuthorization")] string authToken, string sessionKey, [FromBody] VoteCreateUpdateDTO vote)
        {
            if (!SecurityFilter.RequestIsValid(authToken, sessionKey, this.userStateManager))
            {
                return(this.Unauthorized());
            }

            var session = await this.sessionRepository.FindByKeyAsync(sessionKey);

            if (session == null)
            {
                return(this.StatusCode(404, "Session not found"));
            }

            var currentItem = SessionUtils.GetCurrentActiveItem(session.Items, session.Users.Count);

            if (!currentItem.HasValue)
            {
                return(this.StatusCode(404, "Active Item not found"));
            }

            var currentRound = SessionUtils.GetCurrentActiveRound(currentItem.ValueOrDefault().Rounds.ToList(), session.Users.Count);

            if (!currentRound.HasValue)
            {
                return(this.StatusCode(404, "Active Round not found"));
            }

            var userState = this.userStateManager.GetState(authToken.Replace("Bearer ", string.Empty)).ValueOrDefault();

            this.sessionRepository.AddVoteToRound(
                new VoteCreateUpdateDTO {
                Estimate = vote.Estimate, UserId = userState.Id
            },
                currentRound.ValueOrDefault().Id);

            return(this.Ok());
        }