Example #1
0
        public async Task <bool> Login([FromBody] UserInfo userInfo)
        {
            var cached = sessionUtils.GetCachedUserInfo(HttpContext);

            if (cached != null)
            {
                //已经登录
                return(true);
            }
            var res = await authService.ValidateUserInfo(userInfo);

            if (res == null)
            {
                return(false);
            }
            sessionUtils.SetSessionUserInfo(HttpContext, res);
            return(true);
        }
Example #2
0
        private UserInfo RaiseIfNotLoggedIn()
        {
            var userInfo = sessionUtils.GetCachedUserInfo(HttpContext);

            if (userInfo == null)
            {
                throw new UserException("用户未登录!");
            }
            return(userInfo);
        }
Example #3
0
        public async Task <bool> AddOjReview([FromRoute] string ojId, [FromRoute] string review)
        {
            if (review.Length > 100)
            {
                return(false);
            }

            var userInfo = sessionUtils.GetCachedUserInfo(HttpContext);

            if (userInfo == null)
            {
                return(false);
            }
            return(await reviewService.AddOjReview(ojId, userInfo.Id, review));
        }
Example #4
0
        public async Task <List <OjQuestion> > ListOjQuestions([FromRoute] int page)
        {
            var userInfo = sessionUtils.GetCachedUserInfo(HttpContext);

            return(await ojService.ListQuestionSummary(userInfo?.Id, page));
        }