use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.
the class ContestAdminManager method checkContestACInfo.
public void checkContestACInfo(CheckACDto checkACDto) throws StatusFailException, StatusForbiddenException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
// 获取本场比赛的状态
Contest contest = contestEntityService.getById(checkACDto.getCid());
// 超级管理员或者该比赛的创建者,则为比赛管理者
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
if (!isRoot && !contest.getUid().equals(userRolesVo.getUid()) && !(contest.getIsGroup() && groupValidator.isGroupRoot(userRolesVo.getUid(), contest.getGid()))) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
boolean isOk = contestRecordEntityService.updateById(new ContestRecord().setChecked(checkACDto.getChecked()).setId(checkACDto.getId()));
if (!isOk) {
throw new StatusFailException("修改失败!");
}
}
use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.
the class ContestAdminManager method getContestPrint.
public IPage<ContestPrint> getContestPrint(Long cid, Integer currentPage, Integer limit) throws StatusForbiddenException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
// 获取本场比赛的状态
Contest contest = contestEntityService.getById(cid);
// 超级管理员或者该比赛的创建者,则为比赛管理者
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
if (!isRoot && !contest.getUid().equals(userRolesVo.getUid()) && !(contest.getIsGroup() && groupValidator.isGroupRoot(userRolesVo.getUid(), contest.getGid()))) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
if (currentPage == null || currentPage < 1)
currentPage = 1;
if (limit == null || limit < 1)
limit = 30;
// 获取当前比赛的,未被确定的排在签名
IPage<ContestPrint> contestPrintIPage = new Page<>(currentPage, limit);
QueryWrapper<ContestPrint> contestPrintQueryWrapper = new QueryWrapper<>();
contestPrintQueryWrapper.select("id", "cid", "username", "realname", "status", "gmt_create").eq("cid", cid).orderByAsc("status").orderByDesc("gmt_create");
return contestPrintEntityService.page(contestPrintIPage, contestPrintQueryWrapper);
}
use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.
the class ContestManager method getContestInfo.
public ContestVo getContestInfo(Long cid) throws StatusFailException, StatusForbiddenException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
ContestVo contestInfo = contestEntityService.getContestInfoById(cid);
if (contestInfo == null) {
throw new StatusFailException("对不起,该比赛不存在!");
}
Contest contest = contestEntityService.getById(cid);
if (contest.getIsGroup()) {
if (!groupValidator.isGroupMember(userRolesVo.getUid(), contest.getGid()) && !isRoot) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
}
// 设置当前服务器系统时间
contestInfo.setNow(new Date());
return contestInfo;
}
use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.
the class ContestManager method submitPrintText.
public void submitPrintText(ContestPrintDto contestPrintDto) throws StatusFailException, StatusForbiddenException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
// 获取本场比赛的状态
Contest contest = contestEntityService.getById(contestPrintDto.getCid());
// 超级管理员或者该比赛的创建者,则为比赛管理者
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
// 需要对该比赛做判断,是否处于开始或结束状态才可以获取题目,同时若是私有赛需要判断是否已注册(比赛管理员包括超级管理员可以直接获取)
contestValidator.validateContestAuth(contest, userRolesVo, isRoot);
String lockKey = Constants.Account.CONTEST_ADD_PRINT_LOCK.getCode() + userRolesVo.getUid();
if (redisUtils.hasKey(lockKey)) {
long expire = redisUtils.getExpire(lockKey);
throw new StatusForbiddenException("提交打印功能限制,请在" + expire + "秒后再进行提交!");
} else {
redisUtils.set(lockKey, 1, 30);
}
boolean isOk = contestPrintEntityService.saveOrUpdate(new ContestPrint().setCid(contestPrintDto.getCid()).setContent(contestPrintDto.getContent()).setUsername(userRolesVo.getUsername()).setRealname(userRolesVo.getRealname()));
if (!isOk) {
throw new StatusFailException("提交失败");
}
}
use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.
the class ContestManager method toRegisterContest.
public void toRegisterContest(RegisterContestDto registerContestDto) throws StatusFailException, StatusForbiddenException {
Long cid = registerContestDto.getCid();
String password = registerContestDto.getPassword();
if (cid == null || StringUtils.isEmpty(password)) {
throw new StatusFailException("cid或者password不能为空!");
}
// 获取当前登录的用户
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Contest contest = contestEntityService.getById(cid);
if (contest == null || !contest.getVisible()) {
throw new StatusFailException("对不起,该比赛不存在!");
}
if (contest.getIsGroup()) {
if (!groupValidator.isGroupMember(userRolesVo.getUid(), contest.getGid()) && !isRoot) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
}
if (!contest.getPwd().equals(password)) {
// 密码不对
throw new StatusFailException("比赛密码错误,请重新输入!");
}
// 需要校验当前比赛是否开启账号规则限制,如果有,需要对当前用户的用户名进行验证
if (contest.getOpenAccountLimit() && !contestValidator.validateAccountRule(contest.getAccountLimitRule(), userRolesVo.getUsername())) {
throw new StatusFailException("对不起!本次比赛只允许特定账号规则的用户参赛!");
}
QueryWrapper<ContestRegister> wrapper = new QueryWrapper<ContestRegister>().eq("cid", cid).eq("uid", userRolesVo.getUid());
if (contestRegisterEntityService.getOne(wrapper, false) != null) {
throw new StatusFailException("您已注册过该比赛,请勿重复注册!");
}
boolean isOk = contestRegisterEntityService.saveOrUpdate(new ContestRegister().setCid(cid).setUid(userRolesVo.getUid()));
if (!isOk) {
throw new StatusFailException("校验比赛密码失败,请稍后再试");
}
}
Aggregations