Java Code Examples for com.jfinal.kit.Ret#set()

The following examples show how to use com.jfinal.kit.Ret#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserController.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Clear
@EmptyValidate({
        @Form(name = "user", message = "账号不能为空"),
        @Form(name = "pwd", message = "密码不能为空")
})
public void doLogin(String user, String pwd) {

    if (StrUtil.isBlank(user) || StrUtil.isBlank(pwd)) {
        LogKit.error("你当前的 idea 或者 eclipse 可能有问题,请参考文档:http://www.jfinal.com/doc/3-3 进行配置");
        return;
    }

    User loginUser = userService.findByUsernameOrEmail(user);
    if (loginUser == null) {
        renderJson(Ret.fail("message", "用户名不正确。"));
        return;
    }

    Ret ret = userService.doValidateUserPwd(loginUser, pwd);

    if (ret.isOk()) {
        CookieUtil.put(this, JPressConsts.COOKIE_UID, loginUser.getId());
    }

    String gotoUrl = JPressOptions.get("login_goto_url", "/ucenter");
    ret.set("gotoUrl", gotoUrl);

    renderJson(ret);
}
 
Example 2
Source File: ArticleApiController.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 发布评论
 */
public void postComment() {
    Long articleId = getParaToLong("articleId");
    Long pid = getParaToLong("pid");
    String content = getRawData();

    if (articleId == null || articleId <= 0) {
        renderFailJson();
        return;
    }

    if (StrUtil.isBlank(content)) {
        renderJson(Ret.fail().set("message", "评论内容不能为空"));
        return;
    } else {
        content = StrUtil.escapeHtml(content);
    }

    if (DFAUtil.isContainsSensitiveWords(content)){
        renderJson(Ret.fail().set("message", "非法内容,无法发布评论信息"));
        return;
    }


    Article article = articleService.findById(articleId);
    if (article == null) {
        renderFailJson();
        return;
    }

    // 文章关闭了评论的功能
    if (!article.isCommentEnable()) {
        renderJson(Ret.fail().set("message", "该文章的评论功能已关闭"));
        return;
    }

    //是否开启评论功能
    Boolean commentEnable = JPressOptions.isTrueOrEmpty("article_comment_enable");
    if (commentEnable == null || commentEnable == false) {
        renderJson(Ret.fail().set("message", "评论功能已关闭"));
        return;
    }

    User user = getLoginedUser();
    if (user == null) {
        renderJson(Ret.fail().set("message", "用户未登录"));
        return;
    }

    ArticleComment comment = new ArticleComment();

    comment.setArticleId(articleId);
    comment.setContent(content);
    comment.setPid(pid);
    comment.setEmail(user.getEmail());

    comment.setUserId(user.getId());
    comment.setAuthor(user.getNickname());

    comment.put("user", user.keepSafe());

    //是否是管理员必须审核
    Boolean reviewEnable = optionService.findAsBoolByKey("article_comment_review_enable");
    if (reviewEnable != null && reviewEnable == true) {
        comment.setStatus(ArticleComment.STATUS_UNAUDITED);
    }
    /**
     * 无需管理员审核、直接发布
     */
    else {
        comment.setStatus(ArticleComment.STATUS_NORMAL);
    }

    //记录文章的评论量
    articleService.doIncArticleCommentCount(articleId);

    if (pid != null) {
        //记录评论的回复数量
        commentService.doIncCommentReplyCount(pid);
    }
    commentService.saveOrUpdate(comment);

    Ret ret = Ret.ok();
    if (comment.isNormal()) {
        ret.set("comment", comment).set("code", 0);
    } else {
        ret.set("code", 0);
    }


    renderJson(ret);

    ArticleNotifyKit.notify(article, comment, user);
}