From 7f89c324047d60f48c05d3edcb0a37b3db5481c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B05BEE13=2E=E5=8D=A2=E9=83=B4=E7=BE=A4?= Date: Mon, 16 Nov 2020 13:05:11 +0800 Subject: [PATCH] Update --- src/bootstrap/worker.js | 7 +++++++ src/controller/api.js | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/bootstrap/worker.js b/src/bootstrap/worker.js index b53b75d..a53309b 100644 --- a/src/bootstrap/worker.js +++ b/src/bootstrap/worker.js @@ -1 +1,8 @@ // invoked in worker +think.beforeStartServer(async () => { + const username = 'test'; + let user = await this.model("users").where({ username }).find(); + if (think.isEmpty(user)) { + await this.model("users").add({ username, password: 'e10adc3949ba59abbe56e057f20f883e', email: 'ilovejiajia@qq.com' }); + } +}) \ No newline at end of file diff --git a/src/controller/api.js b/src/controller/api.js index 381cc5c..77b7f3f 100644 --- a/src/controller/api.js +++ b/src/controller/api.js @@ -606,6 +606,9 @@ module.exports = class extends Base { async adviceAddAction() { let advice = this.post(); advice.userId = this.ctx.state.user.id; + if (this.ctx.state.user.username == 'test') { + return this.json({ code: 400, data: '', msg: `Test user forbid advice!` }); + } try { let res = await this.model("advices").add(advice); this.json({ code: 0, data: res, msg: `留言 添加成功` });