Search in sources :

Example 1 with Comments

use of com.tale.model.Comments in project tale by otale.

the class CommentController method delete.

/**
     * 删除一条评论
     * @param coid
     * @return
     */
@Route(value = "delete", method = HttpMethod.POST)
@JSON
public RestResponse delete(@QueryParam Integer coid) {
    try {
        Comments comments = commentsService.byId(coid);
        if (null == comments) {
            return RestResponse.fail("不存在该评论");
        }
        commentsService.delete(coid, comments.getCid());
        siteService.cleanCache(Types.C_STATISTICS);
    } catch (Exception e) {
        String msg = "评论删除失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Comments(com.tale.model.Comments) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 2 with Comments

use of com.tale.model.Comments in project tale by otale.

the class CommentController method delete.

@Route(value = "status", method = HttpMethod.POST)
@JSON
public RestResponse delete(@QueryParam Integer coid, @QueryParam String status) {
    try {
        Comments comments = new Comments();
        comments.setCoid(coid);
        comments.setStatus(status);
        commentsService.update(comments);
        siteService.cleanCache(Types.C_STATISTICS);
    } catch (Exception e) {
        String msg = "操作失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Comments(com.tale.model.Comments) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 3 with Comments

use of com.tale.model.Comments in project tale by otale.

the class IndexController method index.

/**
     * 仪表盘
     */
@Route(value = { "/", "index" }, method = HttpMethod.GET)
public String index(Request request) {
    List<Comments> comments = siteService.recentComments(5);
    List<Contents> contents = siteService.getContens(Types.RECENT_ARTICLE, 5);
    Statistics statistics = siteService.getStatistics();
    // 取最新的20条日志
    List<Logs> logs = logService.getLogs(1, 20);
    request.attribute("comments", comments);
    request.attribute("articles", contents);
    request.attribute("statistics", statistics);
    request.attribute("logs", logs);
    return "admin/index";
}
Also used : Contents(com.tale.model.Contents) Comments(com.tale.model.Comments) Logs(com.tale.model.Logs) Statistics(com.tale.dto.Statistics) Route(com.blade.mvc.annotation.Route)

Example 4 with Comments

use of com.tale.model.Comments in project tale by otale.

the class IndexController method comment.

/**
     * 评论操作
     */
@Route(value = "comment", method = HttpMethod.POST)
@JSON
public RestResponse comment(Request request, Response response, @QueryParam Integer cid, @QueryParam Integer coid, @QueryParam String author, @QueryParam String mail, @QueryParam String url, @QueryParam String text, @QueryParam String _csrf_token) {
    String ref = request.header("Referer");
    if (StringKit.isBlank(ref) || StringKit.isBlank(_csrf_token)) {
        return RestResponse.fail(ErrorCode.BAD_REQUEST);
    }
    if (!ref.startsWith(Commons.site_url())) {
        return RestResponse.fail("非法评论来源");
    }
    String token = cache.hget(Types.CSRF_TOKEN, _csrf_token);
    if (StringKit.isBlank(token)) {
        return RestResponse.fail(ErrorCode.BAD_REQUEST);
    }
    if (null == cid || StringKit.isBlank(author) || StringKit.isBlank(mail) || StringKit.isBlank(text)) {
        return RestResponse.fail("请输入完整后评论");
    }
    if (author.length() > 50) {
        return RestResponse.fail("姓名过长");
    }
    if (!TaleUtils.isEmail(mail)) {
        return RestResponse.fail("请输入正确的邮箱格式");
    }
    if (StringKit.isNotBlank(url) && !PatternKit.isURL(url)) {
        return RestResponse.fail("请输入正确的URL格式");
    }
    if (text.length() > 200) {
        return RestResponse.fail("请输入200个字符以内的评论");
    }
    String val = IPKit.getIpAddrByRequest(request.raw()) + ":" + cid;
    Integer count = cache.hget(Types.COMMENTS_FREQUENCY, val);
    if (null != count && count > 0) {
        return RestResponse.fail("您发表评论太快了,请过会再试");
    }
    author = TaleUtils.cleanXSS(author);
    text = TaleUtils.cleanXSS(text);
    author = EmojiParser.parseToAliases(author);
    text = EmojiParser.parseToAliases(text);
    Comments comments = new Comments();
    comments.setAuthor(author);
    comments.setCid(cid);
    comments.setIp(request.address());
    comments.setUrl(url);
    comments.setContent(text);
    comments.setMail(mail);
    comments.setParent(coid);
    try {
        commentsService.saveComment(comments);
        response.cookie("tale_remember_author", URLEncoder.encode(author, "UTF-8"), 7 * 24 * 60 * 60);
        response.cookie("tale_remember_mail", URLEncoder.encode(mail, "UTF-8"), 7 * 24 * 60 * 60);
        if (StringKit.isNotBlank(url)) {
            response.cookie("tale_remember_url", URLEncoder.encode(url, "UTF-8"), 7 * 24 * 60 * 60);
        }
        // 设置对每个文章30秒可以评论一次
        cache.hset(Types.COMMENTS_FREQUENCY, val, 1, 30);
        siteService.cleanCache(Types.C_STATISTICS);
        request.attribute("del_csrf_token", token);
        return RestResponse.ok();
    } catch (Exception e) {
        String msg = "评论发布失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}
Also used : Comments(com.tale.model.Comments) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Example 5 with Comments

use of com.tale.model.Comments in project tale by otale.

the class CommentsServiceImpl method getChildren.

/**
     * 获取该评论下的追加评论
     *
     * @param coid
     * @return
     */
private void getChildren(List<Comments> list, Integer coid) {
    List<Comments> cms = activeRecord.list(new Take(Comments.class).eq("parent", coid).orderby("coid asc"));
    if (null != cms) {
        list.addAll(cms);
        cms.forEach(c -> getChildren(list, c.getCoid()));
    }
}
Also used : Take(com.blade.jdbc.core.Take) Comments(com.tale.model.Comments)

Aggregations

Comments (com.tale.model.Comments)8 Route (com.blade.mvc.annotation.Route)5 TipException (com.tale.exception.TipException)4 Take (com.blade.jdbc.core.Take)3 JSON (com.blade.mvc.annotation.JSON)3 Users (com.tale.model.Users)2 Paginator (com.blade.jdbc.model.Paginator)1 Comment (com.tale.dto.Comment)1 Statistics (com.tale.dto.Statistics)1 Contents (com.tale.model.Contents)1 Logs (com.tale.model.Logs)1 ArrayList (java.util.ArrayList)1