Search in sources :

Example 6 with StatusForbiddenException

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("修改失败!");
    }
}
Also used : StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) ContestRecord(top.hcode.hoj.pojo.entity.contest.ContestRecord) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Session(org.apache.shiro.session.Session)

Example 7 with StatusForbiddenException

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);
}
Also used : StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) ContestPrint(top.hcode.hoj.pojo.entity.contest.ContestPrint) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Session(org.apache.shiro.session.Session)

Example 8 with StatusForbiddenException

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;
}
Also used : StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session)

Example 9 with StatusForbiddenException

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("提交失败");
    }
}
Also used : StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session)

Example 10 with StatusForbiddenException

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("校验比赛密码失败,请稍后再试");
    }
}
Also used : StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session)

Aggregations

StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)113 Session (org.apache.shiro.session.Session)105 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)93 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)78 StatusNotFoundException (top.hcode.hoj.common.exception.StatusNotFoundException)67 Group (top.hcode.hoj.pojo.entity.group.Group)64 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)52 Contest (top.hcode.hoj.pojo.entity.contest.Contest)32 Problem (top.hcode.hoj.pojo.entity.problem.Problem)21 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)20 Transactional (org.springframework.transaction.annotation.Transactional)15 ContestProblem (top.hcode.hoj.pojo.entity.contest.ContestProblem)13 Discussion (top.hcode.hoj.pojo.entity.discussion.Discussion)12 GroupMember (top.hcode.hoj.pojo.entity.group.GroupMember)6 JSONObject (cn.hutool.json.JSONObject)5 FileReader (cn.hutool.core.io.file.FileReader)4 FileWriter (cn.hutool.core.io.file.FileWriter)4 LinkedList (java.util.LinkedList)4 Judge (top.hcode.hoj.pojo.entity.judge.Judge)4 Tag (top.hcode.hoj.pojo.entity.problem.Tag)4