Search in sources :

Example 6 with TipException

use of com.tale.exception.TipException in project tale by otale.

the class ArticleController method modifyArticle.

/**
     * 修改文章操作
     *
     * @param cid
     * @param title
     * @param content
     * @param tags
     * @param categories
     * @param status
     * @param slug
     * @param allow_comment
     * @param allow_ping
     * @param allow_feed
     * @return
     */
@Route(value = "modify", method = HttpMethod.POST)
@JSON
public RestResponse modifyArticle(@QueryParam Integer cid, @QueryParam String title, @QueryParam String content, @QueryParam String fmt_type, @QueryParam String tags, @QueryParam String categories, @QueryParam String status, @QueryParam String slug, @QueryParam String thumb_img, @QueryParam Boolean allow_comment, @QueryParam Boolean allow_ping, @QueryParam Boolean allow_feed) {
    Users users = this.user();
    Contents contents = new Contents();
    contents.setCid(cid);
    contents.setTitle(title);
    contents.setContent(content);
    contents.setStatus(status);
    contents.setFmt_type(fmt_type);
    contents.setSlug(slug);
    contents.setThumb_img(thumb_img);
    if (null != allow_comment) {
        contents.setAllow_comment(allow_comment);
    }
    if (null != allow_ping) {
        contents.setAllow_ping(allow_ping);
    }
    if (null != allow_feed) {
        contents.setAllow_feed(allow_feed);
    }
    contents.setAuthor_id(users.getUid());
    contents.setTags(tags);
    contents.setCategories(categories);
    try {
        contentsService.updateArticle(contents);
        return RestResponse.ok(cid);
    } catch (Exception e) {
        String msg = "文章编辑失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}
Also used : Contents(com.tale.model.Contents) Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Example 7 with TipException

use of com.tale.exception.TipException in project tale by otale.

the class ArticleController method publishArticle.

/**
     * 发布文章操作
     *
     * @param title
     * @param content
     * @param tags
     * @param categories
     * @param status
     * @param slug
     * @param allow_comment
     * @param allow_ping
     * @param allow_feed
     * @return
     */
@Route(value = "publish", method = HttpMethod.POST)
@JSON
public RestResponse publishArticle(@QueryParam String title, @QueryParam String content, @QueryParam String tags, @QueryParam String categories, @QueryParam String status, @QueryParam String slug, @QueryParam String fmt_type, @QueryParam String thumb_img, @QueryParam Boolean allow_comment, @QueryParam Boolean allow_ping, @QueryParam Boolean allow_feed) {
    Users users = this.user();
    Contents contents = new Contents();
    contents.setTitle(title);
    contents.setContent(content);
    contents.setStatus(status);
    contents.setSlug(slug);
    contents.setType(Types.ARTICLE);
    contents.setThumb_img(thumb_img);
    contents.setFmt_type(fmt_type);
    if (null != allow_comment) {
        contents.setAllow_comment(allow_comment);
    }
    if (null != allow_ping) {
        contents.setAllow_ping(allow_ping);
    }
    if (null != allow_feed) {
        contents.setAllow_feed(allow_feed);
    }
    contents.setAuthor_id(users.getUid());
    contents.setTags(tags);
    if (StringKit.isBlank(categories)) {
        categories = "默认分类";
    }
    contents.setCategories(categories);
    try {
        Integer cid = contentsService.publish(contents);
        siteService.cleanCache(Types.C_STATISTICS);
        return RestResponse.ok(cid);
    } catch (Exception e) {
        String msg = "文章发布失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}
Also used : Contents(com.tale.model.Contents) Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Example 8 with TipException

use of com.tale.exception.TipException in project tale by otale.

the class AuthController method doLogin.

@Route(value = "login", method = HttpMethod.POST)
@JSON
public RestResponse doLogin(@QueryParam String username, @QueryParam String password, @QueryParam String remeber_me, Request request, Session session, Response response) {
    Integer error_count = cache.get("login_error_count");
    try {
        error_count = null == error_count ? 0 : error_count;
        if (null != error_count && error_count > 3) {
            return RestResponse.fail("您输入密码已经错误超过3次,请10分钟后尝试");
        }
        Users user = usersService.login(username, password);
        session.attribute(TaleConst.LOGIN_SESSION_KEY, user);
        if (StringKit.isNotBlank(remeber_me)) {
            TaleUtils.setCookie(response, user.getUid());
        }
        Users temp = new Users();
        temp.setUid(user.getUid());
        temp.setLogged(DateKit.getCurrentUnixTime());
        usersService.update(temp);
        LOGGER.info("登录成功:{}", JSONKit.toJSONString(request.querys()));
        cache.set("login_error_count", 0);
        logService.save(LogActions.LOGIN, JSONKit.toJSONString(request.querys()), request.address(), user.getUid());
    } catch (Exception e) {
        error_count += 1;
        cache.set("login_error_count", error_count, 10 * 60);
        String msg = "登录失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 9 with TipException

use of com.tale.exception.TipException 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 10 with TipException

use of com.tale.exception.TipException 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)

Aggregations

TipException (com.tale.exception.TipException)24 JSON (com.blade.mvc.annotation.JSON)12 Route (com.blade.mvc.annotation.Route)12 Users (com.tale.model.Users)10 Contents (com.tale.model.Contents)7 Comments (com.tale.model.Comments)4 Take (com.blade.jdbc.core.Take)3 Config (com.blade.kit.base.Config)3 Attach (com.tale.model.Attach)2 Metas (com.tale.model.Metas)2 File (java.io.File)2 IOException (java.io.IOException)2 FileItem (com.blade.mvc.multipart.FileItem)1 RestResponse (com.blade.mvc.view.RestResponse)1 BackResponse (com.tale.dto.BackResponse)1 ArrayList (java.util.ArrayList)1