Пример #1
0
  @ResponseBody
  @RequestMapping(method = RequestMethod.POST)
  public Object insert(Post post, String tags) {
    MapContainer form = PostFormValidator.validatePublish(post);
    if (!form.isEmpty()) {
      return form.put("success", false);
    }

    post.setId(optionManager.getNextPostid());
    post.setCreator(WebContextFactory.get().getUser().getId());
    post.setCreateTime(new Date());
    post.setLastUpdate(post.getCreateTime());

    /* 由于加入xss的过滤,html内容都被转义了,这里需要unescape */
    String content = HtmlUtils.htmlUnescape(post.getContent());
    post.setContent(JsoupUtils.filter(content));
    String cleanTxt = JsoupUtils.plainText(content);
    post.setExcerpt(
        cleanTxt.length() > PostConstants.EXCERPT_LENGTH
            ? cleanTxt.substring(0, PostConstants.EXCERPT_LENGTH)
            : cleanTxt);

    postManager.insertPost(post, PostTagHelper.from(post, tags, post.getCreator()));
    return new MapContainer("success", true);
  }
Пример #2
0
  @RequestMapping(value = "/my", method = RequestMethod.PUT)
  public String upmy(User user, String repass, Model model) {
    MapContainer form = UserFormValidator.validateMy(user, repass);
    if (!form.isEmpty()) {
      model.addAllAttributes(form);
      model.addAttribute("my", user);
      return "backend/user/my";
    }

    user.setRole(WebContextFactory.get().getUser().getRole());
    user.setLastUpdate(new Date());
    userService.update(user);
    return "redirect:/backend/users";
  }
Пример #3
0
  @ResponseBody
  @RequestMapping(value = "/fast", method = RequestMethod.PUT)
  public Object fast(Post post, String tags) {
    MapContainer form = PostFormValidator.validateFastUpdate(post);
    if (!form.isEmpty()) {
      return form.put("success", false);
    }

    Post old = postService.loadById(post.getId());
    if (old == null) {
      return form.put("success", false).put("msg", "非法请求");
    }

    post.setContent(old.getContent());
    post.setExcerpt(old.getExcerpt());

    post.setType(PostConstants.TYPE_POST);
    post.setLastUpdate(new Date());
    postManager.updatePost(
        post, PostTagHelper.from(post, tags, WebContextFactory.get().getUser().getId()), true);
    return new MapContainer("success", true);
  }
Пример #4
0
 @RequestMapping(value = "/my", method = RequestMethod.GET)
 public String my(Model model) {
   model.addAttribute("my", WebContextFactory.get().getUser());
   return "backend/user/my";
 }