Search in sources :

Example 1 with Mail

use of cn.edu.zjnu.acm.judge.domain.Mail in project judge by zjnu-acm.

the class MailController method delete.

@GetMapping("/deletemail")
public String delete(@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.delete(mailId);
    return "redirect:/mail";
}
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 2 with Mail

use of cn.edu.zjnu.acm.judge.domain.Mail 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) {
    String title = "";
    String content = "";
    if (reply != -1) {
        Mail parent = mailMapper.findOne(reply);
        if (parent == null) {
            throw new BusinessException(BusinessCode.MAIL_NOT_FOUND);
        }
        String toUser = parent.getTo();
        if (!UserDetailsServiceImpl.isUser(toUser)) {
            throw new BusinessException(BusinessCode.MAIL_INVALID_ACCESS);
        }
        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.INSTANCE.getReplyString(content));
    return "mails/sendpage";
}
Also used : BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Mail(cn.edu.zjnu.acm.judge.domain.Mail) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with Mail

use of cn.edu.zjnu.acm.judge.domain.Mail 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 4 with Mail

use of cn.edu.zjnu.acm.judge.domain.Mail 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)

Example 5 with Mail

use of cn.edu.zjnu.acm.judge.domain.Mail in project judge by zjnu-acm.

the class MailController method showMail.

@GetMapping("showmail")
public String showMail(Model model, @RequestParam("mail_id") long mailId) {
    Mail mail = access(mailId);
    mailMapper.readed(mailId);
    model.addAttribute("mail", mail);
    return "mails/view";
}
Also used : Mail(cn.edu.zjnu.acm.judge.domain.Mail) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Mail (cn.edu.zjnu.acm.judge.domain.Mail)6 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 MessageException (cn.edu.zjnu.acm.judge.exception.MessageException)3 BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)1