Search in sources :

Example 11 with Users

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

the class CommentController method reply.

@Route(value = "", method = HttpMethod.POST)
@JSON
public RestResponse reply(@QueryParam Integer coid, @QueryParam String content, Request request) {
    if (null == coid || StringKit.isBlank(content)) {
        return RestResponse.fail("请输入完整后评论");
    }
    if (content.length() > 2000) {
        return RestResponse.fail("请输入2000个字符以内的回复");
    }
    Comments c = commentsService.byId(coid);
    if (null == c) {
        return RestResponse.fail("不存在该评论");
    }
    Users users = this.user();
    content = TaleUtils.cleanXSS(content);
    content = EmojiParser.parseToAliases(content);
    Comments comments = new Comments();
    comments.setAuthor(users.getUsername());
    comments.setAuthor_id(users.getUid());
    comments.setCid(c.getCid());
    comments.setIp(request.address());
    comments.setUrl(users.getHome_url());
    comments.setContent(content);
    if (StringKit.isNotBlank(users.getEmail())) {
        comments.setMail(users.getEmail());
    } else {
        comments.setMail("support@tale.me");
    }
    comments.setParent(coid);
    try {
        commentsService.saveComment(comments);
        siteService.cleanCache(Types.C_STATISTICS);
        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) 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 12 with Users

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

the class IndexController method saveProfile.

/**
     * 保存个人信息
     */
@Route(value = "profile", method = HttpMethod.POST)
@JSON
public RestResponse saveProfile(@QueryParam String screen_name, @QueryParam String email, Request request) {
    Users users = this.user();
    if (StringKit.isNotBlank(screen_name) && StringKit.isNotBlank(email)) {
        Users temp = new Users();
        temp.setUid(users.getUid());
        temp.setScreen_name(screen_name);
        temp.setEmail(email);
        usersService.update(temp);
        logService.save(LogActions.UP_INFO, JSONKit.toJSONString(temp), request.address(), this.getUid());
    }
    return RestResponse.ok();
}
Also used : Users(com.tale.model.Users) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 13 with Users

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

the class InstallController method doInstall.

@Route(value = "/", method = HttpMethod.POST)
@JSON
public RestResponse doInstall(@QueryParam String site_title, @QueryParam String site_url, @QueryParam String admin_user, @QueryParam String admin_email, @QueryParam String admin_pwd) {
    if (FileKit.exist(AttachController.CLASSPATH + "install.lock") && TaleConst.OPTIONS.getInt("allow_install", 0) != 1) {
        return RestResponse.fail("请勿重复安装");
    }
    try {
        if (StringKit.isBlank(site_title) || StringKit.isBlank(site_url) || StringKit.isBlank(admin_user) || StringKit.isBlank(admin_pwd)) {
            return RestResponse.fail("请确认网站信息输入完整");
        }
        if (admin_pwd.length() < 6 || admin_pwd.length() > 14) {
            return RestResponse.fail("请输入6-14位密码");
        }
        if (StringKit.isNotBlank(admin_email) && !TaleUtils.isEmail(admin_email)) {
            return RestResponse.fail("邮箱格式不正确");
        }
        Users users = new Users();
        users.setUsername(admin_user);
        users.setPassword(admin_pwd);
        users.setEmail(admin_email);
        siteService.initSite(users);
        if (site_url.endsWith("/")) {
            site_url = site_url.substring(0, site_url.length() - 1);
        }
        if (!site_url.startsWith("http")) {
            site_url = "http://".concat(site_url);
        }
        optionsService.saveOption("site_title", site_title);
        optionsService.saveOption("site_url", site_url);
        Config config = new Config();
        config.addAll(optionsService.getOptions());
        TaleConst.OPTIONS = config;
    } 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 : Config(com.blade.kit.base.Config) 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 14 with Users

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

the class PageController method publishPage.

@Route(value = "publish", method = HttpMethod.POST)
@JSON
public RestResponse publishPage(@QueryParam String title, @QueryParam String content, @QueryParam String status, @QueryParam String slug, @QueryParam String fmt_type, @QueryParam Boolean allow_comment) {
    Users users = this.user();
    Contents contents = new Contents();
    contents.setTitle(title);
    contents.setContent(content);
    contents.setStatus(status);
    contents.setSlug(slug);
    contents.setFmt_type(fmt_type);
    contents.setType(Types.PAGE);
    contents.setAllow_comment(allow_comment);
    contents.setAllow_ping(true);
    contents.setAuthor_id(users.getUid());
    try {
        contentsService.publish(contents);
        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 : 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