Search in sources :

Example 6 with MessageException

use of cn.edu.zjnu.acm.judge.exception.MessageException in project judge by zjnu-acm.

the class MailController method showMail.

@GetMapping("/showmail")
public String showMail(Model model, @RequestParam("mail_id") long mailId, Authentication authentication) {
    Mail mail = mailMapper.findOne(mailId);
    if (mail == null) {
        throw new MessageException("No such mail", HttpStatus.NOT_FOUND);
    }
    if (!UserDetailsServiceImpl.isUser(authentication, mail.getTo())) {
        throw new MessageException("Sorry, invalid access", HttpStatus.FORBIDDEN);
    }
    mailMapper.readed(mailId);
    model.addAttribute("mail", mail);
    return "mails/view";
}
Also used : Mail(cn.edu.zjnu.acm.judge.domain.Mail) MessageException(cn.edu.zjnu.acm.judge.exception.MessageException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 7 with MessageException

use of cn.edu.zjnu.acm.judge.exception.MessageException in project judge by zjnu-acm.

the class MailController method sendPage.

@GetMapping({ "/sendpage", "/send" })
@SuppressWarnings("AssignmentToMethodParameter")
public String sendPage(Model model, @RequestParam(value = "reply", defaultValue = "-1") long reply, @RequestParam(value = "to", defaultValue = "") String userId, Authentication authentication) {
    String title = "";
    String content = "";
    if (reply != -1) {
        Mail parent = mailMapper.findOne(reply);
        if (parent == null) {
            throw new MessageException("No such mail", HttpStatus.NOT_FOUND);
        }
        String toUser = parent.getTo();
        if (!UserDetailsServiceImpl.isUser(authentication, toUser)) {
            throw new MessageException("invalid access", HttpStatus.FORBIDDEN);
        }
        userId = parent.getFrom();
        title = parent.getTitle();
        content = parent.getContent();
        if (!title.regionMatches(true, 0, "re:", 0, 3)) {
            title = "Re:" + title;
        }
        mailMapper.setReply(reply);
    }
    model.addAttribute("to", userId);
    model.addAttribute("title", title);
    model.addAttribute("content", JudgeUtils.getReplyString(content));
    return "mails/sendpage";
}
Also used : Mail(cn.edu.zjnu.acm.judge.domain.Mail) MessageException(cn.edu.zjnu.acm.judge.exception.MessageException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

MessageException (cn.edu.zjnu.acm.judge.exception.MessageException)7 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 Mail (cn.edu.zjnu.acm.judge.domain.Mail)3 Submission (cn.edu.zjnu.acm.judge.domain.Submission)2 BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)2 SubmissionDetail (cn.edu.zjnu.acm.judge.data.dto.SubmissionDetail)1 Contest (cn.edu.zjnu.acm.judge.domain.Contest)1 Message (cn.edu.zjnu.acm.judge.domain.Message)1 User (cn.edu.zjnu.acm.judge.domain.User)1 Secured (org.springframework.security.access.annotation.Secured)1 Transactional (org.springframework.transaction.annotation.Transactional)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1