Search in sources :

Example 11 with JSON

use of com.blade.mvc.annotation.JSON 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 12 with JSON

use of com.blade.mvc.annotation.JSON 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 13 with JSON

use of com.blade.mvc.annotation.JSON 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 14 with JSON

use of com.blade.mvc.annotation.JSON 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

JSON (com.blade.mvc.annotation.JSON)14 Route (com.blade.mvc.annotation.Route)13 TipException (com.tale.exception.TipException)12 Users (com.tale.model.Users)6 Config (com.blade.kit.base.Config)3 Comments (com.tale.model.Comments)3 Attach (com.tale.model.Attach)2 IOException (java.io.IOException)2 BladeException (com.blade.exception.BladeException)1 RestController (com.blade.mvc.annotation.RestController)1 FileItem (com.blade.mvc.multipart.FileItem)1 ModelAndView (com.blade.mvc.view.ModelAndView)1 RestResponse (com.blade.mvc.view.RestResponse)1 BackResponse (com.tale.dto.BackResponse)1 Metas (com.tale.model.Metas)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1