示例#1
0
 private String validateSubmit(
     HttpServletRequest request, Response resp, String coo, Integer id, Integer[] optionIds) {
   List<String> messages = resp.getMessages();
   if (!Validations.notNull(id, messages, "id")) {
     return resp.post(401);
   }
   if (!Validations.notEmpty(optionIds)) {
     return resp.post(402);
   }
   Vote vote = service.get(id);
   if (!Validations.exist(vote, messages, "Vote", id)) {
     return resp.post(451);
   }
   if (vote.getStatus() == Vote.DISABLED_STATUS) {
     return resp.post(510, "vote.desiabled");
   }
   Date now = new Date();
   Date beginDate = vote.getBeginDate();
   if (beginDate != null && beginDate.after(now)) {
     return resp.post(520, "vote.notStarted");
   }
   Date endDate = vote.getEndDate();
   if (endDate != null && endDate.before(now)) {
     return resp.post(530, "vote.ended");
   }
   if (vote.getMaxSelected() > 0 && optionIds.length > vote.getMaxSelected()) {
     return resp.post(540, "vote.exceedsMaxSelected");
   }
   Integer userId = null;
   String ip = null;
   String cookie = null;
   if (vote.getMode() == Vote.USER_MODE) {
     User user = Context.getCurrentUser(request);
     if (user == null) {
       return resp.post(550, "vote.needLogin");
     }
     userId = user.getId();
   } else if (vote.getMode() == Vote.IP_MODE) {
     ip = Servlets.getRemoteAddr(request);
   } else if (vote.getMode() == Vote.COOKIE_MODE) {
     cookie = coo;
   }
   if (userId != null || ip != null || cookie != null) {
     Integer beforeHour = null;
     if (vote.getInterval() != 0) {
       beforeHour = vote.getInterval() * 24;
     }
     if (voteMarkService.isVoted(Vote.MARK_CODE, vote.getId(), userId, ip, cookie, beforeHour)) {
       return resp.post(560, "vote.voted");
     }
   }
   return null;
 }
示例#2
0
  @RequestMapping(value = "/vote/{id}.jspx")
  public String view(
      @PathVariable("id") Integer id,
      HttpServletRequest request,
      HttpServletResponse response,
      org.springframework.ui.Model modelMap) {
    Response resp = new Response(request, response, modelMap);
    List<String> messages = resp.getMessages();
    Vote vote = service.get(id);
    if (!Validations.exist(vote, messages, "Vote", id)) {
      return resp.notFound();
    }

    Site currSite = Context.getCurrentSite(request);
    modelMap.addAttribute("vote", vote);
    Map<String, Object> data = modelMap.asMap();
    ForeContext.setData(data, request);
    return currSite.getTemplate(VIEW_TEMPLATE);
  }
示例#3
0
  @RequestMapping(value = "/vote.jspx", method = RequestMethod.POST)
  public String submit(
      Integer id,
      Integer[] optionIds,
      HttpServletRequest request,
      HttpServletResponse response,
      org.springframework.ui.Model modelMap) {
    Response resp = new Response(request, response, modelMap);
    String cookie = Site.getIdentityCookie(request, response);
    String result = validateSubmit(request, resp, cookie, id, optionIds);
    if (resp.hasErrors()) {
      return result;
    }

    Integer userId = Context.getCurrentUserId(request);
    String ip = Servlets.getRemoteAddr(request);
    service.vote(id, optionIds, userId, ip, cookie);
    resp.addData("id", id);
    return resp.post();
  }
示例#4
0
  @RequestMapping(value = "/vote.jspx")
  public String form(
      Integer id,
      HttpServletRequest request,
      HttpServletResponse response,
      org.springframework.ui.Model modelMap) {
    Response resp = new Response(request, response, modelMap);
    List<String> messages = resp.getMessages();
    if (!Validations.notNull(id, messages, "id")) {
      return resp.badRequest();
    }
    Vote vote = service.get(id);
    if (!Validations.exist(vote, messages, "Vote", id)) {
      return resp.notFound();
    }

    modelMap.addAttribute("vote", vote);
    Site site = Context.getCurrentSite(request);
    Map<String, Object> data = modelMap.asMap();
    ForeContext.setData(data, request);
    return site.getTemplate(TEMPLATE);
  }