Skip to content

Commit 70e4e6b

Browse files
authored
Merge pull request #40 from TaleLin/dev
Dev
2 parents a839e3c + 491062a commit 70e4e6b

File tree

17 files changed

+78
-77
lines changed

17 files changed

+78
-77
lines changed

app/api/cms/admin.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ admin.linGet(
7575
v.get('query.count')
7676
);
7777
ctx.json({
78-
collection: users,
78+
items: users,
7979
// 超级管理员不算入总数
80-
total_nums: total
80+
total: total,
81+
page: v.get('query.page'),
82+
count: v.get('query.count'),
83+
total_page: Math.ceil(total / parseInt(v.get('query.count')))
8184
});
8285
}
8386
);
@@ -159,8 +162,11 @@ admin.linGet(
159162
});
160163
}
161164
ctx.json({
162-
collection: groups,
163-
total_nums: total
165+
items: groups,
166+
total: total,
167+
page: v.get('query.page'),
168+
count: v.get('query.count'),
169+
total_page: Math.ceil(total / parseInt(v.get('query.count')))
164170
});
165171
}
166172
);

app/api/cms/file.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
'use strict';
22

3-
const { LinRouter, ParametersException } = require('lin-mizar');
4-
// const { ratelimit } = require('lin-mizar/lin/limiter');
3+
const { LinRouter, ParametersException, loginRequired } = require('lin-mizar');
54
const { LocalUploader } = require('../../extensions/file/local-uploader');
6-
// const redis = require('redis');
7-
8-
// const client = redis.createClient();
95

106
const file = new LinRouter({
117
prefix: '/cms/file'
128
});
139

14-
file.post('/', async ctx => {
10+
file.linPost('upload', '/', {}, loginRequired, async ctx => {
1511
const files = await ctx.multipart();
1612
if (files.length < 1) {
1713
throw new ParametersException({ msg: '未找到符合条件的文件资源' });
@@ -21,20 +17,4 @@ file.post('/', async ctx => {
2117
ctx.json(arr);
2218
});
2319

24-
// file.get(
25-
// '/',
26-
// ratelimit({
27-
// db: client,
28-
// duration: 30 * 1000,
29-
// max: 5,
30-
// // throw: true,
31-
// logging: true
32-
// }),
33-
// async ctx => {
34-
// ctx.body = {
35-
// msg: 'just a normal response.'
36-
// };
37-
// }
38-
// );
39-
4020
module.exports = { file };

app/api/cms/log.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ log.linGet(
2929
});
3030
}
3131
ctx.json({
32-
total_nums: total,
33-
collection: rows
32+
total: total,
33+
items: rows,
34+
page: v.get('query.page'),
35+
count: v.get('query.count'),
36+
total_page: Math.ceil(total / parseInt(v.get('query.count')))
3437
});
3538
}
3639
);
@@ -54,8 +57,11 @@ log.linGet(
5457
});
5558
}
5659
ctx.json({
57-
total_nums: total,
58-
collection: rows
60+
total: total,
61+
items: rows,
62+
page: v.get('query.page'),
63+
count: v.get('query.count'),
64+
total_page: Math.ceil(total / parseInt(v.get('query.count')))
5965
});
6066
}
6167
);

app/api/cms/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test.linGet(
2929
mount: true
3030
},
3131
loginRequired,
32-
logger('{user.nickname}就是皮了一波'),
32+
logger('{user.username}就是皮了一波'),
3333
async ctx => {
3434
ctx.json({
3535
msg: '物质决定意识,经济基础决定上层建筑'

app/api/cms/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ user.linPost(
5757
async ctx => {
5858
const v = await new LoginValidator().validate(ctx);
5959
let user = await ctx.manager.userModel.verify(
60-
v.get('body.nickname'),
60+
v.get('body.username'),
6161
v.get('body.password')
6262
);
6363
const { accessToken, refreshToken } = getTokens(user);

app/api/v1/book.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ bookApi.get('/:id', async ctx => {
3939

4040
bookApi.get('/', async ctx => {
4141
const books = await bookDto.getBooks();
42-
if (!books || books.length < 1) {
43-
throw new NotFound({
44-
msg: '没有找到相关书籍'
45-
});
46-
}
42+
// if (!books || books.length < 1) {
43+
// throw new NotFound({
44+
// msg: '没有找到相关书籍'
45+
// });
46+
// }
4747
ctx.json(books);
4848
});
4949

app/config/secure.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
dialect: 'mysql',
88
port: 3306,
99
username: 'root',
10-
password: '123456',
10+
password: 'root',
1111
logging: false,
1212
timezone: '+08:00'
1313
},

app/config/setting.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
'use strict';
22

3-
let siteDomain;
4-
switch (process.env.NODE_ENV) {
5-
case 'development':
6-
siteDomain = 'http://localhost:5000/';
7-
break;
8-
case 'production':
9-
siteDomain = '';
10-
break;
11-
}
123
module.exports = {
134
port: 5000,
14-
siteDomain,
5+
siteDomain: 'http://localhost:5000',
156
countDefault: 10,
167
pageDefault: 0,
178
apiDir: 'app/api',

app/dao/user.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class UserDao {
88
async createUser (ctx, v) {
99
let user = await ctx.manager.userModel.findOne({
1010
where: {
11-
nickname: v.get('body.nickname')
11+
username: v.get('body.username')
1212
}
1313
});
1414
if (user) {
@@ -33,7 +33,7 @@ class UserDao {
3333

3434
async updateUser (ctx, v) {
3535
let user = ctx.currentUser;
36-
if (user.email !== v.get('body.email')) {
36+
if (v.get('body.email') && user.email !== v.get('body.email')) {
3737
const exit = await ctx.manager.userModel.findOne({
3838
where: {
3939
email: v.get('body.email')
@@ -44,8 +44,11 @@ class UserDao {
4444
msg: '邮箱已被注册,请重新输入邮箱'
4545
});
4646
}
47+
user.email = v.get('body.email');
48+
}
49+
if (v.get('body.nickname')) {
50+
user.nickname = v.get('body.nickname')
4751
}
48-
user.email = v.get('body.email');
4952
user.save();
5053
}
5154

@@ -56,8 +59,16 @@ class UserDao {
5659
group_id: user.group_id
5760
}
5861
});
62+
let group = await ctx.manager.groupModel.findOne({
63+
where: {
64+
id: user.group_id
65+
}
66+
})
5967
const aus = this.splitAuths(auths);
6068
set(user, 'auths', aus);
69+
if (group) {
70+
set(user, 'groupName', group.name);
71+
}
6172
return user;
6273
}
6374

@@ -88,7 +99,7 @@ class UserDao {
8899

89100
registerUser (ctx, v) {
90101
const user = new ctx.manager.userModel();
91-
user.nickname = v.get('body.nickname');
102+
user.username = v.get('body.username');
92103
user.password = v.get('body.password');
93104
user.group_id = v.get('body.group_id');
94105
if (v.get('body.email') && v.get('body.email').trim() !== '') {

app/plugins/notify/app/middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function pushMessage (template, event, ctx, extra) {
4242
msg.time = now;
4343
msg.pushed = MessageIsPushed.PUSHED;
4444
msg.user_id = ctx.currentUser.id;
45-
msg.user_name = ctx.currentUser.nickname;
45+
msg.user_name = ctx.currentUser.username;
4646
msg.save();
4747
}
4848

0 commit comments

Comments
 (0)