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); }
private UserInfo RaiseIfNotLoggedIn() { var userInfo = sessionUtils.GetCachedUserInfo(HttpContext); if (userInfo == null) { throw new UserException("用户未登录!"); } return(userInfo); }
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)); }
public async Task <List <OjQuestion> > ListOjQuestions([FromRoute] int page) { var userInfo = sessionUtils.GetCachedUserInfo(HttpContext); return(await ojService.ListQuestionSummary(userInfo?.Id, page)); }