chyz 1.0.13-rc.2 → 1.0.13-rc.23
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/BaseChyz.ts +60 -18
- package/Doc/Moel kullanma.md +13 -0
- package/Examples/Controllers/ApiController.ts +35 -26
- package/Examples/Controllers/BasicApiController.ts +121 -0
- package/Examples/Controllers/KeyCloakController.ts +4 -4
- package/Examples/Controllers/SiteController.ts +18 -8
- package/Examples/Models/AuthAssignment.ts +50 -0
- package/Examples/Models/AuthItem.ts +59 -0
- package/Examples/Models/AuthItemChild.ts +49 -0
- package/Examples/Models/Categories.ts +14 -3
- package/Examples/Models/Customer.ts +2 -2
- package/Examples/Models/KeycloakUser.ts +4 -0
- package/Examples/Models/Order.ts +5 -5
- package/Examples/Models/OrderItem.ts +2 -2
- package/Examples/Models/ProductModels.ts +4 -5
- package/Examples/Models/ProductToCategories.ts +15 -4
- package/Examples/Models/Products.ts +9 -8
- package/Examples/Models/Stocks.ts +2 -2
- package/Examples/Models/User.ts +8 -1
- package/Examples/Models/UserPermission.ts +2 -2
- package/Examples/Models/index.ts +19 -0
- package/Examples/index.ts +20 -1
- package/Examples/log/app.log +9456 -0
- package/Examples/log/errors.log +1904 -0
- package/Examples/tsconfig.json +2 -1
- package/README.md +267 -16
- package/base/ActionFilter.ts +1 -1
- package/base/BaseError.ts +4 -2
- package/base/InvalidArgumentException.ts +16 -0
- package/base/Model.ts +81 -55
- package/base/ModelManager.ts +19 -0
- package/base/RestClient.ts +4 -4
- package/base/ValidationHttpException.ts +1 -1
- package/base/index.ts +2 -0
- package/dist/BaseChyz.js +48 -9
- package/dist/BaseChyz.js.map +1 -1
- package/dist/base/ActionFilter.js +1 -1
- package/dist/base/ActionFilter.js.map +1 -1
- package/dist/base/BaseError.js +6 -2
- package/dist/base/BaseError.js.map +1 -1
- package/dist/base/InvalidArgumentException.js +18 -0
- package/dist/base/InvalidArgumentException.js.map +1 -0
- package/dist/base/Model.js +47 -32
- package/dist/base/Model.js.map +1 -1
- package/dist/base/ModelManager.js +9 -0
- package/dist/base/ModelManager.js.map +1 -0
- package/dist/base/RestClient.js +4 -4
- package/dist/base/RestClient.js.map +1 -1
- package/dist/base/ValidationHttpException.js +1 -1
- package/dist/base/index.js +2 -0
- package/dist/base/index.js.map +1 -1
- package/dist/filters/AccessControl.js +15 -3
- package/dist/filters/AccessControl.js.map +1 -1
- package/dist/filters/AccessRule.js +99 -38
- package/dist/filters/AccessRule.js.map +1 -1
- package/dist/filters/auth/HttpBasicAuth.js +65 -0
- package/dist/filters/auth/HttpBasicAuth.js.map +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
- package/dist/filters/auth/index.js +1 -0
- package/dist/filters/auth/index.js.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/package.json +55 -0
- package/dist/rbac/AuthAssignment.js +45 -0
- package/dist/rbac/AuthAssignment.js.map +1 -0
- package/dist/rbac/AuthItem.js +52 -0
- package/dist/rbac/AuthItem.js.map +1 -0
- package/dist/rbac/AuthItemChild.js +44 -0
- package/dist/rbac/AuthItemChild.js.map +1 -0
- package/dist/rbac/AuthManager.js +359 -0
- package/dist/rbac/AuthManager.js.map +1 -0
- package/dist/web/WebUser.js +78 -0
- package/dist/web/WebUser.js.map +1 -1
- package/filters/AccessControl.ts +19 -6
- package/filters/AccessRule.ts +61 -16
- package/filters/auth/HttpBasicAuth.ts +68 -0
- package/filters/auth/JwtHttpBearerAuth.ts +1 -1
- package/filters/auth/index.ts +1 -0
- package/index.ts +2 -2
- package/package-lock.json +5259 -0
- package/package.json +6 -6
- package/rbac/AuthAssignment.ts +50 -0
- package/rbac/AuthItem.ts +57 -0
- package/rbac/AuthItemChild.ts +50 -0
- package/rbac/AuthManager.ts +398 -0
- package/web/IdentityInterface.ts +6 -0
- package/web/WebUser.ts +88 -1
- package/Examples/yarn.lock +0 -2549
package/BaseChyz.ts
CHANGED
|
@@ -3,11 +3,14 @@ import {RouteDefinition} from "./model/RouteDefinition";
|
|
|
3
3
|
import {NextFunction, Request, Response} from "express";
|
|
4
4
|
import {Controller} from "./base/Controller";
|
|
5
5
|
import Utils from "./requiments/Utils";
|
|
6
|
+
import {ModelManager} from "./base";
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
const express = require("express");
|
|
9
10
|
const log4js = require("log4js");
|
|
10
11
|
const fs = require('fs');
|
|
12
|
+
const validate = require('validate.js');
|
|
13
|
+
|
|
11
14
|
|
|
12
15
|
var ip = require('ip');
|
|
13
16
|
var bodyParser = require('body-parser')
|
|
@@ -21,6 +24,7 @@ export default class BaseChyz {
|
|
|
21
24
|
private _port: number = 3001;
|
|
22
25
|
static db: any;
|
|
23
26
|
static routes: any;
|
|
27
|
+
private static _validate: any = validate;
|
|
24
28
|
private _logConfig: any = require('./log/config/log4js.json') ?? {}
|
|
25
29
|
private _controllerpath: string = "Controllers"
|
|
26
30
|
private static controllers: Array<Controller> = []
|
|
@@ -45,8 +49,7 @@ export default class BaseChyz {
|
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
init() {
|
|
48
|
-
|
|
49
|
-
this.logProvider().configure(this._logConfig);
|
|
52
|
+
|
|
50
53
|
|
|
51
54
|
/**
|
|
52
55
|
* set request id
|
|
@@ -83,6 +86,13 @@ export default class BaseChyz {
|
|
|
83
86
|
this.controllerpath = this.config.controllerpath
|
|
84
87
|
}
|
|
85
88
|
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Model Register
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
this.loadModels();
|
|
95
|
+
|
|
86
96
|
/**
|
|
87
97
|
* Express Server
|
|
88
98
|
*/
|
|
@@ -114,6 +124,14 @@ export default class BaseChyz {
|
|
|
114
124
|
}
|
|
115
125
|
|
|
116
126
|
|
|
127
|
+
static get validate(): any {
|
|
128
|
+
return this._validate;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static set validate(value: any) {
|
|
132
|
+
this._validate = value;
|
|
133
|
+
}
|
|
134
|
+
|
|
117
135
|
app(config: any = {}): BaseChyz {
|
|
118
136
|
|
|
119
137
|
/**
|
|
@@ -122,13 +140,23 @@ export default class BaseChyz {
|
|
|
122
140
|
this.config = config;
|
|
123
141
|
|
|
124
142
|
|
|
143
|
+
// logger setting
|
|
144
|
+
this.logProvider().level = log4js.levels.ALL;
|
|
145
|
+
this.logProvider().configure(this._logConfig);
|
|
146
|
+
|
|
125
147
|
let components = Utils.findKeyValue(config, "components")
|
|
126
148
|
if (components) {
|
|
127
149
|
for (const componentsKey in components) {
|
|
150
|
+
|
|
128
151
|
let comp = components[componentsKey];
|
|
129
152
|
BaseChyz.debug("Create Component ", componentsKey)
|
|
130
|
-
|
|
131
|
-
|
|
153
|
+
try {
|
|
154
|
+
BaseChyz.components[componentsKey] = Utils.createObject(new comp.class, comp);
|
|
155
|
+
BaseChyz.components[componentsKey]?.init();
|
|
156
|
+
} catch (e) {
|
|
157
|
+
BaseChyz.error("Create Component ", e)
|
|
158
|
+
}
|
|
159
|
+
|
|
132
160
|
}
|
|
133
161
|
}
|
|
134
162
|
|
|
@@ -137,14 +165,12 @@ export default class BaseChyz {
|
|
|
137
165
|
if (middlewares) {
|
|
138
166
|
for (const middlewareKey in middlewares) {
|
|
139
167
|
let middleware1 = middlewares[middlewareKey];
|
|
140
|
-
BaseChyz.debug("Create middlewares ", middlewareKey)
|
|
168
|
+
BaseChyz.logs().debug("Create middlewares ", middlewareKey)
|
|
141
169
|
BaseChyz.middlewares[middlewareKey] = middleware1;
|
|
142
170
|
// BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
|
|
143
171
|
}
|
|
144
172
|
}
|
|
145
173
|
|
|
146
|
-
|
|
147
|
-
|
|
148
174
|
this.init();
|
|
149
175
|
|
|
150
176
|
return this;
|
|
@@ -229,6 +255,30 @@ export default class BaseChyz {
|
|
|
229
255
|
return BaseChyz.middlewares[key] ?? null
|
|
230
256
|
}
|
|
231
257
|
|
|
258
|
+
/**
|
|
259
|
+
* load model
|
|
260
|
+
*/
|
|
261
|
+
async loadModels() {
|
|
262
|
+
let models: any = {}
|
|
263
|
+
let path = `${this._controllerpath}/../Models`;
|
|
264
|
+
fs.readdirSync(path).forEach((file: string) => {
|
|
265
|
+
if (file !== "index.ts") {
|
|
266
|
+
let model = require(`${path}/${file}`);
|
|
267
|
+
// @ts-ignore
|
|
268
|
+
let className = file.split(".")[0] + "Class";
|
|
269
|
+
if (model[className])
|
|
270
|
+
models[className.replace("Class", "")] = new model[className];
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
ModelManager._register(models);
|
|
275
|
+
|
|
276
|
+
for (const key of Object.keys(ModelManager)) {
|
|
277
|
+
if (key != "_register") {
|
|
278
|
+
ModelManager[key].init();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
232
282
|
|
|
233
283
|
/**
|
|
234
284
|
* load contoller
|
|
@@ -264,7 +314,7 @@ export default class BaseChyz {
|
|
|
264
314
|
BaseChyz.debug(`Call Request id ${instance.id}`)
|
|
265
315
|
await instance.beforeAction(route, req, res)
|
|
266
316
|
next()
|
|
267
|
-
} catch (e) {
|
|
317
|
+
} catch (e: any) {
|
|
268
318
|
BaseChyz.error(e);
|
|
269
319
|
|
|
270
320
|
res.status(e.statusCode || 500)
|
|
@@ -288,8 +338,8 @@ export default class BaseChyz {
|
|
|
288
338
|
res.status(e.statusCode || 500)
|
|
289
339
|
// @ts-ignore
|
|
290
340
|
res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
|
|
291
|
-
}else{
|
|
292
|
-
res.json(e
|
|
341
|
+
} else {
|
|
342
|
+
res.json(e)
|
|
293
343
|
}
|
|
294
344
|
}
|
|
295
345
|
})
|
|
@@ -308,7 +358,6 @@ export default class BaseChyz {
|
|
|
308
358
|
BaseChyz.express.use(methodOverride());
|
|
309
359
|
|
|
310
360
|
|
|
311
|
-
|
|
312
361
|
// CORS
|
|
313
362
|
BaseChyz.express.use(function (req: any, res: Response, next: any) {
|
|
314
363
|
// @ts-ignore
|
|
@@ -352,10 +401,3 @@ export default class BaseChyz {
|
|
|
352
401
|
|
|
353
402
|
|
|
354
403
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
process.on('uncaughtException', err => {
|
|
358
|
-
BaseChyz.error('There was an uncaught error', err)
|
|
359
|
-
process.exit(1) //mandatory (as per the Node.js docs)
|
|
360
|
-
})
|
|
361
|
-
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {Controller} from "../../base";
|
|
10
|
+
import {Controller, ModelManager} from "../../base";
|
|
11
11
|
import BaseChyz from "../../BaseChyz";
|
|
12
12
|
// @ts-ignore
|
|
13
13
|
import {Request, Response} from "express";
|
|
@@ -18,10 +18,9 @@ import {JwtHttpBearerAuth} from "../../filters/auth";
|
|
|
18
18
|
|
|
19
19
|
import {ValidationHttpException} from "../../base";
|
|
20
20
|
import {ForbiddenHttpException} from "../../base";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
import {ProductModels} from "../Models/ProductModels";
|
|
21
|
+
import {ProductsClass} from "../Models/Products";
|
|
22
|
+
import {AccessControl} from "../../filters";
|
|
23
|
+
|
|
25
24
|
|
|
26
25
|
@controller("/api")
|
|
27
26
|
class ApiController extends Controller {
|
|
@@ -37,22 +36,18 @@ class ApiController extends Controller {
|
|
|
37
36
|
"class": JwtHttpBearerAuth,
|
|
38
37
|
// "auth": this.myCheck
|
|
39
38
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// 'roles': ['@'],
|
|
53
|
-
// }
|
|
54
|
-
// ]
|
|
55
|
-
// }
|
|
39
|
+
'access': {
|
|
40
|
+
'class': AccessControl,
|
|
41
|
+
'only': ['order/list' ],
|
|
42
|
+
'rules': [
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
'allow': true,
|
|
46
|
+
'actions': ['order/list' ],
|
|
47
|
+
'roles': ['edis-manager'],
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
56
51
|
}]
|
|
57
52
|
}
|
|
58
53
|
|
|
@@ -70,17 +65,15 @@ class ApiController extends Controller {
|
|
|
70
65
|
data.Customer["2fa"] = "true";
|
|
71
66
|
|
|
72
67
|
//Customer Model Create
|
|
73
|
-
let customer
|
|
68
|
+
let customer = ModelManager.Customer.save();
|
|
74
69
|
//Order Model Create
|
|
75
|
-
let order
|
|
70
|
+
let order = ModelManager.Order;
|
|
76
71
|
|
|
77
72
|
|
|
78
73
|
let transaction
|
|
79
74
|
try {
|
|
80
75
|
// get transaction
|
|
81
76
|
transaction = await BaseChyz.getComponent("db").transaction();
|
|
82
|
-
|
|
83
|
-
|
|
84
77
|
customer.load(data, "Customer");//load customer data
|
|
85
78
|
let cus: any = await customer.save({}, {transaction});
|
|
86
79
|
|
|
@@ -117,7 +110,23 @@ class ApiController extends Controller {
|
|
|
117
110
|
|
|
118
111
|
@get("order/list")
|
|
119
112
|
async listOrder(req: Request, res: Response) {
|
|
120
|
-
|
|
113
|
+
const {Products}: { Products: ProductsClass } = ModelManager;
|
|
114
|
+
let product = await Products.findAll( );
|
|
115
|
+
return res.json(product)
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@get("categories")
|
|
120
|
+
async Categories(req: Request, res: Response) {
|
|
121
|
+
let product = await ModelManager.Categories.findAll({
|
|
122
|
+
include: [
|
|
123
|
+
{
|
|
124
|
+
model: ModelManager.Products.model(),
|
|
125
|
+
// as: 'product',
|
|
126
|
+
// through: { attributes: [] } // Hide unwanted `PlayerGameTeam` nested object from results
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
});
|
|
121
130
|
return res.json(product)
|
|
122
131
|
|
|
123
132
|
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
|
|
4
|
+
* Author: Cihan Ozturk
|
|
5
|
+
* E-mail: cihan@chy.com.tr
|
|
6
|
+
* Github:https://github.com/cihan53/
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {Controller, ForbiddenHttpException, ModelManager, ValidationHttpException} from "../../base";
|
|
11
|
+
import BaseChyz from "../../BaseChyz";
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import {Request, Response} from "express";
|
|
14
|
+
import {controller, get, post} from "../../decorator";
|
|
15
|
+
import {ProductsClass} from "../Models/Products";
|
|
16
|
+
import {HttpBasicAuth} from "../../filters/auth/HttpBasicAuth";
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@controller("/basic/api")
|
|
20
|
+
class ApiController extends Controller {
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
public behaviors(): any[] {
|
|
25
|
+
|
|
26
|
+
return [{
|
|
27
|
+
'authenticator': {
|
|
28
|
+
"class": HttpBasicAuth,
|
|
29
|
+
// "auth": this.myCheck
|
|
30
|
+
}
|
|
31
|
+
}]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@get("/")
|
|
35
|
+
Index(req: Request, res: Response) {
|
|
36
|
+
|
|
37
|
+
BaseChyz.logs().info("Site Controller Burası", this.id)
|
|
38
|
+
return res.json({message: "index sayfası"})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@post("orderCreate")
|
|
42
|
+
async Login(req: Request, res: Response) {
|
|
43
|
+
let data = req.body;
|
|
44
|
+
data.Customer.status = "true";
|
|
45
|
+
data.Customer["2fa"] = "true";
|
|
46
|
+
|
|
47
|
+
//Customer Model Create
|
|
48
|
+
let customer = ModelManager.Customer.save();
|
|
49
|
+
//Order Model Create
|
|
50
|
+
let order = ModelManager.Order;
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
let transaction
|
|
54
|
+
try {
|
|
55
|
+
// get transaction
|
|
56
|
+
transaction = await BaseChyz.getComponent("db").transaction();
|
|
57
|
+
customer.load(data, "Customer");//load customer data
|
|
58
|
+
let cus: any = await customer.save({}, {transaction});
|
|
59
|
+
|
|
60
|
+
if (!cus) {
|
|
61
|
+
throw new ValidationHttpException(customer.errors);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
data.Order.customer_id = cus.id;
|
|
65
|
+
// data.Order.total = 0;
|
|
66
|
+
// data.Order.status = true;
|
|
67
|
+
order.load(data, "Order");
|
|
68
|
+
let res1 = await order.save({}, {transaction});
|
|
69
|
+
if (!res1) {
|
|
70
|
+
throw new ValidationHttpException(order.errors);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// commit
|
|
74
|
+
await transaction.commit();
|
|
75
|
+
|
|
76
|
+
} catch (e) {
|
|
77
|
+
if (transaction) {
|
|
78
|
+
await transaction.rollback();
|
|
79
|
+
BaseChyz.warn("Rollback transaction")
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (e instanceof ValidationHttpException)
|
|
83
|
+
throw new ValidationHttpException(e.message)
|
|
84
|
+
else
|
|
85
|
+
throw new ForbiddenHttpException(e.message)
|
|
86
|
+
}
|
|
87
|
+
return res.send("Post Controller")
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@get("order/list")
|
|
92
|
+
async listOrder(req: Request, res: Response) {
|
|
93
|
+
const {Products}: { Products: ProductsClass } = ModelManager;
|
|
94
|
+
let product = await Products.findAll({include: [ModelManager.ProductModels.model()]});
|
|
95
|
+
return res.json(product)
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@get("categories")
|
|
100
|
+
async Categories(req: Request, res: Response) {
|
|
101
|
+
let product = await ModelManager.Categories.findAll({
|
|
102
|
+
include: [
|
|
103
|
+
{
|
|
104
|
+
model: ModelManager.Products.model(),
|
|
105
|
+
// as: 'product',
|
|
106
|
+
// through: { attributes: [] } // Hide unwanted `PlayerGameTeam` nested object from results
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
return res.json(product)
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
error(req: Request, res: Response) {
|
|
116
|
+
BaseChyz.logs().info("Error Sayfası")
|
|
117
|
+
return res.send("Post Controller")
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
module.exports = ApiController
|
|
@@ -16,8 +16,8 @@ import {get,post,controller} from "../../decorator";
|
|
|
16
16
|
import {ValidationHttpException,ForbiddenHttpException} from "../../base";
|
|
17
17
|
import {KeyCloakHttpBearerAuth} from "../../filters/auth/KeyCloakHttpBearerAuth";
|
|
18
18
|
|
|
19
|
-
import {OrderClass
|
|
20
|
-
import {CustomerClass
|
|
19
|
+
import {OrderClass} from "../Models/Order";
|
|
20
|
+
import {CustomerClass} from "../Models/Customer";
|
|
21
21
|
|
|
22
22
|
@controller("/oauth2.0")
|
|
23
23
|
class ApiController extends Controller {
|
|
@@ -46,9 +46,9 @@ class ApiController extends Controller {
|
|
|
46
46
|
data.Customer["2fa"] = "true";
|
|
47
47
|
|
|
48
48
|
//Customer Model Create
|
|
49
|
-
let customer: CustomerClass =
|
|
49
|
+
let customer: CustomerClass = new CustomerClass();
|
|
50
50
|
//Order Model Create
|
|
51
|
-
let order: OrderClass =
|
|
51
|
+
let order: OrderClass = new OrderClass() ;
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
let transaction
|
|
@@ -26,11 +26,12 @@ class SiteController extends Controller {
|
|
|
26
26
|
public myCheck(token) {
|
|
27
27
|
console.log("myyyyyyyyyyyyyyyyyyyyy")
|
|
28
28
|
}
|
|
29
|
+
|
|
29
30
|
public behaviors(): any[] {
|
|
30
31
|
return [{
|
|
31
32
|
'authenticator': {
|
|
32
33
|
"class": JwtHttpBearerAuth,
|
|
33
|
-
"except":["index","login"]
|
|
34
|
+
"except": ["index", "login"]
|
|
34
35
|
// "auth": this.myCheck
|
|
35
36
|
}
|
|
36
37
|
}]
|
|
@@ -88,25 +89,33 @@ class SiteController extends Controller {
|
|
|
88
89
|
// @ts-ignore
|
|
89
90
|
let xForwardedFor = (req.headers['x-forwarded-for'] || '').replace(/:\d+$/, '');
|
|
90
91
|
let ip = xForwardedFor || req.socket.remoteAddress;
|
|
91
|
-
var source: string
|
|
92
|
+
var source: string = req.headers['user-agent'] || '';
|
|
92
93
|
if (req.headers['x-ucbrowser-ua']) { //special case of UC Browser
|
|
93
|
-
source = req.headers['x-ucbrowser-ua']+"";
|
|
94
|
+
source = req.headers['x-ucbrowser-ua'] + "";
|
|
94
95
|
}
|
|
95
96
|
token = await JsonWebToken.sign({
|
|
96
97
|
user: user.id,
|
|
97
98
|
ip: ip,
|
|
98
99
|
agent: source,
|
|
99
|
-
|
|
100
|
+
platform: "admin",
|
|
101
|
+
role: [
|
|
102
|
+
"admin"
|
|
103
|
+
],
|
|
104
|
+
permissions: [
|
|
105
|
+
"xxxx",
|
|
106
|
+
|
|
107
|
+
],
|
|
108
|
+
}, user.authkey, null);
|
|
100
109
|
|
|
101
|
-
BaseChyz.debug("Db user create access token", username,"expiresIn","1h")
|
|
110
|
+
BaseChyz.debug("Db user create access token", username, "expiresIn", "1h")
|
|
102
111
|
return res.json({token: token})
|
|
103
112
|
} else {
|
|
104
113
|
let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
|
|
105
|
-
res.status(500).json(
|
|
114
|
+
res.status(500).json(error.toJSON())
|
|
106
115
|
}
|
|
107
116
|
} else {
|
|
108
117
|
let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
|
|
109
|
-
res.status(500).json(
|
|
118
|
+
res.status(500).json(error.toJSON())
|
|
110
119
|
}
|
|
111
120
|
|
|
112
121
|
|
|
@@ -136,4 +145,5 @@ class SiteController extends Controller {
|
|
|
136
145
|
return res.send("Post Controller")
|
|
137
146
|
}
|
|
138
147
|
}
|
|
139
|
-
|
|
148
|
+
|
|
149
|
+
module.exports = SiteController
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
3
|
+
* Author: Cihan Ozturk
|
|
4
|
+
* E-mail: cihan@chy.com.tr
|
|
5
|
+
* Github:https://github.com/cihan53/
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {DataTypes, Model, ModelManager, Relation} from "../../base";
|
|
9
|
+
|
|
10
|
+
export class AuthAssignmentClass extends Model {
|
|
11
|
+
[x: string]: any;
|
|
12
|
+
|
|
13
|
+
tableName() {
|
|
14
|
+
return 'auth_assignment';
|
|
15
|
+
}
|
|
16
|
+
attributes() {
|
|
17
|
+
return {
|
|
18
|
+
|
|
19
|
+
// Model attributes are defined here
|
|
20
|
+
item_name: {
|
|
21
|
+
type: DataTypes.STRING,
|
|
22
|
+
primaryKey:true,
|
|
23
|
+
allowNull: false
|
|
24
|
+
},
|
|
25
|
+
user_id : {
|
|
26
|
+
type: DataTypes.STRING,
|
|
27
|
+
allowNull: false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
init(){
|
|
34
|
+
super.init();
|
|
35
|
+
this.model().removeAttribute('id')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
relations(): Relation[] {
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
type: "hasMany",
|
|
42
|
+
foreignKey: "name",
|
|
43
|
+
sourceKey:'item_name',
|
|
44
|
+
model: ModelManager.AuthItem.model()
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
3
|
+
* Author: Cihan Ozturk
|
|
4
|
+
* E-mail: cihan@chy.com.tr
|
|
5
|
+
* Github:https://github.com/cihan53/
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
import {DataTypes, Model, ModelManager, Relation} from "../../base";
|
|
11
|
+
|
|
12
|
+
export class AuthItemClass extends Model {
|
|
13
|
+
[x: string]: any;
|
|
14
|
+
|
|
15
|
+
tableName() {
|
|
16
|
+
return 'auth_item';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
attributes() {
|
|
20
|
+
return {
|
|
21
|
+
// Model attributes are defined here
|
|
22
|
+
name: {
|
|
23
|
+
type: DataTypes.STRING,
|
|
24
|
+
primaryKey:true,
|
|
25
|
+
allowNull: false
|
|
26
|
+
},
|
|
27
|
+
type: {
|
|
28
|
+
type: DataTypes.INTEGER,
|
|
29
|
+
allowNull: false
|
|
30
|
+
},
|
|
31
|
+
description: {
|
|
32
|
+
type: DataTypes.STRING,
|
|
33
|
+
allowNull: false
|
|
34
|
+
},
|
|
35
|
+
rule_name: {
|
|
36
|
+
type: DataTypes.STRING,
|
|
37
|
+
allowNull: false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
init() {
|
|
44
|
+
super.init();
|
|
45
|
+
this.model().removeAttribute('id')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
relations(): Relation[] {
|
|
49
|
+
return [
|
|
50
|
+
{
|
|
51
|
+
type: "hasOne",
|
|
52
|
+
foreignKey: "item_name",
|
|
53
|
+
model: ModelManager.AuthAssignment.model()
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
3
|
+
* Author: Cihan Ozturk
|
|
4
|
+
* E-mail: cihan@chy.com.tr
|
|
5
|
+
* Github:https://github.com/cihan53/
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import {DataTypes, Model, ModelManager, Relation} from "../../base";
|
|
10
|
+
|
|
11
|
+
export class AuthItemChildClass extends Model {
|
|
12
|
+
[x: string]: any;
|
|
13
|
+
|
|
14
|
+
tableName() {
|
|
15
|
+
return 'auth_item_child';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
attributes() {
|
|
19
|
+
return {
|
|
20
|
+
// Model attributes are defined here
|
|
21
|
+
parent: {
|
|
22
|
+
type: DataTypes.STRING,
|
|
23
|
+
primaryKey: true,
|
|
24
|
+
allowNull: false
|
|
25
|
+
},
|
|
26
|
+
child: {
|
|
27
|
+
type: DataTypes.STRING,
|
|
28
|
+
allowNull: false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
init() {
|
|
34
|
+
super.init();
|
|
35
|
+
this.model().removeAttribute('id')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
relations(): Relation[] {
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
type: "hasOne",
|
|
42
|
+
foreignKey: "item_name",
|
|
43
|
+
model: ModelManager.AuthAssignment.model()
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* E-mail: cihan@chy.com.tr
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
|
-
import {DataTypes, Model} from "../../base";
|
|
7
|
+
import {DataTypes, Model, ModelManager, Relation} from "../../base";
|
|
8
8
|
|
|
9
9
|
export class CategoriesClass extends Model {
|
|
10
10
|
[x: string]: any;
|
|
@@ -29,8 +29,19 @@ export class CategoriesClass extends Model {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
relations(): Relation[] {
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
type: "belongsToMany",
|
|
36
|
+
foreignKey: "category_id",
|
|
37
|
+
sourceKey: "id",
|
|
38
|
+
model: ModelManager.Products.model(),
|
|
39
|
+
through: ModelManager.ProductToCategories.model()
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
32
43
|
|
|
33
44
|
}
|
|
34
45
|
|
|
35
|
-
const Categories = new CategoriesClass();
|
|
36
|
-
export {Categories};
|
|
46
|
+
// const Categories = new CategoriesClass();
|
|
47
|
+
// export {Categories};
|