Search in sources :

Example 1 with Users

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

the class PageController method modifyArticle.

@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 status, @QueryParam String slug, @QueryParam Boolean allow_comment) {
    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.setType(Types.PAGE);
    contents.setAllow_comment(allow_comment);
    contents.setAllow_ping(true);
    contents.setAuthor_id(users.getUid());
    try {
        contentsService.updateArticle(contents);
    } 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 : Contents(com.tale.model.Contents) Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException)

Example 2 with Users

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

the class BaseInterceptor method before.

@Override
public boolean before(Request request, Response response) {
    String uri = request.uri();
    String ip = IPKit.getIpAddrByRequest(request.raw());
    // 禁止该ip访问
    if (TaleConst.BLOCK_IPS.contains(ip)) {
        response.text("You have been banned, brother");
        return false;
    }
    LOGGE.info("UserAgent: {}", request.userAgent());
    LOGGE.info("用户访问地址: {}, 来路地址: {}", uri, ip);
    if (!TaleConst.INSTALL && !uri.startsWith("/install")) {
        response.go("/install");
        return false;
    }
    if (TaleConst.INSTALL) {
        Users user = TaleUtils.getLoginUser();
        if (null == user) {
            Integer uid = TaleUtils.getCookieUid(request);
            if (null != uid) {
                user = usersService.byId(Integer.valueOf(uid));
                request.session().attribute(TaleConst.LOGIN_SESSION_KEY, user);
            }
        }
        if (uri.startsWith("/admin") && !uri.startsWith("/admin/login")) {
            if (null == user) {
                response.go("/admin/login");
                return false;
            }
            request.attribute("plugin_menus", TaleConst.plugin_menus);
        }
    }
    String method = request.method();
    if (method.equals("GET")) {
        String csrf_token = UUID.UU64();
        // 默认存储20分钟
        int timeout = TaleConst.BCONF.getInt("app.csrf-token-timeout", 20) * 60;
        cache.hset(Types.CSRF_TOKEN, csrf_token, uri, timeout);
        request.attribute("_csrf_token", csrf_token);
    }
    return true;
}
Also used : Users(com.tale.model.Users)

Example 3 with Users

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

the class TaleUtils method getLoginUser.

/**
     * 返回当前登录用户
     *
     * @return
     */
public static Users getLoginUser() {
    Session session = WebContextHolder.session();
    if (null == session) {
        return null;
    }
    Users user = session.attribute(TaleConst.LOGIN_SESSION_KEY);
    return user;
}
Also used : Users(com.tale.model.Users) Session(com.blade.mvc.http.wrapper.Session)

Example 4 with Users

use of com.tale.model.Users 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 5 with Users

use of com.tale.model.Users 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)

Aggregations

Users (com.tale.model.Users)14 TipException (com.tale.exception.TipException)10 Route (com.blade.mvc.annotation.Route)7 JSON (com.blade.mvc.annotation.JSON)6 Contents (com.tale.model.Contents)4 Take (com.blade.jdbc.core.Take)2 Comments (com.tale.model.Comments)2 Config (com.blade.kit.base.Config)1 Session (com.blade.mvc.http.wrapper.Session)1 FileItem (com.blade.mvc.multipart.FileItem)1 RestResponse (com.blade.mvc.view.RestResponse)1 Attach (com.tale.model.Attach)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1