q-koa 9.7.6 → 9.8.1
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/core/app.js
CHANGED
|
@@ -873,7 +873,11 @@ class APP {
|
|
|
873
873
|
|
|
874
874
|
if (fn === 'updateSort') {
|
|
875
875
|
if (cacheModel.includes(controller)) {
|
|
876
|
-
ctx.app[appName].
|
|
876
|
+
if (ctx.app[appName].redisClient) {
|
|
877
|
+
ctx.app[appName].redisClient.publish('cache clear', `${controller}`)
|
|
878
|
+
} else {
|
|
879
|
+
ctx.app[appName].cache.set(`${controller}`, null)
|
|
880
|
+
}
|
|
877
881
|
}
|
|
878
882
|
}
|
|
879
883
|
|
|
@@ -1759,6 +1763,16 @@ class APP {
|
|
|
1759
1763
|
const result = await app[appName].model[controller][fn](list)
|
|
1760
1764
|
ctx.SUCCESS(result)
|
|
1761
1765
|
}
|
|
1766
|
+
if (cacheModel.includes(controller)) {
|
|
1767
|
+
if (ctx.app[appName].redisClient) {
|
|
1768
|
+
ctx.app[appName].redisClient.publish(
|
|
1769
|
+
'cache clear',
|
|
1770
|
+
`${controller}`
|
|
1771
|
+
)
|
|
1772
|
+
} else {
|
|
1773
|
+
ctx.app[appName].cache.set(`${controller}`, null)
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1762
1776
|
}
|
|
1763
1777
|
|
|
1764
1778
|
if (fn === 'upsert' || fn === 'create') {
|
|
@@ -1788,7 +1802,14 @@ class APP {
|
|
|
1788
1802
|
ctx.SUCCESS(flag)
|
|
1789
1803
|
|
|
1790
1804
|
if (cacheModel.includes(controller)) {
|
|
1791
|
-
ctx.app[appName].
|
|
1805
|
+
if (ctx.app[appName].redisClient) {
|
|
1806
|
+
ctx.app[appName].redisClient.publish(
|
|
1807
|
+
'cache clear',
|
|
1808
|
+
`${controller}`
|
|
1809
|
+
)
|
|
1810
|
+
} else {
|
|
1811
|
+
ctx.app[appName].cache.set(`${controller}`, null)
|
|
1812
|
+
}
|
|
1792
1813
|
}
|
|
1793
1814
|
}
|
|
1794
1815
|
|
|
@@ -1813,7 +1834,14 @@ class APP {
|
|
|
1813
1834
|
ctx.SUCCESS(result)
|
|
1814
1835
|
|
|
1815
1836
|
if (cacheModel.includes(controller)) {
|
|
1816
|
-
ctx.app[appName].
|
|
1837
|
+
if (ctx.app[appName].redisClient) {
|
|
1838
|
+
ctx.app[appName].redisClient.publish(
|
|
1839
|
+
'cache clear',
|
|
1840
|
+
`${controller}`
|
|
1841
|
+
)
|
|
1842
|
+
} else {
|
|
1843
|
+
ctx.app[appName].cache.set(`${controller}`, null)
|
|
1844
|
+
}
|
|
1817
1845
|
}
|
|
1818
1846
|
}
|
|
1819
1847
|
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
const md5 = require('js-md5')
|
|
2
2
|
const { getAppByCtx, getConfig, lodash } = require('q-koa')
|
|
3
3
|
const { getAppConfig } = require('../../utils')
|
|
4
|
+
|
|
4
5
|
exports.login = async (ctx) => {
|
|
5
6
|
const { app, appName } = getAppByCtx(ctx)
|
|
6
|
-
const { mobile, password, ...rest } = ctx.request.body
|
|
7
|
+
const { mobile, password, config: _config, ...rest } = ctx.request.body
|
|
8
|
+
|
|
9
|
+
const config = _config || ctx.request.header.config || 'weixin_mp'
|
|
10
|
+
const appConfig = getConfig(app)
|
|
11
|
+
const { app_id } = await appConfig.getObject(config)
|
|
12
|
+
|
|
7
13
|
const where =
|
|
8
14
|
process.env.NODE_ENV !== 'production'
|
|
9
15
|
? {
|
|
@@ -86,26 +92,73 @@ exports.login = async (ctx) => {
|
|
|
86
92
|
/**
|
|
87
93
|
* 查出最新用户,存token并返回
|
|
88
94
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
id: result.id,
|
|
92
|
-
},
|
|
93
|
-
include: [
|
|
94
|
-
{
|
|
95
|
-
model: app.model.github_user,
|
|
96
|
-
},
|
|
97
|
-
{
|
|
95
|
+
const h5_user_include = config.includes('h5')
|
|
96
|
+
? {
|
|
98
97
|
model: app.model.h5_user,
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
where: {
|
|
99
|
+
appid: app_id,
|
|
100
|
+
},
|
|
101
|
+
attributes: {
|
|
102
|
+
exclude: ['created_at', 'updated_at', 'createdid'],
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
: {
|
|
106
|
+
model: app.model.h5_user,
|
|
107
|
+
}
|
|
108
|
+
const mp_user_include = config.includes('mp')
|
|
109
|
+
? {
|
|
110
|
+
model: app.model.mp_user,
|
|
111
|
+
where: {
|
|
112
|
+
appid: app_id,
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
: {
|
|
101
116
|
model: app.model.mp_user,
|
|
117
|
+
}
|
|
118
|
+
const includeDefault = [
|
|
119
|
+
{
|
|
120
|
+
model: app.model.github_user,
|
|
121
|
+
},
|
|
122
|
+
h5_user_include,
|
|
123
|
+
mp_user_include,
|
|
124
|
+
{
|
|
125
|
+
model: app.model.toutiao_user,
|
|
126
|
+
},
|
|
127
|
+
...app.include.user,
|
|
128
|
+
].filter((item) => item.model)
|
|
129
|
+
|
|
130
|
+
if (app.appConfig.loginData) {
|
|
131
|
+
const include = includeDefault.filter((i) => {
|
|
132
|
+
return app.appConfig.loginData.excludeInclude.every((m) => {
|
|
133
|
+
return app.model[m] !== i.model
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
const { exclude_list = [] } = await getAppConfig({ app, config })
|
|
137
|
+
const attributes = {
|
|
138
|
+
exclude: Array.from(
|
|
139
|
+
new Set([
|
|
140
|
+
...app.appConfig.loginData.attributes.exclude,
|
|
141
|
+
...(Array.isArray(exclude_list) ? exclude_list : []),
|
|
142
|
+
])
|
|
143
|
+
),
|
|
144
|
+
}
|
|
145
|
+
result = await app.model.user.findOne({
|
|
146
|
+
where: {
|
|
147
|
+
id: result.id,
|
|
102
148
|
},
|
|
103
|
-
|
|
104
|
-
|
|
149
|
+
attributes,
|
|
150
|
+
include,
|
|
151
|
+
})
|
|
152
|
+
} else {
|
|
153
|
+
result = await app.model.user.findOne({
|
|
154
|
+
where: {
|
|
155
|
+
id: result.id,
|
|
105
156
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
157
|
+
include: includeDefault,
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!result) throw new Error('账号密码错误,或者不属于当前应用')
|
|
109
162
|
|
|
110
163
|
const tokenResult = {
|
|
111
164
|
id: result.id,
|
|
@@ -133,7 +186,9 @@ exports.login = async (ctx) => {
|
|
|
133
186
|
|
|
134
187
|
return ctx.SUCCESS({
|
|
135
188
|
token,
|
|
136
|
-
user:
|
|
189
|
+
user: app.appConfig.loginData
|
|
190
|
+
? lodash.omit(result.toJSON(), app.appConfig.loginData.omit)
|
|
191
|
+
: result,
|
|
137
192
|
})
|
|
138
193
|
}
|
|
139
194
|
|
|
@@ -11,6 +11,7 @@ const WXBizDataCrypt = require('../../services/weixinCrypt')
|
|
|
11
11
|
const weixinArticle = require('../../services/weixinArticle')
|
|
12
12
|
const fxp = require('fast-xml-parser')
|
|
13
13
|
const crypto = require('crypto')
|
|
14
|
+
const { getAppConfig } = require('../../utils')
|
|
14
15
|
|
|
15
16
|
const check = ({ timestamp, nonce, signature, token }) => {
|
|
16
17
|
const tmp = [token, timestamp, nonce].sort().join('')
|
|
@@ -387,25 +388,74 @@ exports.mp_login = async (ctx) => {
|
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
390
|
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
id: uid,
|
|
393
|
-
},
|
|
394
|
-
include: [
|
|
395
|
-
{
|
|
391
|
+
const h5_user_include = config.includes('h5')
|
|
392
|
+
? {
|
|
396
393
|
model: app.model.h5_user,
|
|
397
|
-
|
|
398
|
-
|
|
394
|
+
where: {
|
|
395
|
+
appid: app_id,
|
|
396
|
+
},
|
|
397
|
+
attributes: {
|
|
398
|
+
exclude: ['created_at', 'updated_at', 'createdid'],
|
|
399
|
+
},
|
|
400
|
+
}
|
|
401
|
+
: {
|
|
402
|
+
model: app.model.h5_user,
|
|
403
|
+
}
|
|
404
|
+
const mp_user_include = config.includes('mp')
|
|
405
|
+
? {
|
|
399
406
|
model: app.model.mp_user,
|
|
407
|
+
where: {
|
|
408
|
+
appid: app_id,
|
|
409
|
+
},
|
|
410
|
+
}
|
|
411
|
+
: {
|
|
412
|
+
model: app.model.mp_user,
|
|
413
|
+
}
|
|
414
|
+
let result
|
|
415
|
+
const includeDefault = [
|
|
416
|
+
{
|
|
417
|
+
model: app.model.github_user,
|
|
418
|
+
},
|
|
419
|
+
h5_user_include,
|
|
420
|
+
mp_user_include,
|
|
421
|
+
{
|
|
422
|
+
model: app.model.toutiao_user,
|
|
423
|
+
},
|
|
424
|
+
...app.include.user,
|
|
425
|
+
].filter((item) => item.model)
|
|
426
|
+
|
|
427
|
+
if (app.appConfig.loginData) {
|
|
428
|
+
const include = includeDefault.filter((i) => {
|
|
429
|
+
return app.appConfig.loginData.excludeInclude.every((m) => {
|
|
430
|
+
return app.model[m] !== i.model
|
|
431
|
+
})
|
|
432
|
+
})
|
|
433
|
+
const { exclude_list = [] } = await getAppConfig({ app, config })
|
|
434
|
+
const attributes = {
|
|
435
|
+
exclude: Array.from(
|
|
436
|
+
new Set([
|
|
437
|
+
...app.appConfig.loginData.attributes.exclude,
|
|
438
|
+
...(Array.isArray(exclude_list) ? exclude_list : []),
|
|
439
|
+
])
|
|
440
|
+
),
|
|
441
|
+
}
|
|
442
|
+
result = await app.model.user.findOne({
|
|
443
|
+
where: {
|
|
444
|
+
id: uid,
|
|
400
445
|
},
|
|
401
|
-
|
|
402
|
-
|
|
446
|
+
attributes,
|
|
447
|
+
include,
|
|
448
|
+
})
|
|
449
|
+
} else {
|
|
450
|
+
result = await app.model.user.findOne({
|
|
451
|
+
where: {
|
|
452
|
+
id: uid,
|
|
403
453
|
},
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
454
|
+
include: includeDefault,
|
|
455
|
+
})
|
|
456
|
+
}
|
|
407
457
|
|
|
408
|
-
if (!result.id) throw new Error('登录失败')
|
|
458
|
+
if (!(result && result.id)) throw new Error('登录失败')
|
|
409
459
|
|
|
410
460
|
const tokenResult = {
|
|
411
461
|
id: result.id,
|
|
@@ -434,7 +484,9 @@ exports.mp_login = async (ctx) => {
|
|
|
434
484
|
|
|
435
485
|
return ctx.SUCCESS({
|
|
436
486
|
token,
|
|
437
|
-
user:
|
|
487
|
+
user: app.appConfig.loginData
|
|
488
|
+
? lodash.omit(result.toJSON(), app.appConfig.loginData.omit)
|
|
489
|
+
: result,
|
|
438
490
|
})
|
|
439
491
|
}
|
|
440
492
|
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const { getAppByCtx, getConfig } = require('q-koa')
|
|
2
|
-
|
|
3
|
-
exports.upsert = async (ctx) => {
|
|
4
|
-
const { app } = getAppByCtx(ctx)
|
|
5
|
-
const appConfig = getConfig(app)
|
|
6
|
-
appConfig.update('application')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
exports.bulkCreate = async (ctx) => {
|
|
10
|
-
const { app } = getAppByCtx(ctx)
|
|
11
|
-
const appConfig = getConfig(app)
|
|
12
|
-
appConfig.update('application')
|
|
13
|
-
}
|