expressa 2.0.13 → 2.0.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.
@@ -1,52 +1,52 @@
1
- const auth = require('../auth')
2
- const util = require('../util')
3
- const collectionsApi = require('./collections')
4
- const permissions = require('../middleware/permissions')
5
-
6
- exports.login = async (req, collection) => {
7
- const password = req.body.password
8
-
9
- if (typeof req.body.email !== 'string') {
10
- throw new util.ApiError(400, 'email must be a string')
11
- }
12
-
13
- req.body.email = req.body.email.toLowerCase()
14
-
15
- // check if user exists
16
- const result = await req.db[collection].find({
17
- email: req.body.email
18
- })
19
- if (result.length === 0) {
20
- throw new util.ApiError(400, 'No ' + collection + ' found with this email.')
21
- }
22
- const user = result[0]
23
- if (!auth.isValidPassword(password, user.password)) {
24
- throw new util.ApiError(401, 'Incorrect password')
25
- }
26
- const jwt_options = req.settings.jwt_expires_in ? { expiresIn: req.settings.jwt_expires_in } : {}
27
- const payload = auth.doLogin({
28
- id: user._id,
29
- collection,
30
- timestamp: user.meta.password_last_updated_at,
31
- jwt_secret: req.getSetting('jwt_secret'),
32
- jwt_options
33
- })
34
- req.uid = user._id
35
- req.ucollection = collection
36
- req.user = user
37
- await permissions.addRolePermissionsAsync(req)
38
- payload.canUseAdmin = req.hasPermission('login to admin')
39
- return payload
40
- }
41
-
42
- exports.register = function (req, collection) {
43
- req.url = `/${collection}`
44
- req.params.collection = collection
45
- return collectionsApi.insert(req)
46
- }
47
-
48
- exports.getMe = function (req, collection) {
49
- req.params.collection = collection
50
- req.params.id = req.uid
51
- return collectionsApi.getById(req)
52
- }
1
+ const auth = require('../auth')
2
+ const util = require('../util')
3
+ const collectionsApi = require('./collections')
4
+ const permissions = require('../middleware/permissions')
5
+
6
+ exports.login = async (req, collection) => {
7
+ const password = req.body.password
8
+
9
+ if (typeof req.body.email !== 'string') {
10
+ throw new util.ApiError(400, 'email must be a string')
11
+ }
12
+
13
+ req.body.email = req.body.email.toLowerCase()
14
+
15
+ // check if user exists
16
+ const result = await req.db[collection].find({
17
+ email: req.body.email
18
+ })
19
+ if (result.length === 0) {
20
+ throw new util.ApiError(400, 'No ' + collection + ' found with this email.')
21
+ }
22
+ const user = result[0]
23
+ if (!auth.isValidPassword(password, user.password)) {
24
+ throw new util.ApiError(401, 'Incorrect password')
25
+ }
26
+ const jwt_options = req.settings.jwt_expires_in ? { expiresIn: req.settings.jwt_expires_in } : {}
27
+ const payload = auth.doLogin({
28
+ id: user._id,
29
+ collection,
30
+ timestamp: user.meta.password_last_updated_at,
31
+ jwt_secret: req.getSetting('jwt_secret'),
32
+ jwt_options
33
+ })
34
+ req.uid = user._id
35
+ req.ucollection = collection
36
+ req.user = user
37
+ await permissions.addRolePermissionsAsync(req)
38
+ payload.canUseAdmin = req.hasPermission('login to admin')
39
+ return payload
40
+ }
41
+
42
+ exports.register = function (req, collection) {
43
+ req.url = `/${collection}`
44
+ req.params.collection = collection
45
+ return collectionsApi.insert(req)
46
+ }
47
+
48
+ exports.getMe = function (req, collection) {
49
+ req.params.collection = collection
50
+ req.params.id = req.uid
51
+ return collectionsApi.getById(req)
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expressa",
3
- "version": "2.0.13",
3
+ "version": "2.0.14",
4
4
  "description": "API framework using JSON schemas",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/thomas4019/expressa",
package/util.js CHANGED
@@ -75,6 +75,8 @@ exports.getSchemaProperty = function(collection, path) {
75
75
  for (const part of parts) {
76
76
  if (obj.properties && obj.properties[part]) {
77
77
  obj = obj.properties[part]
78
+ } else if (obj.items && obj.items.properties && obj.items.properties[part]) {
79
+ obj = obj.items.properties[part]
78
80
  } else {
79
81
  return
80
82
  }