Skip to content

Commit 3f1eadc

Browse files
author
pedro
authored
Merge pull request #7 from TaleLin/dev
Dev
2 parents d3b3e41 + d3bacb1 commit 3f1eadc

13 files changed

Lines changed: 182 additions & 201 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<a href="http://doc.cms.7yue.pro/">
33
<img src="http://doc.cms.7yue.pro/left-logo.png" width="250"/></a>
44
<br>
5-
Lin-CMS-Koa (测试版)
5+
Lin-CMS-Koa
66
</h1>
77

88
<h4 align="center">一个简单易用的CMS后端项目 | <a href="http://doc.cms.7yue.pro/" target="_blank">Lin-CMS-Koa</a></h4>
99

1010
<p align="center">
1111
<a href="http://flask.pocoo.org/docs/1.0/" rel="nofollow">
1212
<img src="https://img.shields.io/badge/koa-2.7.0-green.svg" alt="flask version" data-canonical-src="https://img.shields.io/badge/koa-2.7.0-green.svg" style="max-width:100%;"></a>
13-
<a href="https://pypi.org/project/Lin-CMS/" rel="nofollow"><img src="https://img.shields.io/badge/lin--cms--test-0.0.1--alpha8-red.svg" alt="lin-cms version" data-canonical-src="https://img.shields.io/badge/lin--cms--test-0.0.1--alpha8-red.svg" style="max-width:100%;"></a>
13+
<a href="https://pypi.org/project/Lin-CMS/" rel="nofollow"><img src="https://img.shields.io/badge/lin--mizar-0.1.1-green.svg" alt="lin-cms version" data-canonical-src="https://img.shields.io/badge/lin--cms--test-0.0.1--alpha8-red.svg" style="max-width:100%;"></a>
1414
<a href="http://doc.cms.7yue.pro/" rel="nofollow"><img src="https://img.shields.io/badge/license-MIT-lightgrey.svg" alt="LISENCE" data-canonical-src="https://img.shields.io/badge/license-MIT-lightgrey.svg" style="max-width:100%;"></a>
1515
</p>
1616

app/api/cms/admin.js

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {
44
LinRouter,
55
routeMetaInfo,
66
adminRequired,
7-
Success,
87
NotFound,
98
Failed
109
} = require("lin-mizar");
@@ -95,11 +94,9 @@ admin.linPut(
9594
async ctx => {
9695
const v = await new ResetPasswordValidator().validate(ctx);
9796
await adminDao.changeUserPassword(ctx, v);
98-
ctx.json(
99-
new Success({
100-
msg: "密码修改成功"
101-
})
102-
);
97+
ctx.success({
98+
msg: "密码修改成功"
99+
});
103100
}
104101
);
105102

@@ -116,11 +113,9 @@ admin.linDelete(
116113
const v = await new PositiveIdValidator().validate(ctx);
117114
const id = v.get("path.id");
118115
await adminDao.deleteUser(ctx, id);
119-
ctx.json(
120-
new Success({
121-
msg: "操作成功"
122-
})
123-
);
116+
ctx.success({
117+
msg: "操作成功"
118+
});
124119
}
125120
);
126121

@@ -136,11 +131,9 @@ admin.linPut(
136131
async ctx => {
137132
const v = await new UpdateUserInfoValidator().validate(ctx);
138133
await adminDao.updateUserInfo(ctx, v);
139-
ctx.json(
140-
new Success({
141-
msg: "操作成功"
142-
})
143-
);
134+
ctx.success({
135+
msg: "操作成功"
136+
});
144137
}
145138
);
146139

@@ -221,18 +214,13 @@ admin.linPost(
221214
const v = await new NewGroupValidator().validate(ctx);
222215
const ok = await adminDao.createGroup(ctx, v);
223216
if (!ok) {
224-
ctx.json(
225-
new Failed({
226-
msg: "新建分组失败"
227-
})
228-
);
229-
} else {
230-
ctx.json(
231-
new Success({
232-
msg: "新建分组成功"
233-
})
234-
);
217+
throw new Failed({
218+
msg: "新建分组失败"
219+
});
235220
}
221+
ctx.success({
222+
msg: "新建分组成功"
223+
});
236224
}
237225
);
238226

@@ -248,11 +236,9 @@ admin.linPut(
248236
async ctx => {
249237
const v = await new UpdateGroupValidator().validate(ctx);
250238
await adminDao.updateGroup(ctx, v);
251-
ctx.json(
252-
new Success({
253-
msg: "更新分组成功"
254-
})
255-
);
239+
ctx.success({
240+
msg: "更新分组成功"
241+
});
256242
}
257243
);
258244

@@ -269,11 +255,9 @@ admin.linDelete(
269255
const v = await new PositiveIdValidator().validate(ctx);
270256
const id = v.get("path.id");
271257
await adminDao.deleteGroup(ctx, id);
272-
ctx.json(
273-
new Success({
274-
msg: "删除分组成功"
275-
})
276-
);
258+
ctx.success({
259+
msg: "删除分组成功"
260+
});
277261
}
278262
);
279263

@@ -289,11 +273,9 @@ admin.linPost(
289273
async ctx => {
290274
const v = await new DispatchAuthValidator().validate(ctx);
291275
await adminDao.dispatchAuth(ctx, v);
292-
ctx.json(
293-
new Success({
294-
msg: "添加权限成功"
295-
})
296-
);
276+
ctx.success({
277+
msg: "添加权限成功"
278+
});
297279
}
298280
);
299281

@@ -309,11 +291,9 @@ admin.linPost(
309291
async ctx => {
310292
const v = await new DispatchAuthsValidator().validate(ctx);
311293
await adminDao.dispatchAuths(ctx, v);
312-
ctx.json(
313-
new Success({
314-
msg: "添加权限成功"
315-
})
316-
);
294+
ctx.success({
295+
msg: "添加权限成功"
296+
});
317297
}
318298
);
319299

@@ -329,11 +309,9 @@ admin.linPost(
329309
async ctx => {
330310
const v = await new RemoveAuthsValidator().validate(ctx);
331311
await adminDao.removeAuths(ctx, v);
332-
ctx.json(
333-
new Success({
334-
msg: "删除权限成功"
335-
})
336-
);
312+
ctx.success({
313+
msg: "删除权限成功"
314+
});
337315
}
338316
);
339317

app/api/cms/log.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const { LinRouter, groupRequired, NotFound } = require("lin-mizar");
44
const { LogFindValidator } = require("../../validators/log");
55
const { PaginateValidator } = require("../../validators/common");
6-
const { get } = require("lodash");
76
const { LogDao } = require("../../dao/log");
87

98
const log = new LinRouter({
@@ -47,7 +46,7 @@ log.linGet(
4746
groupRequired,
4847
async ctx => {
4948
const v = await new LogFindValidator().validate(ctx);
50-
const keyword = get(ctx.request.query, "keyword", "");
49+
const keyword = v.get("query.keyword", false, "");
5150
const { rows, total } = await logDao.searchLogs(v, keyword);
5251
if (total < 1) {
5352
throw new NotFound({

app/api/cms/user.js

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ const {
66
getTokens,
77
loginRequired,
88
adminRequired,
9-
Success,
109
refreshTokenRequiredWithUnifyException,
1110
Failed,
12-
logger,
13-
checkUserIsActive
11+
logger
1412
} = require("lin-mizar");
1513

1614
const {
@@ -41,11 +39,9 @@ user.linPost(
4139
async ctx => {
4240
const v = await new RegisterValidator().validate(ctx);
4341
await userDao.createUser(ctx, v);
44-
ctx.json(
45-
new Success({
46-
msg: "用户创建成功"
47-
})
48-
);
42+
ctx.success({
43+
msg: "用户创建成功"
44+
});
4945
}
5046
);
5147

@@ -58,7 +54,6 @@ user.linPost(
5854
mount: false
5955
},
6056
async ctx => {
61-
checkUserIsActive(ctx.currentUser);
6257
const v = await new LoginValidator().validate(ctx);
6358
let user = await ctx.manager.userModel.verify(
6459
v.get("body.nickname"),
@@ -84,11 +79,9 @@ user.linPut(
8479
async ctx => {
8580
const v = await new UpdateInfoValidator().validate(ctx);
8681
await userDao.updateUser(ctx, v);
87-
ctx.json(
88-
new Success({
89-
msg: "操作成功"
90-
})
91-
);
82+
ctx.success({
83+
msg: "操作成功"
84+
});
9285
}
9386
);
9487

@@ -108,20 +101,15 @@ user.linPut(
108101
v.get("body.old_password"),
109102
v.get("body.new_password")
110103
);
111-
if (ok) {
112-
user.save();
113-
ctx.json(
114-
new Success({
115-
msg: "密码修改成功"
116-
})
117-
);
118-
} else {
119-
ctx.json(
120-
new Failed({
121-
msg: "修改密码失败"
122-
})
123-
);
104+
if (!ok) {
105+
throw new Failed({
106+
msg: "修改密码失败,你可能输入了错误的旧密码"
107+
});
124108
}
109+
user.save();
110+
ctx.success({
111+
msg: "密码修改成功"
112+
});
125113
}
126114
);
127115

app/api/v1/book.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const {
44
LinRouter,
55
NotFound,
6-
Success,
76
groupRequired,
87
disableLoading
98
} = require("lin-mizar");
@@ -61,22 +60,18 @@ bookApi.get("/search/one", async ctx => {
6160
bookApi.post("/", async ctx => {
6261
const v = await new CreateOrUpdateBookValidator().validate(ctx);
6362
await bookDto.createBook(v);
64-
ctx.json(
65-
new Success({
66-
msg: "新建图书成功"
67-
})
68-
);
63+
ctx.success({
64+
msg: "新建图书成功"
65+
});
6966
});
7067

7168
bookApi.put("/:id", async ctx => {
7269
const v = await new CreateOrUpdateBookValidator().validate(ctx);
7370
const id = getSafeParamId(ctx);
7471
await bookDto.updateBook(v, id);
75-
ctx.json(
76-
new Success({
77-
msg: "更新图书成功"
78-
})
79-
);
72+
ctx.success({
73+
msg: "更新图书成功"
74+
});
8075
});
8176

8277
bookApi.linDelete(
@@ -92,11 +87,9 @@ bookApi.linDelete(
9287
const v = await new PositiveIdValidator().validate(ctx);
9388
const id = v.get("path.id");
9489
await bookDto.deleteBook(id);
95-
ctx.json(
96-
new Success({
97-
msg: "删除图书成功"
98-
})
99-
);
90+
ctx.success({
91+
msg: "删除图书成功"
92+
});
10093
}
10194
);
10295

app/libs/util.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,18 @@ function getSafeParamId (ctx) {
1313
return id;
1414
}
1515

16-
module.exports = { getSafeParamId };
16+
function isOptional (val) {
17+
// undefined , null , "" , " ", 皆通过
18+
if (val === void 0) {
19+
return true;
20+
}
21+
if (val === null) {
22+
return true;
23+
}
24+
if (typeof val === "string") {
25+
return val === "" || val.trim() === "";
26+
}
27+
return false;
28+
}
29+
30+
module.exports = { getSafeParamId, isOptional };

app/plugins/notify/app/message.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
"use strict";
22

3-
const {
4-
LinRouter,
5-
loginRequired,
6-
NotFound,
7-
paginate,
8-
Success
9-
} = require("lin-mizar");
3+
const { LinRouter, loginRequired, NotFound, paginate } = require("lin-mizar");
104
const { getSafeParamId } = require("../../../libs/util");
115
const { IdsValidator } = require("./validators");
126
const { MessageDao } = require("./message-dao");
@@ -53,11 +47,9 @@ messageApi.linPut(
5347
async ctx => {
5448
const id = getSafeParamId(ctx);
5549
await messageDao.readMessage(id);
56-
ctx.json(
57-
new Success({
58-
msg: "操作成功"
59-
})
60-
);
50+
ctx.success({
51+
msg: "操作成功"
52+
});
6153
}
6254
);
6355

@@ -73,11 +65,9 @@ messageApi.linPut(
7365
async ctx => {
7466
const v = await new IdsValidator().validate(ctx);
7567
await messageDao.readMessages(v);
76-
ctx.json(
77-
new Success({
78-
msg: "操作成功"
79-
})
80-
);
68+
ctx.success({
69+
msg: "操作成功"
70+
});
8171
}
8272
);
8373

@@ -93,11 +83,9 @@ messageApi.linDelete(
9383
async ctx => {
9484
const id = getSafeParamId(ctx);
9585
await messageDao.deleteMessage(id);
96-
ctx.json(
97-
new Success({
98-
msg: "操作成功"
99-
})
100-
);
86+
ctx.success({
87+
msg: "操作成功"
88+
});
10189
}
10290
);
10391

0 commit comments

Comments
 (0)