Here are the examples of the java api com.blade.mvc.http.Request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
56 Examples
19
Source : TaleUtils.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 获取cookie中的用户id
*
* @param request
* @return
*/
public static Integer getCookieUid(Request request) {
if (null != request) {
Optional<String> c = request.cookie(TaleConst.USER_IN_COOKIE);
if (c.isPresent()) {
try {
String value = c.get();
long[] ids = HASH_IDS.decode(value);
if (null != ids && ids.length > 0) {
return Long.valueOf(ids[0]).intValue();
}
} catch (Exception e) {
}
}
}
return null;
}
19
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 归档页
*
* @return
*/
@GetRoute(value = { "archives", "archives.html" })
public String archives(Request request) {
List<Archive> archives = siteService.getArchives();
request.attribute("archives", archives);
request.attribute("is_archive", true);
return this.render("archives");
}
19
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 搜索页
*
* @param keyword
* @return
*/
@GetRoute(value = { "search/:keyword", "search/:keyword.html" })
public String search(Request request, @PathParam String keyword, @Param(defaultValue = "12") int limit) {
return this.search(request, keyword, 1, limit);
}
19
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 首页
*
* @return
*/
@GetRoute
public String index(Request request, @Param(defaultValue = "12") int limit) {
return this.index(request, 1, limit);
}
19
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 首页分页
*
* @param request
* @param page
* @param limit
* @return
*/
@GetRoute(value = { "page/:page", "page/:page.html" })
public String index(Request request, @PathParam int page, @Param(defaultValue = "12") int limit) {
page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
if (page > 1) {
this.replacedle(request, "第" + page + "页");
}
request.attribute("page_num", page);
request.attribute("limit", limit);
request.attribute("is_home", true);
request.attribute("page_prefix", "/page");
return this.render("index");
}
19
Source : CategoryController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 某个分类详情页
*/
@GetRoute(value = { "category/:keyword", "category/:keyword.html" })
public String categories(Request request, @PathParam String keyword, @Param(defaultValue = "12") int limit) {
return this.categories(request, keyword, 1, limit);
}
19
Source : ThemeController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 主题设置页面
*
* @param request
* @return
*/
@GetRoute(value = "setting")
public String setting(Request request) {
String currentTheme = Commons.site_theme();
String key = "theme_" + currentTheme + "_options";
String option = optionsService.getOption(key);
Map<String, Object> map = new HashMap<>();
try {
if (StringKit.isNotBlank(option)) {
map = JsonKit.toAson(option);
}
request.attribute("theme_options", map);
} catch (Exception e) {
log.error("解析主题设置出现异常", e);
}
request.attribute("theme_options", map);
return this.render("setting");
}
19
Source : PageController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@Route(value = "new", method = HttpMethod.GET)
public String newPage(Request request) {
request.attribute(Types.ATTACH_URL, Commons.site_option(Types.ATTACH_URL, Commons.site_url()));
return "admin/page_edit";
}
19
Source : PageController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@Route(value = "/:cid", method = HttpMethod.GET)
public String editPage(@PathParam String cid, Request request) {
Optional<Contents> contents = contentsService.getContents(cid);
if (!contents.isPresent()) {
return render_404();
}
request.attribute("contents", contents.get());
request.attribute(Types.ATTACH_URL, Commons.site_option(Types.ATTACH_URL, Commons.site_url()));
return "admin/page_edit";
}
19
Source : PageController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@Route(value = "", method = HttpMethod.GET)
public String index(Request request) {
Page<Contents> contentsPage = new Contents().where("type", Types.PAGE).page(1, TaleConst.MAX_POSTS, "created desc");
request.attribute("articles", contentsPage);
return "admin/page_list";
}
19
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 仪表盘
*/
@Route(value = { "/", "index" }, method = HttpMethod.GET)
public String index(Request request) {
List<Comments> comments = siteService.recentComments(5);
List<Contents> contents = siteService.getContens(Types.RECENT_ARTICLE, 5);
Statistics statistics = siteService.getStatistics();
// 取最新的20条日志
Page<Logs> logsPage = new Logs().page(1, 20, "id desc");
List<Logs> logs = logsPage.getRows();
request.attribute("comments", comments);
request.attribute("articles", contents);
request.attribute("statistics", statistics);
request.attribute("logs", logs);
return "admin/index";
}
19
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 系统设置
*/
@Route(value = "setting", method = HttpMethod.GET)
public String setting(Request request) {
Map<String, String> options = optionsService.getOptions();
request.attribute("options", options);
return "admin/setting";
}
19
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 保存个人信息
*/
@Route(value = "profile", method = HttpMethod.POST)
@JSON
public RestResponse saveProfile(@Param String screen_name, @Param String email, Request request) {
Users users = this.user();
if (StringKit.isNotBlank(screen_name) && StringKit.isNotBlank(email)) {
Users temp = new Users();
temp.setScreen_name(screen_name);
temp.setEmail(email);
temp.update(users.getUid());
new Logs(LogActions.UP_INFO, JsonKit.toString(temp), request.address(), this.getUid()).save();
}
return RestResponse.ok();
}
19
Source : CommentController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@GetRoute(value = "")
public String index(@Param(defaultValue = "1") int page, @Param(defaultValue = "15") int limit, Request request) {
Users users = this.user();
Page<Comments> commentPage = new Comments().where("author_id", "<>", users.getUid()).page(page, limit);
request.attribute("comments", commentPage);
return "admin/comment_list";
}
19
Source : AttachController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 附件页面
*
* @param request
* @param page
* @param limit
* @return
*/
@Route(value = "", method = HttpMethod.GET)
public String index(Request request, @Param(defaultValue = "1") int page, @Param(defaultValue = "12") int limit) {
Attach attach = new Attach();
Page<Attach> attachPage = attach.page(page, limit);
request.attribute("attachs", attachPage);
request.attribute(Types.ATTACH_URL, Commons.site_option(Types.ATTACH_URL, Commons.site_url()));
request.attribute("max_file_size", TaleConst.MAX_FILE_SIZE / 1024);
return "admin/attach";
}
19
Source : ArticleController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 文章管理首页
*
* @param page
* @param limit
* @param request
* @return
*/
@GetRoute(value = "")
public String index(@Param(defaultValue = "1") int page, @Param(defaultValue = "15") int limit, Request request) {
Page<Contents> articles = new Contents().where("type", Types.ARTICLE).page(page, limit, "created desc");
request.attribute("articles", articles);
return "admin/article_list";
}
19
Source : AdminController.java
with MIT License
from biezhi
with MIT License
from biezhi
@GetRoute("template/:theme")
public String template(@PathParam String theme, Request request) throws IOException {
File themeDir = new File(Utils.CLreplacedPATH + "templates/themes/" + theme);
File[] files = themeDir.listFiles(pathname -> pathname.getName().endsWith(".html"));
List<Template> list = new ArrayList<>();
for (File file : Objects.requireNonNull(files)) {
list.add(new Template(file.getName(), IOKit.readToString(file.toPath())));
}
request.attribute("files", list);
request.attribute("theme", theme);
return "admin/template.html";
}
19
Source : AdminController.java
with MIT License
from biezhi
with MIT License
from biezhi
@GetRoute("orders")
public String orders(OrderParam orderParam, Request request) {
Page<Order> orders = makeMoneyService.findOrders(orderParam);
request.attribute("orderPage", orders);
return "admin/orders.html";
}
18
Source : Theme.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 分页
*
* @param limit
* @return
*/
public static Page<Contents> articles(int limit) {
Request request = WebContext.request();
Integer page = request.attribute("page_num");
page = null == page ? request.queryInt("page", 1) : page;
page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
Page<Contents> articles = new Contents().where("type", Types.ARTICLE).and("status", Types.PUBLISH).page(page, limit, "created desc");
request.attribute("articles", articles);
if (page > 1) {
WebContext.request().attribute("replacedle", "第" + page + "页");
}
request.attribute("is_home", true);
request.attribute("page_prefix", "/page");
return articles;
}
18
Source : InstallController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 安装页
*
* @return
*/
@Route(value = "/", method = HttpMethod.GET)
public String index(Request request) {
boolean existInstall = Files.exists(Paths.get(AttachController.CLreplacedPATH + "install.lock"));
int allow_reinstall = TaleConst.OPTIONS.getInt("allow_install", 0);
if (allow_reinstall == 1) {
request.attribute("is_install", false);
} else {
request.attribute("is_install", existInstall);
}
return "install";
}
18
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@GetRoute(value = { "search/:keyword/:page", "search/:keyword/:page.html" })
public String search(Request request, @PathParam String keyword, @PathParam int page, @Param(defaultValue = "12") int limit) {
page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
Page<Contents> articles = new Contents().where("type", Types.ARTICLE).and("status", Types.PUBLISH).like("replacedle", "%" + keyword + "%").page(page, limit, "created desc");
request.attribute("articles", articles);
request.attribute("type", "搜索");
request.attribute("keyword", keyword);
request.attribute("page_prefix", "/search/" + keyword);
return this.render("page-category");
}
18
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@GetRoute(value = { "search", "search.html" })
public String search(Request request, @Param(defaultValue = "12") int limit) {
String keyword = request.query("s").orElse("");
return this.search(request, keyword, 1, limit);
}
18
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 自定义页面
*/
@CsrfToken(newToken = true)
@GetRoute(value = { "/:cid", "/:cid.html" })
public String page(@PathParam String cid, Request request) {
Optional<Contents> contentsOptional = contentsService.getContents(cid);
if (!contentsOptional.isPresent()) {
return this.render_404();
}
Contents contents = contentsOptional.get();
if (contents.getAllowComment()) {
int cp = request.queryInt("cp", 1);
request.attribute("cp", cp);
}
request.attribute("article", contents);
Contents temp = new Contents();
temp.setHits(contents.getHits() + 1);
temp.update(contents.getCid());
if (Types.ARTICLE.equals(contents.getType())) {
return this.render("post");
}
if (Types.PAGE.equals(contents.getType())) {
return this.render("page");
}
return this.render_404();
}
18
Source : CategoryController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 标签详情页
*
* @param name 标签名
*/
@GetRoute(value = { "tag/:name", "tag/:name.html" })
public String tagPage(Request request, @PathParam String name, @Param(defaultValue = "12") int limit) {
return this.tags(request, name, 1, limit);
}
18
Source : BaseController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
public BaseController keywords(Request request, String keywords) {
request.attribute("keywords", keywords);
return this;
}
18
Source : BaseController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
public BaseController replacedle(Request request, String replacedle) {
request.attribute("replacedle", replacedle);
return this;
}
18
Source : ThemeController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@GetRoute(value = "")
public String index(Request request) {
// 读取主题
String themesDir = AttachController.CLreplacedPATH + "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 (Files.exists(Paths.get(f.getPath() + "/setting.html"))) {
themeDto.setHreplacedetting(true);
}
themes.add(themeDto);
try {
Blade.me().addStatics("/templates/themes/" + f.getName() + "/screenshot.png");
} catch (Exception e) {
}
}
}
request.attribute("current_theme", Commons.site_theme());
request.attribute("themes", themes);
return "admin/themes";
}
18
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 重启系统
*
* @param sleep
* @return
*/
@Route(value = "reload", method = HttpMethod.GET)
public void reload(@Param(defaultValue = "0") int sleep, Request request) {
if (sleep < 0 || sleep > 999) {
sleep = 10;
}
try {
// sh tale.sh reload 10
String webHome = new File(AttachController.CLreplacedPATH).getParent();
String cmd = "sh " + webHome + "/bin tale.sh reload " + sleep;
log.info("execute shell: {}", cmd);
ShellUtils.shell(cmd);
new Logs(LogActions.RELOAD_SYS, "", request.address(), this.getUid()).save();
TimeUnit.SECONDS.sleep(sleep);
} catch (Exception e) {
log.error("重启系统失败", e);
}
}
18
Source : ArticleController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 文章编辑页面
*
* @param cid
* @param request
* @return
*/
@GetRoute(value = "/:cid")
public String editArticle(@PathParam String cid, Request request) {
Optional<Contents> contents = contentsService.getContents(cid);
if (!contents.isPresent()) {
return render_404();
}
request.attribute("contents", contents.get());
List<Metas> categories = metreplacedervice.getMetas(Types.CATEGORY);
request.attribute("categories", categories);
request.attribute("active", "article");
request.attribute(Types.ATTACH_URL, Commons.site_option(Types.ATTACH_URL, Commons.site_url()));
return "admin/article_edit";
}
18
Source : ArticleController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 文章发布页面
*
* @param request
* @return
*/
@GetRoute(value = "publish")
public String newArticle(Request request) {
List<Metas> categories = metreplacedervice.getMetas(Types.CATEGORY);
request.attribute("categories", categories);
request.attribute(Types.ATTACH_URL, Commons.site_option(Types.ATTACH_URL, Commons.site_url()));
return "admin/article_edit";
}
18
Source : IndexController.java
with MIT License
from biezhi
with MIT License
from biezhi
/**
* 打赏首页
*
* @param orderParam
* @param request
* @return
*/
@GetRoute("/")
public String index(@Param OrderParam orderParam, Request request) {
Page<Order> orderPage = makeMoneyService.findOrders(orderParam);
request.attribute("orderPage", orderPage);
Map<String, String> options = makeMoneyService.findOptions();
request.attribute("options", options);
return "themes/" + THEME_NAME + "/index.html";
}
17
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 文章页
*/
@CsrfToken(newToken = true)
@GetRoute(value = { "article/:cid", "article/:cid.html" })
public String post(Request request, @PathParam String cid) {
Optional<Contents> contentsOptional = contentsService.getContents(cid);
if (!contentsOptional.isPresent()) {
return this.render_404();
}
Contents contents = contentsOptional.get();
if (Types.DRAFT.equals(contents.getStatus())) {
return this.render_404();
}
request.attribute("article", contents);
request.attribute("is_post", true);
if (contents.getAllowComment()) {
int cp = request.queryInt("cp", 1);
request.attribute("cp", cp);
}
Contents temp = new Contents();
temp.setHits(contents.getHits() + 1);
temp.update(contents.getCid());
return this.render("post");
}
17
Source : ThemeController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 保存主题配置项
*
* @param request
* @return
*/
@PostRoute(value = "setting")
@JSON
public RestResponse saveSetting(Request request) {
try {
Map<String, List<String>> query = request.parameters();
// theme_milk_options => { }
String currentTheme = Commons.site_theme();
String key = "theme_" + currentTheme + "_options";
Map<String, String> options = new HashMap<>();
query.forEach((k, v) -> options.put(k, v.get(0)));
optionsService.saveOption(key, JsonKit.toString(options));
TaleConst.OPTIONS = Environment.of(optionsService.getOptions());
new Logs(LogActions.THEME_SETTING, JsonKit.toString(query), request.address(), this.getUid()).save();
return RestResponse.ok();
} catch (Exception e) {
String msg = "主题设置失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
log.error(msg, e);
}
return RestResponse.fail(msg);
}
}
17
Source : PageController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@Route(value = "delete")
@JSON
public RestResponse delete(@Param int cid, Request request) {
try {
contentsService.delete(cid);
siteService.cleanCache(Types.C_STATISTICS);
new Logs(LogActions.DEL_PAGE, cid + "", request.address(), this.getUid()).save();
} catch (Exception e) {
String msg = "页面删除失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
log.error(msg, e);
}
return RestResponse.fail(msg);
}
return RestResponse.ok();
}
17
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 修改密码
*/
@Route(value = "preplacedword", method = HttpMethod.POST)
@JSON
public RestResponse upPwd(@Param String old_preplacedword, @Param String preplacedword, Request request) {
Users users = this.user();
if (StringKit.isBlank(old_preplacedword) || StringKit.isBlank(preplacedword)) {
return RestResponse.fail("请确认信息输入完整");
}
if (!users.getPreplacedword().equals(EncryptKit.md5(users.getUsername() + old_preplacedword))) {
return RestResponse.fail("旧密码错误");
}
if (preplacedword.length() < 6 || preplacedword.length() > 14) {
return RestResponse.fail("请输入6-14位密码");
}
try {
Users temp = new Users();
String pwd = EncryptKit.md5(users.getUsername() + preplacedword);
temp.setPreplacedword(pwd);
temp.update(users.getUid());
new Logs(LogActions.UP_PWD, null, request.address(), this.getUid()).save();
return RestResponse.ok();
} catch (Exception e) {
String msg = "密码修改失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
log.error(msg, e);
}
return RestResponse.fail(msg);
}
}
17
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 系统备份
*
* @return
*/
@Route(value = "backup", method = HttpMethod.POST)
@JSON
public RestResponse backup(@Param String bk_type, @Param String bk_path, Request request) {
if (StringKit.isBlank(bk_type)) {
return RestResponse.fail("请确认信息输入完整");
}
try {
BackResponse backResponse = siteService.backup(bk_type, bk_path, "yyyyMMddHHmm");
new Logs(LogActions.SYS_BACKUP, null, request.address(), this.getUid()).save();
return RestResponse.ok(backResponse);
} catch (Exception e) {
String msg = "备份失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
log.error(msg, e);
}
return RestResponse.fail(msg);
}
}
17
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 保存系统设置
*/
@Route(value = "setting", method = HttpMethod.POST)
@JSON
public RestResponse saveSetting(@Param String site_theme, Request request) {
try {
Map<String, List<String>> querys = request.parameters();
optionsService.saveOptions(querys);
Environment config = Environment.of(optionsService.getOptions());
TaleConst.OPTIONS = config;
new Logs(LogActions.SYS_SETTING, JsonKit.toString(querys), request.address(), this.getUid()).save();
return RestResponse.ok();
} catch (Exception e) {
String msg = "保存设置失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
log.error(msg, e);
}
return RestResponse.fail(msg);
}
}
17
Source : ArticleController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 删除文章操作
*
* @param cid
* @param request
* @return
*/
@Route(value = "delete")
@JSON
public RestResponse delete(@Param int cid, Request request) {
try {
contentsService.delete(cid);
siteService.cleanCache(Types.C_STATISTICS);
new Logs(LogActions.DEL_ARTICLE, cid + "", request.address(), this.getUid()).save();
} catch (Exception e) {
String msg = "文章删除失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
log.error(msg, e);
}
return RestResponse.fail(msg);
}
return RestResponse.ok();
}
17
Source : CallbackController.java
with MIT License
from biezhi
with MIT License
from biezhi
@PostRoute("payjs")
public String payjs(Request request) {
String body = request.bodyToString();
log.info("收到PAYJS支付回调1: {}", body);
return "success";
}
16
Source : BaseWebHook.java
with MIT License
from tfssweb
with MIT License
from tfssweb
private boolean isRedirect(Request request, Response response) {
Users user = TaleUtils.getLoginUser();
String uri = request.uri();
if (null == user) {
Integer uid = TaleUtils.getCookieUid(request);
if (null != uid) {
user = new Users().find(uid);
request.session().attribute(TaleConst.LOGIN_SESSION_KEY, user);
}
}
if (uri.startsWith(TaleConst.ADMIN_URI) && !uri.startsWith(TaleConst.LOGIN_URI)) {
if (null == user) {
response.redirect(TaleConst.LOGIN_URI);
return false;
}
request.attribute(TaleConst.PLUGINS_MENU_NAME, TaleConst.PLUGIN_MENUS);
}
return true;
}
16
Source : CategoryController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 分类列表页
*
* @since 1.3.1
*/
@GetRoute(value = { "categories", "categories.html" })
public String categories(Request request) {
Map<String, List<Contents>> mapping = metreplacedervice.getMetaMapping(Types.CATEGORY);
Set<String> categories = mapping.keySet();
request.attribute("categories", categories);
request.attribute("mapping", mapping);
return this.render("categories");
}
16
Source : CategoryController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 标签列表页面
* <p>
* 渲染所有的标签和文章映射
*
* @since 1.3.1
*/
@GetRoute(value = { "tags", "tags.html" })
public String tags(Request request) {
Map<String, List<Contents>> mapping = metreplacedervice.getMetaMapping(Types.TAG);
Set<String> tags = mapping.keySet();
request.attribute("tags", tags);
request.attribute("mapping", mapping);
return this.render("tags");
}
16
Source : ThemeController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 激活主题
*
* @param request
* @param site_theme
* @return
*/
@PostRoute(value = "active")
@JSON
public RestResponse activeTheme(Request request, @Param String site_theme) {
try {
optionsService.saveOption("site_theme", site_theme);
optionsService.deleteOption("theme_option_");
TaleConst.OPTIONS.set("site_theme", site_theme);
BaseController.THEME = "themes/" + site_theme;
String themePath = "/templates/themes/" + site_theme;
try {
TaleLoader.loadTheme(themePath);
} catch (Exception e) {
}
new Logs(LogActions.THEME_SETTING, site_theme, request.address(), this.getUid()).save();
return RestResponse.ok();
} catch (Exception e) {
String msg = "主题启用失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
log.error(msg, e);
}
return RestResponse.fail(msg);
}
}
16
Source : XssMiddleware.java
with MIT License
from biezhi
with MIT License
from biezhi
protected void filterParameters(Request request) {
Map<String, List<String>> parameters = request.parameters();
Set<Map.Entry<String, List<String>>> entries = parameters.entrySet();
for (Map.Entry<String, List<String>> entry : entries) {
List<String> snzValues = entry.getValue().stream().map(this::stripXSS).collect(Collectors.toList());
parameters.put(entry.getKey(), snzValues);
}
}
15
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 评论操作
*/
@CsrfToken(valid = true)
@PostRoute(value = "comment")
@JSON
public RestResponse comment(Request request, Response response, @HeaderParam String Referer, @Valid Comments comments) {
if (StringKit.isBlank(Referer)) {
return RestResponse.fail(ErrorCode.BAD_REQUEST);
}
if (!Referer.startsWith(Commons.site_url())) {
return RestResponse.fail("非法评论来源");
}
String val = request.address() + ":" + comments.getCid();
Integer count = cache.hget(Types.COMMENTS_FREQUENCY, val);
if (null != count && count > 0) {
return RestResponse.fail("您发表评论太快了,请过会再试");
}
comments.setAuthor(TaleUtils.cleanXSS(comments.getAuthor()));
comments.setContent(TaleUtils.cleanXSS(comments.getContent()));
comments.setAuthor(EmojiParser.parseToAliases(comments.getAuthor()));
comments.setContent(EmojiParser.parseToAliases(comments.getContent()));
comments.setIp(request.address());
comments.setParent(comments.getCoid());
try {
commentsService.saveComment(comments);
response.cookie("tale_remember_author", URLEncoder.encode(comments.getAuthor(), "UTF-8"), 7 * 24 * 60 * 60);
response.cookie("tale_remember_mail", URLEncoder.encode(comments.getMail(), "UTF-8"), 7 * 24 * 60 * 60);
if (StringKit.isNotBlank(comments.getUrl())) {
response.cookie("tale_remember_url", URLEncoder.encode(comments.getUrl(), "UTF-8"), 7 * 24 * 60 * 60);
}
// 设置对每个文章30秒可以评论一次
cache.hset(Types.COMMENTS_FREQUENCY, val, 1, 30);
siteService.cleanCache(Types.C_STATISTICS);
return RestResponse.ok();
} catch (Exception e) {
String msg = "评论发布失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
log.error(msg, e);
}
return RestResponse.fail(msg);
}
}
15
Source : CategoryController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 某个分类详情页分页
*/
@GetRoute(value = { "category/:keyword/:page", "category/:keyword/:page.html" })
public String categories(Request request, @PathParam String keyword, @PathParam int page, @Param(defaultValue = "12") int limit) {
page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
Metas metaDto = metreplacedervice.getMeta(Types.CATEGORY, keyword);
if (null == metaDto) {
return this.render_404();
}
Page<Contents> contentsPage = contentsService.getArticles(metaDto.getMid(), page, limit);
request.attribute("articles", contentsPage);
request.attribute("meta", metaDto);
request.attribute("type", "分类");
request.attribute("keyword", keyword);
request.attribute("is_category", true);
request.attribute("page_prefix", "/category/" + keyword);
return this.render("page-category");
}
15
Source : CategoryController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 标签下文章分页
*/
@GetRoute(value = { "tag/:name/:page", "tag/:name/:page.html" })
public String tags(Request request, @PathParam String name, @PathParam int page, @Param(defaultValue = "12") int limit) {
page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
Metas metaDto = metreplacedervice.getMeta(Types.TAG, name);
if (null == metaDto) {
return this.render_404();
}
Page<Contents> contentsPage = contentsService.getArticles(metaDto.getMid(), page, limit);
request.attribute("articles", contentsPage);
request.attribute("meta", metaDto);
request.attribute("type", "标签");
request.attribute("keyword", name);
request.attribute("is_tag", true);
request.attribute("page_prefix", "/tag/" + name);
return this.render("page-category");
}
15
Source : TemplateController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@Route(value = "", method = HttpMethod.GET)
public String index(Request request) {
String themePath = Const.CLreplacedPATH + File.separatorChar + "templates" + File.separatorChar + "themes" + File.separatorChar + Commons.site_theme();
try {
List<String> files = Files.list(Paths.get(themePath)).map(path -> path.getFileName().toString()).filter(path -> path.endsWith(".html")).collect(Collectors.toList());
List<String> partial = Files.list(Paths.get(themePath + File.separatorChar + "partial")).map(path -> path.getFileName().toString()).filter(path -> path.endsWith(".html")).map(fileName -> "partial/" + fileName).collect(Collectors.toList());
List<String> statics = Files.list(Paths.get(themePath + File.separatorChar + "static")).map(path -> path.getFileName().toString()).filter(path -> path.endsWith(".js") || path.endsWith(".css")).map(fileName -> "static/" + fileName).collect(Collectors.toList());
files.addAll(partial);
files.addAll(statics);
request.attribute("tpls", files);
} catch (IOException e) {
log.error("找不到模板路径");
}
return "admin/tpl_list";
}
15
Source : CategoryController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@Route(value = "", method = HttpMethod.GET)
public String index(Request request) {
List<Metas> categories = siteService.getMetas(Types.RECENT_META, Types.CATEGORY, TaleConst.MAX_POSTS);
List<Metas> tags = siteService.getMetas(Types.RECENT_META, Types.TAG, TaleConst.MAX_POSTS);
request.attribute("categories", categories);
request.attribute("tags", tags);
return "admin/category";
}
15
Source : AttachController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
@Route(value = "delete")
@JSON
public RestResponse delete(@Param Integer id, Request request) {
try {
Attach attach = new Attach().find(id);
if (null == attach) {
return RestResponse.fail("不存在该附件");
}
String fkey = attach.getFkey();
siteService.cleanCache(Types.C_STATISTICS);
String filePath = CLreplacedPATH.substring(0, CLreplacedPATH.length() - 1) + fkey;
java.nio.file.Path path = Paths.get(filePath);
log.info("Delete attach: [{}]", filePath);
if (Files.exists(path)) {
Files.delete(path);
}
attach.delete(id);
new Logs(LogActions.DEL_ATTACH, fkey, request.address(), this.getUid()).save();
} catch (Exception e) {
String msg = "附件删除失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
log.error(msg, e);
}
return RestResponse.fail(msg);
}
return RestResponse.ok();
}
See More Examples