use of cn.edu.sdu.qd.oj.common.exception.ApiException in project sduoj-server by SDUOJ.
the class ProblemManageService method createProblem.
@Transactional
public String createProblem(ProblemManageDTO problem) {
problem.setProblemId(null);
problem.setProblemCode(null);
ProblemDO problemDO = problemManageConverter.from(problem);
AssertUtils.isTrue(problemDao.save(problemDO), ApiExceptionEnum.UNKNOWN_ERROR);
// TODO: 魔法值解决
problemDO.setProblemCode("SDUOJ-" + problemDO.getProblemId());
if (!problemDao.lambdaUpdate().eq(ProblemDO::getProblemId, problemDO.getProblemId()).set(ProblemDO::getProblemCode, problemDO.getProblemCode()).update()) {
throw new ApiException(ApiExceptionEnum.UNKNOWN_ERROR);
}
return problemDO.getProblemCode();
}
use of cn.edu.sdu.qd.oj.common.exception.ApiException in project sduoj-server by SDUOJ.
the class UserController method thirdPartyLogin.
@GetMapping("/thirdPartyLogin")
@ResponseBody
public ResponseResult<UserThirdPartyLoginRespDTO> thirdPartyLogin(HttpServletRequest request, HttpServletResponse response, @RealIp String ipv4, @RequestHeader("user-agent") String userAgent) {
ThirdPartyEnum thirdParty = ThirdPartyEnum.of(request.getParameter("thirdParty"));
AssertUtils.notNull(thirdParty, ApiExceptionEnum.THIRD_PARTY_NOT_EXIST);
UserThirdPartyLoginRespDTO respDTO = null;
switch(thirdParty) {
case SDUCAS:
respDTO = userService.thirdPartyLoginBySduCas(request.getParameter("ticket"), ipv4, userAgent);
break;
case QQ:
case WECHAT:
throw new ApiException(ApiExceptionEnum.THIRD_PARTY_ERROR, "暂不支持这种第三方认证");
}
Optional.ofNullable(respDTO).map(UserThirdPartyLoginRespDTO::getUser).ifPresent(userSessionDTO -> {
writeSessionToHeader(response, userSessionDTO);
});
return respDTO != null ? ResponseResult.ok(respDTO) : ResponseResult.error();
}
use of cn.edu.sdu.qd.oj.common.exception.ApiException in project sduoj-server by SDUOJ.
the class UserService method updateEmail.
public void updateEmail(Long userId, String password, @Email(message = "parameter is not an email") @NotBlank String email, String emailCode) {
validateEmailCode(email, emailCode);
validatePassword(userId, password);
// 特判用户标 UserFeatureEnum.BAN_EMAIL_UPDATE
UserDO userDO = userDao.lambdaQuery().select(UserDO::getFeatures).eq(UserDO::getUserId, userId).one();
if (userConverter.featuresTo(userDO.getFeatures()).isBanEmailUpdate()) {
throw new ApiException(ApiExceptionEnum.FEATURE_ERROR, "该用户被禁止更改邮箱");
}
AssertUtils.isTrue(userDao.lambdaUpdate().set(UserDO::getEmail, email).eq(UserDO::getUserId, userId).update(), ApiExceptionEnum.UNKNOWN_ERROR);
consumeEmailCode(email, emailCode);
}
use of cn.edu.sdu.qd.oj.common.exception.ApiException in project sduoj-server by SDUOJ.
the class UserService method thirdPartyBinding.
/**
* 第三方登录绑定已有账号
*/
@Transactional
public UserSessionDTO thirdPartyBinding(UserThirdPartyBindingReqDTO reqDTO, String ipv4, String userAgent) {
// 取 redis 中的 token
UserThirdPartyLoginRespDTO respDTO = JSON.parseObject((String) redisUtils.get(RedisConstants.getThirdPartyToken(reqDTO.getToken())), UserThirdPartyLoginRespDTO.class);
AssertUtils.notNull(respDTO, ApiExceptionEnum.THIRD_PARTY_NOT_EXIST);
ThirdPartyEnum thirdParty = respDTO.getThirdParty();
// 调用具体的第三方绑定方式
UserDO userDO = null;
switch(thirdParty) {
case SDUCAS:
userDO = thirdPartyBindingBySduCas(reqDTO, respDTO);
break;
case QQ:
case WECHAT:
throw new ApiException(ApiExceptionEnum.THIRD_PARTY_ERROR, "暂不支持这种第三方认证");
}
// 特判用户标 UserFeatureEnum.BAN_THIRD_PARTY
if (userConverter.featuresTo(userDO.getFeatures()).isBanThirdParty()) {
throw new ApiException(ApiExceptionEnum.FEATURE_ERROR, "该用户被禁止使用第三方认证");
}
// 删除 redis 中对应的 token
redisUtils.del(RedisConstants.getThirdPartyToken(reqDTO.getToken()));
// 登录
return loginWithWritingSession(userDO, ipv4, userAgent);
}
use of cn.edu.sdu.qd.oj.common.exception.ApiException in project sduoj-server by SDUOJ.
the class ContestService method queryContestAndValidate.
private ContestDO queryContestAndValidate(long contestId, long userId) {
ContestDO contestDO = contestDao.lambdaQuery().select(ContestDO::getContestId, ContestDO::getFeatures, ContestDO::getGmtStart, ContestDO::getGmtEnd, ContestDO::getUserId, ContestDO::getProblems, ContestDO::getParticipants, ContestDO::getUnofficialParticipants).eq(ContestDO::getContestId, contestId).one();
AssertUtils.notNull(contestDO, ApiExceptionEnum.CONTEST_NOT_FOUND);
// 判断比赛可见性
ContestFeatureDTO featureDTO = ContestConvertUtils.featuresTo(contestDO.getFeatures());
ContestOpennessEnum openness = ContestOpennessEnum.of(featureDTO.getOpenness());
AssertUtils.isTrue(contestDO.containsUserIdInParticipants(userId) || !ContestOpennessEnum.PRIVATE.equals(openness), ApiExceptionEnum.CONTEST_NOT_PARTICIPATE);
if (contestDO.getGmtStart().after(new Date())) {
throw new ApiException(ApiExceptionEnum.CONTEST_NOT_BEGIN);
}
return contestDO;
}
Aggregations