@kne/fastify-account 1.0.0-alpha.12 → 1.0.0-alpha.14
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/README.md +1136 -898
- package/libs/controllers/account.js +95 -22
- package/libs/controllers/admin.js +46 -6
- package/libs/controllers/adminPermission.js +2 -0
- package/libs/controllers/adminRole.js +2 -0
- package/libs/services/tenant-invite.js +1 -1
- package/libs/services/tenant-role.js +1 -1
- package/libs/services/tenant-user.js +1 -1
- package/libs/services/tenant.js +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,8 @@ module.exports = fp(async (fastify, options) => {
|
|
|
5
5
|
`${options.prefix}/sendEmailCode`,
|
|
6
6
|
{
|
|
7
7
|
schema: {
|
|
8
|
+
tags: ['账号'],
|
|
9
|
+
summary: '发送邮箱验证码',
|
|
8
10
|
body: {
|
|
9
11
|
type: 'object',
|
|
10
12
|
required: ['email'],
|
|
@@ -39,12 +41,28 @@ module.exports = fp(async (fastify, options) => {
|
|
|
39
41
|
`${options.prefix}/sendSMSCode`,
|
|
40
42
|
{
|
|
41
43
|
schema: {
|
|
44
|
+
tags: ['账号'],
|
|
45
|
+
summary: '发送短信验证码',
|
|
42
46
|
body: {
|
|
43
47
|
type: 'object',
|
|
44
48
|
required: ['phone'],
|
|
45
49
|
properties: {
|
|
46
50
|
phone: { type: 'string', description: '电话' }
|
|
47
51
|
}
|
|
52
|
+
},
|
|
53
|
+
response: {
|
|
54
|
+
200: {
|
|
55
|
+
content: {
|
|
56
|
+
'application/json': {
|
|
57
|
+
schema: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
code: { type: 'string', description: '验证码' }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
48
66
|
}
|
|
49
67
|
}
|
|
50
68
|
},
|
|
@@ -59,6 +77,8 @@ module.exports = fp(async (fastify, options) => {
|
|
|
59
77
|
`${options.prefix}/validateCode`,
|
|
60
78
|
{
|
|
61
79
|
schema: {
|
|
80
|
+
tags: ['账号'],
|
|
81
|
+
summary: '验证码验证',
|
|
62
82
|
body: {
|
|
63
83
|
type: 'object',
|
|
64
84
|
required: ['name', 'type', 'code'],
|
|
@@ -67,6 +87,15 @@ module.exports = fp(async (fastify, options) => {
|
|
|
67
87
|
type: { type: 'number', description: '0:手机注册,1:邮箱注册,2:手机登录,3:邮箱登录,4:验证租户管理员' },
|
|
68
88
|
code: { type: 'string', description: '接受到的验证码' }
|
|
69
89
|
}
|
|
90
|
+
},
|
|
91
|
+
response: {
|
|
92
|
+
200: {
|
|
93
|
+
content: {
|
|
94
|
+
'application/json': {
|
|
95
|
+
schema: {}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
70
99
|
}
|
|
71
100
|
}
|
|
72
101
|
},
|
|
@@ -88,23 +117,39 @@ module.exports = fp(async (fastify, options) => {
|
|
|
88
117
|
`${options.prefix}/accountIsExists`,
|
|
89
118
|
{
|
|
90
119
|
schema: {
|
|
120
|
+
tags: ['账号'],
|
|
121
|
+
summary: '账号是否已存在',
|
|
91
122
|
body: {
|
|
92
123
|
oneOf: [
|
|
93
124
|
{
|
|
94
125
|
type: 'object',
|
|
95
126
|
required: ['phone'],
|
|
96
127
|
properties: {
|
|
97
|
-
phone: { type: 'string' }
|
|
128
|
+
phone: { type: 'string', description: '电话' }
|
|
98
129
|
}
|
|
99
130
|
},
|
|
100
131
|
{
|
|
101
132
|
type: 'object',
|
|
102
133
|
required: ['email'],
|
|
103
134
|
properties: {
|
|
104
|
-
email: { type: 'string' }
|
|
135
|
+
email: { type: 'string', description: '邮箱' }
|
|
105
136
|
}
|
|
106
137
|
}
|
|
107
138
|
]
|
|
139
|
+
},
|
|
140
|
+
response: {
|
|
141
|
+
200: {
|
|
142
|
+
content: {
|
|
143
|
+
'application/json': {
|
|
144
|
+
schema: {
|
|
145
|
+
type: 'object',
|
|
146
|
+
properties: {
|
|
147
|
+
isExists: { type: 'boolean', description: 'true已存在,false不存在' }
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
108
153
|
}
|
|
109
154
|
}
|
|
110
155
|
},
|
|
@@ -118,39 +163,50 @@ module.exports = fp(async (fastify, options) => {
|
|
|
118
163
|
`${options.prefix}/register`,
|
|
119
164
|
{
|
|
120
165
|
schema: {
|
|
166
|
+
tags: ['账号'],
|
|
167
|
+
summary: '注册账号',
|
|
121
168
|
body: {
|
|
122
169
|
oneOf: [
|
|
123
170
|
{
|
|
124
171
|
type: 'object',
|
|
125
172
|
required: ['phone', 'password', 'code'],
|
|
126
173
|
properties: {
|
|
127
|
-
avatar: { type: 'string' },
|
|
128
|
-
phone: { type: 'string' },
|
|
129
|
-
code: { type: 'string' },
|
|
130
|
-
password: { type: 'string' },
|
|
131
|
-
invitationCode: { type: 'string' },
|
|
132
|
-
nickname: { type: 'string' },
|
|
133
|
-
gender: { type: 'string' },
|
|
134
|
-
birthday: { type: 'string', format: 'date' },
|
|
135
|
-
description: { type: 'string' }
|
|
174
|
+
avatar: { type: 'string', description: '头像图片id' },
|
|
175
|
+
phone: { type: 'string', description: '电话' },
|
|
176
|
+
code: { type: 'string', description: '验证码' },
|
|
177
|
+
password: { type: 'string', description: '密码(需要md5加密)' },
|
|
178
|
+
invitationCode: { type: 'string', description: '邀请码,用来默认加入租户' },
|
|
179
|
+
nickname: { type: 'string', description: '昵称' },
|
|
180
|
+
gender: { type: 'string', description: '性别' },
|
|
181
|
+
birthday: { type: 'string', format: 'date', description: '出生日期' },
|
|
182
|
+
description: { type: 'string', description: '个人简介' }
|
|
136
183
|
}
|
|
137
184
|
},
|
|
138
185
|
{
|
|
139
186
|
type: 'object',
|
|
140
187
|
required: ['email', 'password', 'code'],
|
|
141
188
|
properties: {
|
|
142
|
-
avatar: { type: 'string' },
|
|
143
|
-
email: { type: 'string' },
|
|
144
|
-
code: { type: 'string' },
|
|
145
|
-
password: { type: 'string' },
|
|
146
|
-
invitationCode: { type: 'string' },
|
|
147
|
-
nickname: { type: 'string' },
|
|
148
|
-
gender: { type: 'string' },
|
|
149
|
-
birthday: { type: 'string', format: 'date' },
|
|
150
|
-
description: { type: 'string' }
|
|
189
|
+
avatar: { type: 'string', description: '头像图片id' },
|
|
190
|
+
email: { type: 'string', description: '邮箱' },
|
|
191
|
+
code: { type: 'string', description: '验证码' },
|
|
192
|
+
password: { type: 'string', description: '密码(需要md5加密)' },
|
|
193
|
+
invitationCode: { type: 'string', description: '邀请码,用来默认加入租户' },
|
|
194
|
+
nickname: { type: 'string', description: '昵称' },
|
|
195
|
+
gender: { type: 'string', description: '性别' },
|
|
196
|
+
birthday: { type: 'string', format: 'date', description: '出生日期' },
|
|
197
|
+
description: { type: 'string', description: '个人简介' }
|
|
151
198
|
}
|
|
152
199
|
}
|
|
153
200
|
]
|
|
201
|
+
},
|
|
202
|
+
response: {
|
|
203
|
+
200: {
|
|
204
|
+
content: {
|
|
205
|
+
'application/json': {
|
|
206
|
+
schema: {}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
154
210
|
}
|
|
155
211
|
}
|
|
156
212
|
},
|
|
@@ -164,12 +220,29 @@ module.exports = fp(async (fastify, options) => {
|
|
|
164
220
|
`${options.prefix}/login`,
|
|
165
221
|
{
|
|
166
222
|
schema: {
|
|
223
|
+
tags: ['账号'],
|
|
224
|
+
summary: '登录',
|
|
167
225
|
body: {
|
|
168
226
|
type: 'object',
|
|
169
227
|
required: ['username', 'password'],
|
|
170
228
|
properties: {
|
|
171
|
-
username: { type: 'string' },
|
|
172
|
-
password: { type: 'string' }
|
|
229
|
+
username: { type: 'string', description: '用户名' },
|
|
230
|
+
password: { type: 'string', description: '密码' }
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
response: {
|
|
234
|
+
200: {
|
|
235
|
+
content: {
|
|
236
|
+
'application/json': {
|
|
237
|
+
schema: {
|
|
238
|
+
type: 'object',
|
|
239
|
+
properties: {
|
|
240
|
+
token: { type: 'string', description: '用户token' },
|
|
241
|
+
currentTenantId: { type: 'string', description: '当前租户id' }
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
173
246
|
}
|
|
174
247
|
}
|
|
175
248
|
}
|
|
@@ -2,11 +2,15 @@ const fp = require('fastify-plugin');
|
|
|
2
2
|
|
|
3
3
|
module.exports = fp(async (fastify, options) => {
|
|
4
4
|
const { authenticate, services } = fastify.account;
|
|
5
|
-
// 用于系统初始化时,设置第一个用户,只能使用一次,其他用户由该用户创建
|
|
6
5
|
fastify.post(
|
|
7
6
|
`${options.prefix}/initSuperAdmin`,
|
|
8
7
|
{
|
|
9
|
-
onRequest: [authenticate.user]
|
|
8
|
+
onRequest: [authenticate.user],
|
|
9
|
+
schema: {
|
|
10
|
+
tags: ['管理后台'],
|
|
11
|
+
summary: '初始化用户为管理员',
|
|
12
|
+
description: '用于系统初始化时,设置第一个用户,只能使用一次,其他用户由该用户创建'
|
|
13
|
+
}
|
|
10
14
|
},
|
|
11
15
|
async request => {
|
|
12
16
|
await services.admin.initSuperAdmin(request.userInfo);
|
|
@@ -17,7 +21,38 @@ module.exports = fp(async (fastify, options) => {
|
|
|
17
21
|
fastify.get(
|
|
18
22
|
`${options.prefix}/admin/getSuperAdminInfo`,
|
|
19
23
|
{
|
|
20
|
-
onRequest: [authenticate.user, authenticate.admin]
|
|
24
|
+
onRequest: [authenticate.user, authenticate.admin],
|
|
25
|
+
schema: {
|
|
26
|
+
tags: ['管理后台'],
|
|
27
|
+
summary: '获取管理员信息',
|
|
28
|
+
response: {
|
|
29
|
+
200: {
|
|
30
|
+
content: {
|
|
31
|
+
'application/json': {
|
|
32
|
+
schema: {
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {
|
|
35
|
+
userInfo: {
|
|
36
|
+
type: 'object',
|
|
37
|
+
properties: {
|
|
38
|
+
id: { type: 'string', description: '用户id' },
|
|
39
|
+
nickname: { type: 'string', description: '用户昵称' },
|
|
40
|
+
email: { type: 'string', description: '邮箱' },
|
|
41
|
+
phone: { type: 'string', description: '电话' },
|
|
42
|
+
gender: { type: 'string', description: '性别' },
|
|
43
|
+
birthday: { type: 'string', format: 'date', description: '出生日期' },
|
|
44
|
+
description: { type: 'string', description: '个人简介' },
|
|
45
|
+
currentTenantId: { type: 'string', description: '当前租户ID' },
|
|
46
|
+
status: { type: 'number', description: '状态' }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
21
56
|
},
|
|
22
57
|
async request => {
|
|
23
58
|
return { userInfo: request.userInfo };
|
|
@@ -29,12 +64,14 @@ module.exports = fp(async (fastify, options) => {
|
|
|
29
64
|
{
|
|
30
65
|
onRequest: [authenticate.user, authenticate.admin],
|
|
31
66
|
schema: {
|
|
67
|
+
tags: ['管理后台'],
|
|
68
|
+
summary: '设置用户为超级管理员',
|
|
32
69
|
body: {
|
|
33
70
|
type: 'object',
|
|
34
71
|
required: ['status', 'userId'],
|
|
35
72
|
properties: {
|
|
36
|
-
status: { type: 'boolean' },
|
|
37
|
-
userId: { type: 'string' }
|
|
73
|
+
status: { type: 'boolean', description: 'true:将用户设置为超级管理员,false:取消用户超级管理员' },
|
|
74
|
+
userId: { type: 'string', description: '用户ID' }
|
|
38
75
|
}
|
|
39
76
|
}
|
|
40
77
|
}
|
|
@@ -66,7 +103,10 @@ module.exports = fp(async (fastify, options) => {
|
|
|
66
103
|
{
|
|
67
104
|
onRequest: [authenticate.user, authenticate.admin],
|
|
68
105
|
schema: {
|
|
69
|
-
query: {
|
|
106
|
+
query: {
|
|
107
|
+
perPage: { type: 'number' },
|
|
108
|
+
currentPage: { type: 'number' }
|
|
109
|
+
}
|
|
70
110
|
}
|
|
71
111
|
},
|
|
72
112
|
async request => {
|
|
@@ -5,7 +5,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
5
5
|
const queryFilter = {};
|
|
6
6
|
const { count, rows } = await models.tenantToken.findAndCountAll({
|
|
7
7
|
where: Object.assign({}, queryFilter, { tenantId, type: 10 }),
|
|
8
|
-
offset:
|
|
8
|
+
offset: perPage * (currentPage - 1),
|
|
9
9
|
limit: perPage
|
|
10
10
|
});
|
|
11
11
|
return { pageData: rows, totalCount: count };
|
|
@@ -11,7 +11,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
11
11
|
}
|
|
12
12
|
const { count, rows } = await models.tenantRole.findAndCountAll({
|
|
13
13
|
where: Object.assign({}, queryFilter, { tenantId }),
|
|
14
|
-
offset:
|
|
14
|
+
offset: perPage * (currentPage - 1),
|
|
15
15
|
limit: perPage
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -471,7 +471,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
471
471
|
const { count, rows } = await fastify.account.models.tenantUser.findAndCountAll({
|
|
472
472
|
include: [fastify.account.models.tenantRole, fastify.account.models.tenantOrg, fastify.account.models.user],
|
|
473
473
|
where: Object.assign({}, queryFilter, { tenantId }),
|
|
474
|
-
offset:
|
|
474
|
+
offset: perPage * (currentPage - 1),
|
|
475
475
|
limit: perPage
|
|
476
476
|
});
|
|
477
477
|
|
package/libs/services/tenant.js
CHANGED
|
@@ -98,7 +98,7 @@ module.exports = fp(async (fastify, options) => {
|
|
|
98
98
|
|
|
99
99
|
const { count, rows } = await models.tenant.findAndCountAll({
|
|
100
100
|
where: queryFilter,
|
|
101
|
-
offset:
|
|
101
|
+
offset: perPage * (currentPage - 1),
|
|
102
102
|
limit: perPage
|
|
103
103
|
});
|
|
104
104
|
|