@JSON @PostRoute("api_test/:size") public RestResponse<Integer> api_portal(@PathParam Integer size) { return RestResponse.ok(size); }
@PostRoute("save") @JSON public RestResponse savePerson(@BodyParam Map<String, Object> person) { return RestResponse.ok(person); }
@PostRoute("upload") @JSON public RestResponse upload(@MultipartParam FileItem fileItem) throws IOException { System.out.println(fileItem); fileItem.moveTo(new File(fileItem.getFileName())); return RestResponse.ok(); }
@PostRoute("template") @JSON public RestResponse updateTemplate(@BodyParam TemplateParam templateParam) throws IOException { java.nio.file.Path file = Paths.get(Utils.CLASSPATH + "templates/themes/" + templateParam.getTheme() + "/" + templateParam.getFileName()); Files.write(file, templateParam.getContent().getBytes()); return RestResponse.ok(); }
@PostRoute("order/delete/:orderNo") @JSON public RestResponse orders(@PathParam String orderNo) { Anima.deleteById(Order.class, orderNo); return RestResponse.ok(); }
@Route(value = "delete") @JSON public RestResponse delete(@Param int mid) { try { metasService.delete(mid); siteService.cleanCache(Types.C_STATISTICS); } catch (Exception e) { String msg = "删除失败"; if (e instanceof TipException) { msg = e.getMessage(); } else { log.error(msg, e); } return RestResponse.fail(msg); } return RestResponse.ok(); }
@Route(value = "save", method = HttpMethod.POST) @JSON public RestResponse saveCategory(@Param String cname, @Param Integer mid) { try { metasService.saveMeta(Types.CATEGORY, cname, mid); siteService.cleanCache(Types.C_STATISTICS); } catch (Exception e) { String msg = "分类保存失败"; if (e instanceof TipException) { msg = e.getMessage(); } else { log.error(msg, e); } return RestResponse.fail(msg); } return RestResponse.ok(); }
/** * 修改通用配置 */ @PostRoute("common_config") @JSON public RestResponse updateOptions(@BodyParam Map<String, String> options) { optionService.updateOptions(options); Bootstrap.refreshConfig(); return RestResponse.ok(); }
@PostRoute("black") @JSON public RestResponse updateBlackList(@BodyParam InstallParam installParam) { installParam.setUpdate(true); optionService.updatePayConfig(installParam); return RestResponse.ok(); }
@PostRoute("password") @JSON public RestResponse updatePassword(@Param PasswordParam passwordParam) { Option option = select().from(Option.class) .where(Option::getKey, Constant.SAFE_PASSWORD).one(); String base64 = Base64.getEncoder().encodeToString(option.getValue().getBytes()); boolean success = PasswordKit.checkPassword(passwordParam.getOldPass(), new String(Base64.getDecoder().decode(base64))); if (!success) { return RestResponse.fail("旧密码输入错误, 无法修改!"); } String pass = PasswordKit.hashPassword(passwordParam.getNewPass()); update().from(Option.class) .set(Option::getValue, pass) .where(Option::getKey, Constant.SAFE_PASSWORD).execute(); return RestResponse.ok(); }
@Route(value = "modify", method = HttpMethod.POST) @JSON public RestResponse modifyArticle(@Valid Contents contents) { if (null == contents || null == contents.getCid()) { return RestResponse.fail("缺少参数,请重试"); } try { Integer cid = contents.getCid(); contents.setType(Types.PAGE); contentsService.updateArticle(contents); return RestResponse.ok(cid); } catch (Exception e) { String msg = "页面编辑失败"; if (e instanceof TipException) { msg = e.getMessage(); } else { log.error(msg, e); } return RestResponse.fail(msg); } }
@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(); } }
@PostRoute(value = "status") @JSON public RestResponse delete(@Param Integer coid, @Param String status) { try { Comments comments = new Comments(); comments.setCoid(coid); comments.setStatus(status); comments.update(); siteService.cleanCache(Types.C_STATISTICS); } catch (Exception e) { String msg = "操作失败"; if (e instanceof TipException) { msg = e.getMessage(); } else { log.error(msg, e); } return RestResponse.fail(msg); } return RestResponse.ok(); }
/** * 创建支付订单 * * @param order * @param request * @return */ @PostRoute("/pay_order") @JSON public RestResponse<PayOrderResponse> createOrder(Order order, Request request) { try { Validator.orderParam(order); if (null == request.header("") || null == request.userAgent()) { return RestResponse.fail("非法请求"); } return RestResponse.ok(makeMoneyService.createOrder(order)); } catch (ValidatorException e) { return RestResponse.fail(e.getMessage()); } catch (Exception e) { log.error("支付出现异常", e); return RestResponse.fail(e.getMessage()); } }
/** * 修改支付配置 */ @PostRoute("pay_config") @JSON public RestResponse updatePayConfig(@BodyParam InstallParam installParam) { installParam.setUpdate(true); optionService.updatePayConfig(installParam); Bootstrap.payApi = PayApi.getPayApi(installParam.getPlatform()); Bootstrap.refreshConfig(); return RestResponse.ok(); }
@Route(value = "publish", method = HttpMethod.POST) @JSON public RestResponse publishPage(@Valid Contents contents) { Users users = this.user(); contents.setType(Types.PAGE); contents.setAllowPing(true); contents.setAuthorId(users.getUid()); try { contentsService.publish(contents); siteService.cleanCache(Types.C_STATISTICS); } catch (Exception e) { String msg = "页面发布失败"; if (e instanceof TipException) { msg = e.getMessage(); } else { log.error(msg, e); } return RestResponse.fail(msg); } return RestResponse.ok(); }
@PostRoute("login") @JSON public RestResponse doLogin(@BodyParam LoginParam loginParam, Session session) { Validator.authParam(loginParam.getUsername(), loginParam.getPassword()); long username = select().from(Option.class) .where(Option::getKey, Constant.SAFE_USERNAME) .and(Option::getValue, loginParam.getUsername()) .count(); if (username == 0) { return RestResponse.fail("要饭先把名字输对,O不OK?"); } Option option = select().from(Option.class) .where(Option::getKey, Constant.SAFE_PASSWORD).one(); String base64 = Base64.getEncoder().encodeToString(option.getValue().getBytes()); boolean success = PasswordKit.checkPassword(loginParam.getPassword(), new String(Base64.getDecoder().decode(base64))); if (success) { session.attribute(Constant.LOGIN_SESSION_KEY, username); return RestResponse.ok(); } return RestResponse.fail("密码都输不对的人没资格要饭 (σ`д′)σ"); }
@PostRoute("theme/:name") @JSON public RestResponse updateTheme(@PathParam String name) { IndexController.THEME_NAME = name; update().from(Option.class) .set(Option::getValue, name) .where(Option::getKey, Constant.CURRENT_THEME).execute(); Bootstrap.refreshConfig(); return RestResponse.ok(); }
/** * 保存个人信息 */ @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(); }