sumba 0.1.2 → 0.1.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/bajo/helper/get-user-from-username-password.js +1 -1
- package/bajo/helper/verify/api-key.js +1 -1
- package/bajo/helper/verify/jwt.js +1 -1
- package/bajoDb/fixture/site-setting.json +1 -1
- package/bajoDb/fixture/site.json +1 -1
- package/bajoDb/fixture/user-setting.json +2 -2
- package/bajoDb/fixture/user.json +1 -2
- package/bajoDb/schema/site.json +2 -2
- package/lib/check-site-id.js +3 -2
- package/lib/check-user-id.js +1 -1
- package/package.json +1 -1
- package/bajoDb/feature/dt.js +0 -13
|
@@ -6,7 +6,7 @@ async function getUserByUsernamePassword (username = '', password = '', req) {
|
|
|
6
6
|
await validate({ username, password }, 'SumbaUser', { ns: ['sumba', 'bajoDb'], fields: ['username', 'password'] })
|
|
7
7
|
const bcrypt = await importPkg('bajo-extra:bcrypt')
|
|
8
8
|
const query = { username }
|
|
9
|
-
const rows = await recordFind(coll, { query }, { req, ignoreHidden: true })
|
|
9
|
+
const rows = await recordFind(coll, { query }, { req, ignoreHidden: true, skipHook: true })
|
|
10
10
|
if (rows.length === 0) throw error('Unknown username', { details: [{ field: 'username', error: 'Unknown username' }], statusCode: 401 })
|
|
11
11
|
const rec = rows[0]
|
|
12
12
|
if (rec.status !== 'ACTIVE') throw error('User is inactive or temporary disabled', { details: ['User is inactive or temporary disabled'], statusCode: 401 })
|
|
@@ -30,7 +30,7 @@ async function verifyApiKey (ctx, req, reply, source) {
|
|
|
30
30
|
if (!isMd5(token)) return false
|
|
31
31
|
token = await hash(token)
|
|
32
32
|
const query = { token }
|
|
33
|
-
const rows = await recordFind('SumbaUser', { query }, { req })
|
|
33
|
+
const rows = await recordFind('SumbaUser', { query }, { req, skipHook: true })
|
|
34
34
|
if (rows.length === 0) throw error('Invalid api key provided', { statusCode: 401 })
|
|
35
35
|
if (rows[0].status !== 'ACTIVE') throw error('User is inactive or temporary disabled', { details: [{ field: 'status', error: 'inactive' }], statusCode: 401 })
|
|
36
36
|
req.user = await getUser(rows[0])
|
|
@@ -17,7 +17,7 @@ async function verifyJwt (ctx, req, reply, source) {
|
|
|
17
17
|
const decoded = await verifier(token)
|
|
18
18
|
const id = decoded.payload.uid
|
|
19
19
|
try {
|
|
20
|
-
const rec = await recordGet('SumbaUser', id, { req })
|
|
20
|
+
const rec = await recordGet('SumbaUser', id, { req, skipHook: true })
|
|
21
21
|
if (!rec) throw error('Invalid token or token is expired', { statusCode: 401 })
|
|
22
22
|
if (rec.status !== 'ACTIVE') throw error('User is inactive or temporary disabled', { details: [{ field: 'status', error: 'inactive' }], statusCode: 401 })
|
|
23
23
|
req.user = await getUser(rec)
|
package/bajoDb/fixture/site.json
CHANGED
package/bajoDb/fixture/user.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
[{
|
|
2
|
-
"id": "admin",
|
|
3
2
|
"username": "admin",
|
|
4
3
|
"password": "Sumb44dm!n",
|
|
5
4
|
"email": "admin@domain.com",
|
|
6
5
|
"firstName": "Site",
|
|
7
6
|
"lastName": "Admin",
|
|
8
7
|
"country": "US",
|
|
9
|
-
"siteId": "
|
|
8
|
+
"siteId": "?:SumbaSite::alias:default",
|
|
10
9
|
"status": "ACTIVE"
|
|
11
10
|
}]
|
package/bajoDb/schema/site.json
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
"type": "string",
|
|
5
5
|
"minLength": 5,
|
|
6
6
|
"maxLength": 100,
|
|
7
|
-
"
|
|
7
|
+
"index": "unique"
|
|
8
8
|
}, {
|
|
9
9
|
"name": "alias",
|
|
10
10
|
"type": "string",
|
|
11
11
|
"maxLength": 100,
|
|
12
|
-
"
|
|
12
|
+
"index": "unique"
|
|
13
13
|
}, {
|
|
14
14
|
"name": "title",
|
|
15
15
|
"type": "string",
|
package/lib/check-site-id.js
CHANGED
|
@@ -11,7 +11,8 @@ async function checkSiteId (req, reply) {
|
|
|
11
11
|
const { recordFind, recordGet } = this.bajoDb.helper
|
|
12
12
|
const cfg = getConfig('sumba')
|
|
13
13
|
if (!cfg.multiSite) {
|
|
14
|
-
|
|
14
|
+
const resp = await recordFind('SumbaSite', { query: { alias: 'default' } }, { skipHook: true })
|
|
15
|
+
req.site = resp[0]
|
|
15
16
|
await mergeSetting.call(this, req)
|
|
16
17
|
return
|
|
17
18
|
}
|
|
@@ -23,7 +24,7 @@ async function checkSiteId (req, reply) {
|
|
|
23
24
|
]
|
|
24
25
|
}
|
|
25
26
|
const filter = { query }
|
|
26
|
-
const rows = await recordFind('SumbaSite', filter)
|
|
27
|
+
const rows = await recordFind('SumbaSite', filter, { skipHook: true })
|
|
27
28
|
if (rows.length === 0) throw error('Unknown site or site is not configured yet')
|
|
28
29
|
const row = rows[0]
|
|
29
30
|
if (row.status !== 'ACTIVE') throw error('This site is currently inactive or disabled. Please contact your admin, thanks!')
|
package/lib/check-user-id.js
CHANGED
|
@@ -44,7 +44,7 @@ async function mergeSetting (req) {
|
|
|
44
44
|
const { getConfig } = this.bajo.helper
|
|
45
45
|
const { recordFind } = this.bajoDb.helper
|
|
46
46
|
const filter = { query: { siteId: req.site.id, userId: req.user.id }, limit: 1 }
|
|
47
|
-
const settings = await recordFind('SumbaUserSetting', filter)
|
|
47
|
+
const settings = await recordFind('SumbaUserSetting', filter, { skipHook: true })
|
|
48
48
|
req.user.setting = settings[0] ?? { theme: getConfig('bajoWebMpa').theme ?? '' }
|
|
49
49
|
}
|
|
50
50
|
|
package/package.json
CHANGED
package/bajoDb/feature/dt.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
async function dt (opts = {}) {
|
|
2
|
-
opts.fieldName = opts.fieldName ?? 'dt'
|
|
3
|
-
return {
|
|
4
|
-
properties: [{
|
|
5
|
-
name: opts.fieldName ?? 'dt',
|
|
6
|
-
type: 'datetime',
|
|
7
|
-
required: opts.required ?? true,
|
|
8
|
-
index: opts.index ?? true
|
|
9
|
-
}]
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default dt
|