This commit is contained in:
B05BEE13.卢郴群 2020-11-16 13:05:11 +08:00
parent 101022258d
commit 7f89c32404
2 changed files with 10 additions and 0 deletions

View File

@ -1 +1,8 @@
// invoked in worker // 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' });
}
})

View File

@ -606,6 +606,9 @@ module.exports = class extends Base {
async adviceAddAction() { async adviceAddAction() {
let advice = this.post(); let advice = this.post();
advice.userId = this.ctx.state.user.id; 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 { try {
let res = await this.model("advices").add(advice); let res = await this.model("advices").add(advice);
this.json({ code: 0, data: res, msg: `留言 添加成功` }); this.json({ code: 0, data: res, msg: `留言 添加成功` });