Search in sources :

Example 1 with Route

use of com.blade.mvc.annotation.Route in project tale by otale.

the class IndexController method reload.

/**
     * 重启系统
     * @param sleep
     * @return
     */
@Route(value = "reload", method = HttpMethod.GET)
public void reload(@QueryParam(value = "sleep", defaultValue = "0") int sleep, Request request) {
    if (sleep < 0 || sleep > 999) {
        sleep = 10;
    }
    try {
        // sh tale.sh reload 10
        String webHome = new File(AttachController.CLASSPATH).getParent();
        String cmd = "sh " + webHome + "/bin tale.sh reload " + sleep;
        LOGGER.info("execute shell: {}", cmd);
        ShellUtils.shell(cmd);
        logService.save(LogActions.RELOAD_SYS, "", request.address(), this.getUid());
        TimeUnit.SECONDS.sleep(sleep);
    } catch (Exception e) {
        LOGGER.error("重启系统失败", e);
    }
}
Also used : File(java.io.File) TipException(com.tale.exception.TipException) Route(com.blade.mvc.annotation.Route)

Example 2 with Route

use of com.blade.mvc.annotation.Route in project tale by otale.

the class LinksController method saveLink.

@Route(value = "save", method = HttpMethod.POST)
@JSON
public RestResponse saveLink(@QueryParam String title, @QueryParam String url, @QueryParam String logo, @QueryParam Integer mid, @QueryParam(value = "sort", defaultValue = "0") int sort) {
    try {
        Metas metas = new Metas();
        metas.setName(title);
        metas.setSlug(url);
        metas.setDescription(logo);
        metas.setSort(sort);
        metas.setType(Types.LINK);
        if (null != mid) {
            metas.setMid(mid);
            metasService.update(metas);
        } else {
            metasService.saveMeta(metas);
        }
        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 : Metas(com.tale.model.Metas) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 3 with Route

use of com.blade.mvc.annotation.Route in project tale by otale.

the class ThemeController method index.

@Route(value = "", method = HttpMethod.GET)
public String index(Request request) {
    // 读取主题
    String themesDir = AttachController.CLASSPATH + "templates/themes";
    File[] themesFile = new File(themesDir).listFiles();
    List<ThemeDto> themes = new ArrayList<>(themesFile.length);
    for (File f : themesFile) {
        if (f.isDirectory()) {
            ThemeDto themeDto = new ThemeDto(f.getName());
            if (FileKit.exist(f.getPath() + "/setting.html")) {
                themeDto.setHasSetting(true);
            }
            themes.add(themeDto);
            try {
                Blade.$().embedServer().addStatic("/templates/themes/" + f.getName() + "/screenshot.png");
            } catch (Exception e) {
            }
        }
    }
    request.attribute("current_theme", Commons.site_theme());
    request.attribute("themes", themes);
    return "admin/themes";
}
Also used : ThemeDto(com.tale.dto.ThemeDto) ArrayList(java.util.ArrayList) File(java.io.File) TipException(com.tale.exception.TipException) Route(com.blade.mvc.annotation.Route)

Example 4 with Route

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

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

Aggregations

Route (com.blade.mvc.annotation.Route)18 TipException (com.tale.exception.TipException)14 JSON (com.blade.mvc.annotation.JSON)13 Users (com.tale.model.Users)7 Comments (com.tale.model.Comments)5 Config (com.blade.kit.base.Config)3 File (java.io.File)3 Attach (com.tale.model.Attach)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Take (com.blade.jdbc.core.Take)1 Controller (com.blade.mvc.annotation.Controller)1 RestController (com.blade.mvc.annotation.RestController)1 HttpMethod (com.blade.mvc.http.HttpMethod)1 FileItem (com.blade.mvc.multipart.FileItem)1 RestResponse (com.blade.mvc.view.RestResponse)1 BackResponse (com.tale.dto.BackResponse)1 Statistics (com.tale.dto.Statistics)1 ThemeDto (com.tale.dto.ThemeDto)1 Contents (com.tale.model.Contents)1