public void notify(@BodyParam NotifyType notifyType) { }
@PostRoute("save") @JSON public RestResponse savePerson(@BodyParam Map<String, Object> person) { return RestResponse.ok(person); }
@PostRoute("template_content") @JSON public String templateContent(@BodyParam TemplateParam template) throws IOException { List<String> lines = Files.readAllLines(Paths.get(Utils.CLASSPATH + "templates/themes/" + template.getTheme() + "/" + template.getFileName())); return String.join("\n", lines); }
@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("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("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(); }
@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("install") @JSON public RestResponse doInstall(@BodyParam InstallParam installParam) throws IOException { if (Utils.isInstall()) { return RestResponse.fail("请勿重复安装!"); } log.info("安装参数: {}", installParam); Validator.installParam(installParam); delete().from(Option.class).execute(); optionService.updatePayConfig(installParam); optionService.save(Constant.TODAY_COUNT, "0"); optionService.save(Constant.TOTAL_COUNT, "0"); optionService.save(Constant.TODAY_AMOUNT, "0"); optionService.save(Constant.TOTAL_AMOUNT, "0"); optionService.save(Constant.PAGE_SIZE, "10"); optionService.save(Constant.COMMENT_MIN_SIZE, "4"); optionService.save(Constant.COMMENT_MAX_SIZE, "500"); optionService.save(Constant.AMOUNT_MIN, "0.1"); optionService.save(Constant.AMOUNT_MAX, "1000"); Bootstrap.refreshConfig(); Bootstrap.payApi = PayApi.getPayApi(installParam.getPlatform()); File lock = new File(Utils.CLASSPATH + "install.lock"); lock.createNewFile(); return RestResponse.ok(); }