@modular-rest/server 1.10.2 → 1.10.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/package.json +1 -1
- package/src/application.js +1 -0
- package/src/class/db_schemas.js +12 -9
- package/src/services/jwt/service.js +32 -40
- package/src/services/user_manager/db.js +10 -7
package/package.json
CHANGED
package/src/application.js
CHANGED
|
@@ -24,6 +24,7 @@ const { config, setConfig } = require("./config");
|
|
|
24
24
|
* @param {{
|
|
25
25
|
* cors?: Cors; // CORS options.
|
|
26
26
|
* modulesPath?: string; // Root directory of your router.js/db.js files.
|
|
27
|
+
* uploadDirectory?: string; // Root directory of your uploaded files.
|
|
27
28
|
* staticPath?: {
|
|
28
29
|
* rootDir?: string; // Root directory of your static files.
|
|
29
30
|
* rootPath?: string; // Root path of your static files.
|
package/src/class/db_schemas.js
CHANGED
|
@@ -2,13 +2,16 @@ var mongoose = require("mongoose");
|
|
|
2
2
|
var Schema = mongoose.Schema;
|
|
3
3
|
|
|
4
4
|
module.exports = {
|
|
5
|
-
file: new Schema(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
file: new Schema(
|
|
6
|
+
{
|
|
7
|
+
originalName: String,
|
|
8
|
+
fileName: String,
|
|
9
|
+
owner: String,
|
|
10
|
+
format: String,
|
|
11
|
+
// Tag being used as the parent dir for files
|
|
12
|
+
// uploadDir/$format/$tag/timestamp.format
|
|
13
|
+
tag: String,
|
|
14
|
+
},
|
|
15
|
+
{ timestamps: true }
|
|
16
|
+
),
|
|
14
17
|
};
|
|
@@ -1,45 +1,37 @@
|
|
|
1
|
-
const jwt = require(
|
|
1
|
+
const jwt = require("jsonwebtoken");
|
|
2
2
|
|
|
3
|
-
class JWT
|
|
4
|
-
{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.publicKey = publicKey;
|
|
9
|
-
}
|
|
3
|
+
class JWT {
|
|
4
|
+
setKies(privateKey, publicKey) {
|
|
5
|
+
this.privateKey = privateKey;
|
|
6
|
+
this.publicKey = publicKey;
|
|
7
|
+
}
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
{
|
|
15
|
-
let option = { algorithm: 'RS256'};
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
let token = jwt.sign(payload, this.privateKey, option);
|
|
19
|
-
done(token);
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
reject(error.message);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
9
|
+
sign(payload) {
|
|
10
|
+
return new Promise((done, reject) => {
|
|
11
|
+
let option = { algorithm: "RS256" };
|
|
26
12
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
13
|
+
try {
|
|
14
|
+
let token = jwt.sign(payload, this.privateKey, option);
|
|
15
|
+
done(token);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
reject(error.message);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
verify(token) {
|
|
23
|
+
return new Promise((done, reject) => {
|
|
24
|
+
let option = { algorithm: "RS256" };
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
let decoded = jwt.verify(token, this.publicKey, option);
|
|
28
|
+
done(decoded);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
reject(error);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
42
34
|
}
|
|
43
35
|
|
|
44
|
-
module.exports.name =
|
|
45
|
-
module.exports.main = new JWT();
|
|
36
|
+
module.exports.name = "jwt";
|
|
37
|
+
module.exports.main = new JWT();
|
|
@@ -6,13 +6,16 @@ let { Permission, PermissionTypes } = require("../../class/security");
|
|
|
6
6
|
const { config } = require("../../config");
|
|
7
7
|
const triggerOperator = require("./../../class/trigger_operator");
|
|
8
8
|
|
|
9
|
-
let authSchema = new Schema(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
9
|
+
let authSchema = new Schema(
|
|
10
|
+
{
|
|
11
|
+
permissionGroup: String,
|
|
12
|
+
email: String,
|
|
13
|
+
phone: String,
|
|
14
|
+
password: String,
|
|
15
|
+
type: { type: String, default: "user", enum: ["user", "anonymous"] },
|
|
16
|
+
},
|
|
17
|
+
{ timestamps: true }
|
|
18
|
+
);
|
|
16
19
|
|
|
17
20
|
authSchema.index({ email: 1 }, { unique: true });
|
|
18
21
|
authSchema.pre(["save", "updateOne"], function (next) {
|