q-koa 10.8.6 → 10.9.0
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.
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const { getAppByCtx, getUserByCtx, getConfig, lodash } = require('q-koa')
|
|
2
|
+
|
|
3
|
+
exports.login = async (ctx) => {
|
|
4
|
+
const { app, appName } = getAppByCtx(ctx)
|
|
5
|
+
const user_id = getUserByCtx(ctx)
|
|
6
|
+
const appConfig = getConfig(app)
|
|
7
|
+
const { is_dev } = await appConfig.getObject('base')
|
|
8
|
+
const { uuid } = ctx.request.body
|
|
9
|
+
console.log(uuid)
|
|
10
|
+
if (!app.attributes.user.uuid) throw new Error(`没有uuid字段`)
|
|
11
|
+
|
|
12
|
+
const hasUser = await app.model.user.findOne({
|
|
13
|
+
where: {
|
|
14
|
+
uuid,
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
let result = null
|
|
19
|
+
if (!hasUser) {
|
|
20
|
+
result = await app.model.user.create({
|
|
21
|
+
uuid,
|
|
22
|
+
})
|
|
23
|
+
} else {
|
|
24
|
+
result = hasUser
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const tokenResult = {
|
|
28
|
+
id: result.id,
|
|
29
|
+
name: result.name,
|
|
30
|
+
mobile: result.mobile,
|
|
31
|
+
h5_user: result.h5_user
|
|
32
|
+
? {
|
|
33
|
+
openid: result.h5_user && result.h5_user.openid,
|
|
34
|
+
}
|
|
35
|
+
: null,
|
|
36
|
+
mp_user: result.mp_user
|
|
37
|
+
? {
|
|
38
|
+
openid: result.mp_user && result.mp_user.openid,
|
|
39
|
+
}
|
|
40
|
+
: null,
|
|
41
|
+
toutiao_user: result.toutiao_user
|
|
42
|
+
? {
|
|
43
|
+
openid: result.toutiao_user && result.toutiao_user.openid,
|
|
44
|
+
}
|
|
45
|
+
: null,
|
|
46
|
+
}
|
|
47
|
+
const token = await app.sign({
|
|
48
|
+
user: tokenResult,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return ctx.SUCCESS({
|
|
52
|
+
token,
|
|
53
|
+
user: app.appConfig.loginData
|
|
54
|
+
? lodash.omit(result.toJSON(), app.appConfig.loginData.omit)
|
|
55
|
+
: result,
|
|
56
|
+
})
|
|
57
|
+
}
|
|
@@ -203,7 +203,7 @@ exports.getTable = async (ctx) => {
|
|
|
203
203
|
show_virtual = false,
|
|
204
204
|
is_cache = true,
|
|
205
205
|
} = ctx.request.body
|
|
206
|
-
|
|
206
|
+
if (_model === 'page') return ctx.SUCCESS({})
|
|
207
207
|
if (is_cache && app.cache && app.cache.get(`${_model}-table`)) {
|
|
208
208
|
return ctx.SUCCESS(app.cache.get(`${_model}-table`))
|
|
209
209
|
}
|