Search in sources :

Example 21 with TipException

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

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

the class IndexController method backup.

/**
     * 系统备份
     * @return
     */
@Route(value = "backup", method = HttpMethod.POST)
@JSON
public RestResponse backup(@QueryParam String bk_type, @QueryParam String bk_path, Request request) {
    if (StringKit.isBlank(bk_type)) {
        return RestResponse.fail("请确认信息输入完整");
    }
    try {
        BackResponse backResponse = siteService.backup(bk_type, bk_path, "yyyyMMddHHmm");
        logService.save(LogActions.SYS_BACKUP, null, request.address(), this.getUid());
        return RestResponse.ok(backResponse);
    } catch (Exception e) {
        String msg = "备份失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}
Also used : BackResponse(com.tale.dto.BackResponse) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 23 with TipException

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

Example 24 with TipException

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

the class ThemeController method saveSetting.

/**
     * 保存主题配置项
     * @param request
     * @return
     */
@Route(value = "setting", method = HttpMethod.POST)
@JSON
public RestResponse saveSetting(Request request) {
    try {
        Map<String, String> querys = request.querys();
        optionsService.saveOptions(querys);
        Config config = new Config();
        config.addAll(optionsService.getOptions());
        TaleConst.OPTIONS = config;
        logService.save(LogActions.THEME_SETTING, JSONKit.toJSONString(querys), request.address(), this.getUid());
        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 : Config(com.blade.kit.base.Config) 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