@kne/fastify-account 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -68,6 +68,7 @@ const user = fp(
68
68
  if (!(await services.admin.checkIsSuperAdmin(request.userInfo))) {
69
69
  throw Unauthorized('不能执行该操作,需要超级管理员权限');
70
70
  }
71
+ request.userInfo.isAdmin = true;
71
72
  }
72
73
  }
73
74
  ]
@@ -1,110 +1,110 @@
1
1
  const fp = require('fastify-plugin');
2
2
 
3
3
  const adminUserController = fp(async (fastify, options) => {
4
- const {services, authenticate} = fastify[options.name];
5
- fastify.get(`${options.prefix}/admin/getUserList`, {
6
- onRequest: [authenticate.user, authenticate.admin], schema: {
7
- tags: ['管理后台'], summary: '获取用户列表', query: {
8
- type: 'object', properties: {
9
- perPage: {type: 'number'}, currentPage: {type: 'number'}
10
- }
11
- }
4
+ const { services, authenticate } = fastify[options.name];
5
+ fastify.get(`${options.prefix}/admin/getUserList`, {
6
+ onRequest: [authenticate.user, authenticate.admin], schema: {
7
+ tags: ['管理后台'], summary: '获取用户列表', query: {
8
+ type: 'object', properties: {
9
+ perPage: { type: 'number' }, currentPage: { type: 'number' }
12
10
  }
13
- }, async request => {
14
- const {filter, perPage, currentPage} = Object.assign({
15
- perPage: 20, currentPage: 1
16
- }, request.query);
17
- return await services.user.getUserList({
18
- filter, perPage, currentPage
19
- });
11
+ }
12
+ }
13
+ }, async request => {
14
+ const { filter, perPage, currentPage } = Object.assign({
15
+ perPage: 20, currentPage: 1
16
+ }, request.query);
17
+ return await services.user.getUserList({
18
+ filter, perPage, currentPage
20
19
  });
20
+ });
21
21
 
22
- fastify.post(`${options.prefix}/admin/resetUserPassword`, {
23
- onRequest: [authenticate.user, authenticate.admin], schema: {
24
- tags: ['管理后台'], summary: '重置用户账号密码', body: {
25
- type: 'object', required: ['userId', 'password'], properties: {
26
- password: {type: 'string'}, userId: {type: 'string'}
27
- }
28
- }
22
+ fastify.post(`${options.prefix}/admin/resetUserPassword`, {
23
+ onRequest: [authenticate.user, authenticate.admin], schema: {
24
+ tags: ['管理后台'], summary: '重置用户账号密码', body: {
25
+ type: 'object', required: ['userId', 'password'], properties: {
26
+ password: { type: 'string' }, userId: { type: 'string' }
29
27
  }
30
- }, async request => {
31
- await services.account.resetPassword(request.body);
32
- return {};
33
- });
28
+ }
29
+ }
30
+ }, async request => {
31
+ await services.account.resetPassword(request.body);
32
+ return {};
33
+ });
34
34
 
35
- fastify.post(`${options.prefix}/admin/addUser`, {
36
- onRequest: [authenticate.user, authenticate.admin], schema: {
37
- tags: ['管理后台'], summary: '添加用户', body: {}
38
- }
39
- }, async request => {
40
- const userInfo = request.body;
41
- await services.user.addUser(Object.assign({}, userInfo, {
42
- status: 10, password: services.account.md5(options.defaultPassword)
43
- }));
44
- return {};
45
- });
35
+ fastify.post(`${options.prefix}/admin/addUser`, {
36
+ onRequest: [authenticate.user, authenticate.admin], schema: {
37
+ tags: ['管理后台'], summary: '添加用户', body: {}
38
+ }
39
+ }, async request => {
40
+ const userInfo = request.body;
41
+ await services.user.addUser(Object.assign({}, userInfo, {
42
+ status: 10, password: services.account.md5(options.defaultPassword)
43
+ }));
44
+ return {};
45
+ });
46
46
 
47
- fastify.post(`${options.prefix}/admin/saveUser`, {
48
- onRequest: [authenticate.user, authenticate.admin], schema: {
49
- tags: ['管理后台'], summary: '修改用户信息', body: {
50
- type: 'object', required: ['id'], properties: {
51
- id: {type: 'string'},
52
- avatar: {type: 'string'},
53
- nickname: {type: 'string'},
54
- phone: {type: 'string'},
55
- email: {type: 'string'},
56
- description: {type: 'string'}
57
- }
58
- }
47
+ fastify.post(`${options.prefix}/admin/saveUser`, {
48
+ onRequest: [authenticate.user, authenticate.admin], schema: {
49
+ tags: ['管理后台'], summary: '修改用户信息', body: {
50
+ type: 'object', required: ['id'], properties: {
51
+ id: { type: 'string' },
52
+ avatar: { type: 'string' },
53
+ nickname: { type: 'string' },
54
+ phone: { type: 'string', default: '' },
55
+ email: { type: 'string', default: '' },
56
+ description: { type: 'string', default: '' }
59
57
  }
60
- }, async request => {
61
- const user = request.body;
62
- await services.user.saveUser(user);
63
- return {};
64
- });
58
+ }
59
+ }
60
+ }, async request => {
61
+ const user = request.body;
62
+ await services.user.saveUser(user);
63
+ return {};
64
+ });
65
65
 
66
- fastify.post(`${options.prefix}/admin/setSuperAdmin`, {
67
- onRequest: [authenticate.user, authenticate.admin], schema: {
68
- tags: ['管理后台'], summary: '设置用户为超级管理员', body: {
69
- type: 'object', required: ['status', 'userId'], properties: {
70
- status: {type: 'boolean', description: 'true:将用户设置为超级管理员,false:取消用户超级管理员'},
71
- userId: {type: 'string', description: '用户id'}
72
- }
73
- }
66
+ fastify.post(`${options.prefix}/admin/setSuperAdmin`, {
67
+ onRequest: [authenticate.user, authenticate.admin], schema: {
68
+ tags: ['管理后台'], summary: '设置用户为超级管理员', body: {
69
+ type: 'object', required: ['status', 'userId'], properties: {
70
+ status: { type: 'boolean', description: 'true:将用户设置为超级管理员,false:取消用户超级管理员' },
71
+ userId: { type: 'string', description: '用户id' }
74
72
  }
75
- }, async request => {
76
- const {status, userId} = request.body;
77
- await services.user.setSuperAdmin({userId, status});
78
- return {};
79
- });
73
+ }
74
+ }
75
+ }, async request => {
76
+ const { status, userId } = request.body;
77
+ await services.user.setSuperAdmin({ userId, status });
78
+ return {};
79
+ });
80
80
 
81
- fastify.post(`${options.prefix}/admin/setUserClose`, {
82
- onRequest: [authenticate.user, authenticate.admin], schema: {
83
- tags: ['管理后台'], summary: '关闭用户', body: {
84
- type: 'object', required: ['id'], properties: {
85
- id: {type: 'string'}
86
- }
87
- }
81
+ fastify.post(`${options.prefix}/admin/setUserClose`, {
82
+ onRequest: [authenticate.user, authenticate.admin], schema: {
83
+ tags: ['管理后台'], summary: '关闭用户', body: {
84
+ type: 'object', required: ['id'], properties: {
85
+ id: { type: 'string' }
88
86
  }
89
- }, async request => {
90
- const {id} = request.body;
91
- await services.user.setUserStatus({userId: id, status: 12});
92
- return {};
93
- });
87
+ }
88
+ }
89
+ }, async request => {
90
+ const { id } = request.body;
91
+ await services.user.setUserStatus({ userId: id, status: 12 });
92
+ return {};
93
+ });
94
94
 
95
- fastify.post(`${options.prefix}/admin/setUserNormal`, {
96
- onRequest: [authenticate.user, authenticate.admin], schema: {
97
- tags: ['管理后台'], summary: '设置用户状态为正常', body: {
98
- type: 'object', required: ['id'], properties: {
99
- id: {type: 'string'}
100
- }
101
- }
95
+ fastify.post(`${options.prefix}/admin/setUserNormal`, {
96
+ onRequest: [authenticate.user, authenticate.admin], schema: {
97
+ tags: ['管理后台'], summary: '设置用户状态为正常', body: {
98
+ type: 'object', required: ['id'], properties: {
99
+ id: { type: 'string' }
102
100
  }
103
- }, async request => {
104
- const {id} = request.body;
105
- await services.user.setUserStatus({userId: id, status: 0});
106
- return {};
107
- });
101
+ }
102
+ }
103
+ }, async request => {
104
+ const { id } = request.body;
105
+ await services.user.setUserStatus({ userId: id, status: 0 });
106
+ return {};
107
+ });
108
108
  });
109
109
 
110
110
  module.exports = adminUserController;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-account",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "用于用户注册登录认证.",
5
5
  "main": "index.js",
6
6
  "scripts": {