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);
}
}
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();
}
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";
}
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();
}
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();
}
Aggregations