chyz 1.0.12-rc.9 → 1.0.13-rc.1
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 +52 -10
- package/Examples/Controllers/ApiController.ts +41 -31
- package/Examples/Controllers/KeyCloakController.ts +100 -0
- package/Examples/Controllers/PublicController.ts +5 -7
- package/Examples/Controllers/SiteController.ts +18 -6
- package/Examples/Models/Categories.ts +36 -0
- package/Examples/Models/Customer.ts +10 -8
- package/Examples/Models/KeycloakUser.ts +66 -0
- package/Examples/Models/Order.ts +33 -17
- package/Examples/Models/OrderItem.ts +4 -3
- package/Examples/Models/ProductModels.ts +50 -0
- package/Examples/Models/ProductToCategories.ts +35 -0
- package/Examples/Models/Products.ts +49 -0
- package/Examples/Models/Stocks.ts +60 -0
- package/Examples/Models/User.ts +26 -6
- package/Examples/Models/UserPermission.ts +37 -0
- package/Examples/index-keycloack.ts +78 -0
- package/Examples/index.ts +16 -15
- package/Examples/keycloak.json +7 -0
- package/Examples/log/access.log +0 -0
- package/Examples/log/app.log +871 -0
- package/Examples/log/errors.log +80 -0
- package/Examples/package.json +46 -45
- package/Examples/yarn.lock +354 -7
- package/README.md +77 -22
- package/base/ActionFilter.ts +2 -2
- package/base/BaseError.ts +2 -2
- package/base/DataErrorDbException.ts +1 -1
- package/base/ForbiddenHttpException.ts +1 -1
- package/base/InvalidConfigException.ts +1 -1
- package/base/Model.ts +155 -10
- package/base/NotFoundHttpException.ts +1 -1
- package/base/RestClient.ts +28 -0
- package/base/UnauthorizedHttpException.ts +2 -1
- package/base/ValidationHttpException.ts +1 -1
- package/base/index.ts +2 -0
- package/dist/BaseChyz.js +37 -6
- package/dist/BaseChyz.js.map +1 -1
- package/dist/base/ActionFilter.js +2 -2
- package/dist/base/ActionFilter.js.map +1 -1
- package/dist/base/BaseError.js +2 -2
- package/dist/base/BaseError.js.map +1 -1
- package/dist/base/DataErrorDbException.js +1 -1
- package/dist/base/DataErrorDbException.js.map +1 -1
- package/dist/base/ForbiddenHttpException.js +1 -1
- package/dist/base/ForbiddenHttpException.js.map +1 -1
- package/dist/base/InvalidConfigException.js +1 -1
- package/dist/base/InvalidConfigException.js.map +1 -1
- package/dist/base/Model.js +121 -3
- package/dist/base/Model.js.map +1 -1
- package/dist/base/NotFoundHttpException.js +1 -1
- package/dist/base/NotFoundHttpException.js.map +1 -1
- package/dist/base/RestClient.js +27 -0
- package/dist/base/RestClient.js.map +1 -0
- package/dist/base/UnauthorizedHttpException.js +1 -1
- package/dist/base/UnauthorizedHttpException.js.map +1 -1
- package/dist/base/ValidationHttpException.js +1 -1
- package/dist/base/ValidationHttpException.js.map +1 -1
- package/dist/base/index.js +2 -0
- package/dist/base/index.js.map +1 -1
- package/dist/filters/AccessControl.js +2 -2
- package/dist/filters/AccessControl.js.map +1 -1
- package/dist/filters/AccessRule.js.map +1 -1
- package/dist/filters/auth/AuthMethod.js +2 -2
- package/dist/filters/auth/AuthMethod.js.map +1 -1
- package/dist/filters/auth/HttpHeaderAuth.js.map +1 -1
- package/dist/filters/auth/JwtHttpBearerAuth.js +1 -0
- package/dist/filters/auth/JwtHttpBearerAuth.js.map +1 -1
- package/dist/filters/auth/KeyCloakHttpBearerAuth.js +117 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.js.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/log/config/log4js.json +55 -0
- package/dist/web/{User.js → WebUser.js} +12 -7
- package/dist/web/WebUser.js.map +1 -0
- package/filters/AccessControl.ts +3 -3
- package/filters/AccessRule.ts +2 -2
- package/filters/auth/AuthMethod.ts +4 -4
- package/filters/auth/HttpHeaderAuth.ts +2 -2
- package/filters/auth/JwtHttpBearerAuth.ts +4 -5
- package/filters/auth/KeyCloakHttpBearerAuth.ts +115 -0
- package/index.ts +14 -0
- package/log/config/log4js.json +55 -0
- package/package.json +55 -52
- package/web/{User.ts → WebUser.ts} +10 -6
- package/dist/web/User.js.map +0 -1
package/BaseChyz.ts
CHANGED
|
@@ -8,8 +8,8 @@ import Utils from "./requiments/Utils";
|
|
|
8
8
|
const express = require("express");
|
|
9
9
|
const log4js = require("log4js");
|
|
10
10
|
const fs = require('fs');
|
|
11
|
-
const _ = require('lodash');
|
|
12
11
|
|
|
12
|
+
var ip = require('ip');
|
|
13
13
|
var bodyParser = require('body-parser')
|
|
14
14
|
var methodOverride = require('method-override')
|
|
15
15
|
|
|
@@ -25,6 +25,8 @@ export default class BaseChyz {
|
|
|
25
25
|
private _controllerpath: string = "Controllers"
|
|
26
26
|
private static controllers: Array<Controller> = []
|
|
27
27
|
public static components: any = {}
|
|
28
|
+
public static middlewares: any = {}
|
|
29
|
+
|
|
28
30
|
|
|
29
31
|
get logConfig(): any {
|
|
30
32
|
return this._logConfig;
|
|
@@ -61,7 +63,6 @@ export default class BaseChyz {
|
|
|
61
63
|
writable: true
|
|
62
64
|
})
|
|
63
65
|
|
|
64
|
-
|
|
65
66
|
Object.defineProperty(BaseChyz.express.request, 'identity', {
|
|
66
67
|
configurable: true,
|
|
67
68
|
enumerable: true,
|
|
@@ -120,7 +121,6 @@ export default class BaseChyz {
|
|
|
120
121
|
*/
|
|
121
122
|
this.config = config;
|
|
122
123
|
|
|
123
|
-
this.init();
|
|
124
124
|
|
|
125
125
|
let components = Utils.findKeyValue(config, "components")
|
|
126
126
|
if (components) {
|
|
@@ -132,6 +132,21 @@ export default class BaseChyz {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
|
|
136
|
+
let middlewares = Utils.findKeyValue(config, "middlewares")
|
|
137
|
+
if (middlewares) {
|
|
138
|
+
for (const middlewareKey in middlewares) {
|
|
139
|
+
let middleware1 = middlewares[middlewareKey];
|
|
140
|
+
BaseChyz.debug("Create middlewares ", middlewareKey)
|
|
141
|
+
BaseChyz.middlewares[middlewareKey] = middleware1;
|
|
142
|
+
// BaseChyz.middlewares[middlewareKey] = Utils.createObject(new middleware1.class, middleware1);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
this.init();
|
|
149
|
+
|
|
135
150
|
return this;
|
|
136
151
|
}
|
|
137
152
|
|
|
@@ -140,7 +155,7 @@ export default class BaseChyz {
|
|
|
140
155
|
return log4js;
|
|
141
156
|
}
|
|
142
157
|
|
|
143
|
-
public getLogger(){
|
|
158
|
+
public getLogger() {
|
|
144
159
|
return this.logProvider().getLogger(this.constructor.name);
|
|
145
160
|
}
|
|
146
161
|
|
|
@@ -151,12 +166,15 @@ export default class BaseChyz {
|
|
|
151
166
|
public static trace(...args: any[]) {
|
|
152
167
|
BaseChyz.logs().fatal(...arguments)
|
|
153
168
|
}
|
|
169
|
+
|
|
154
170
|
public static debug(...args: any[]) {
|
|
155
171
|
BaseChyz.logs().debug(...arguments)
|
|
156
172
|
}
|
|
173
|
+
|
|
157
174
|
public static info(...args: any[]) {
|
|
158
175
|
BaseChyz.logs().info(...arguments)
|
|
159
176
|
}
|
|
177
|
+
|
|
160
178
|
public static warn(...args: any[]) {
|
|
161
179
|
BaseChyz.logs().warn(...arguments)
|
|
162
180
|
}
|
|
@@ -170,8 +188,6 @@ export default class BaseChyz {
|
|
|
170
188
|
}
|
|
171
189
|
|
|
172
190
|
|
|
173
|
-
|
|
174
|
-
|
|
175
191
|
public static warning(...args: any[]) {
|
|
176
192
|
BaseChyz.logs().warn(...arguments)
|
|
177
193
|
}
|
|
@@ -208,6 +224,12 @@ export default class BaseChyz {
|
|
|
208
224
|
return BaseChyz.components[key] ?? null
|
|
209
225
|
}
|
|
210
226
|
|
|
227
|
+
|
|
228
|
+
public static getMiddlewares(key: any) {
|
|
229
|
+
return BaseChyz.middlewares[key] ?? null
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
|
|
211
233
|
/**
|
|
212
234
|
* load contoller
|
|
213
235
|
*/
|
|
@@ -261,8 +283,8 @@ export default class BaseChyz {
|
|
|
261
283
|
} catch (e) {
|
|
262
284
|
BaseChyz.error(e)
|
|
263
285
|
// next(e)
|
|
264
|
-
res.status(e.statusCode)
|
|
265
|
-
res.json({error: {code: e.statusCode, name: e.name, message: e.message}})
|
|
286
|
+
res.status(e.statusCode || 500)
|
|
287
|
+
res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
|
|
266
288
|
}
|
|
267
289
|
})
|
|
268
290
|
|
|
@@ -277,8 +299,8 @@ export default class BaseChyz {
|
|
|
277
299
|
BaseChyz.express.use(bodyParser.json())
|
|
278
300
|
BaseChyz.express.use(bodyParser.urlencoded({extended: true})); // support encoded bodies
|
|
279
301
|
BaseChyz.express.use(methodOverride());
|
|
280
|
-
BaseChyz.express.use(
|
|
281
|
-
|
|
302
|
+
BaseChyz.express.use(methodOverride());
|
|
303
|
+
|
|
282
304
|
|
|
283
305
|
|
|
284
306
|
// CORS
|
|
@@ -293,7 +315,20 @@ export default class BaseChyz {
|
|
|
293
315
|
next();
|
|
294
316
|
});
|
|
295
317
|
|
|
318
|
+
//Middlewares
|
|
319
|
+
for (const middleware1 of Object.keys(BaseChyz.middlewares)) {
|
|
320
|
+
if (!Utils.isFunction(middleware1)) {
|
|
321
|
+
let keycloak = BaseChyz.middlewares[middleware1].keycloak;
|
|
322
|
+
BaseChyz.express.use(keycloak.middleware(BaseChyz.middlewares[middleware1].config));
|
|
323
|
+
} else {
|
|
324
|
+
BaseChyz.express.use(BaseChyz.middlewares[middleware1]);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
}
|
|
328
|
+
|
|
296
329
|
|
|
330
|
+
BaseChyz.express.use(this.errorResponder)
|
|
331
|
+
BaseChyz.express.use(this.errorHandler)
|
|
297
332
|
}
|
|
298
333
|
|
|
299
334
|
|
|
@@ -303,6 +338,8 @@ export default class BaseChyz {
|
|
|
303
338
|
BaseChyz.express.listen(this._port, () => {
|
|
304
339
|
BaseChyz.info("Express Server Start ")
|
|
305
340
|
BaseChyz.info(`Liten Port ${this._port}`)
|
|
341
|
+
BaseChyz.info(`http://localhost:${this._port}`)
|
|
342
|
+
BaseChyz.info(`http://${ip.address()}:${this._port}`)
|
|
306
343
|
})
|
|
307
344
|
return this;
|
|
308
345
|
}
|
|
@@ -311,3 +348,8 @@ export default class BaseChyz {
|
|
|
311
348
|
}
|
|
312
349
|
|
|
313
350
|
|
|
351
|
+
process.on('uncaughtException', err => {
|
|
352
|
+
BaseChyz.error('There was an uncaught error', err)
|
|
353
|
+
process.exit(1) //mandatory (as per the Node.js docs)
|
|
354
|
+
})
|
|
355
|
+
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
|
|
3
4
|
* Author: Cihan Ozturk
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* E-mail: cihan@chy.com.tr
|
|
6
|
+
* Github:https://github.com/cihan53/
|
|
7
|
+
*
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
|
-
import {Controller} from "../../base
|
|
10
|
+
import {Controller} from "../../base";
|
|
9
11
|
import BaseChyz from "../../BaseChyz";
|
|
10
12
|
// @ts-ignore
|
|
11
13
|
import {Request, Response} from "express";
|
|
12
|
-
import {get} from "../../decorator
|
|
13
|
-
import {post} from "../../decorator
|
|
14
|
-
import {controller} from "../../decorator
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
import {Customer} from "../Models/Customer";
|
|
19
|
-
import {ValidationHttpException} from "../../base/ValidationHttpException";
|
|
20
|
-
import {ValidationError} from "sequelize";
|
|
14
|
+
import {get} from "../../decorator";
|
|
15
|
+
import {post} from "../../decorator";
|
|
16
|
+
import {controller} from "../../decorator";
|
|
17
|
+
import {JwtHttpBearerAuth} from "../../filters/auth";
|
|
18
|
+
|
|
19
|
+
import {ValidationHttpException} from "../../base";
|
|
21
20
|
import {ForbiddenHttpException} from "../../base";
|
|
21
|
+
import {OrderClass, Order} from "../Models/Order";
|
|
22
|
+
import {CustomerClass, Customer} from "../Models/Customer";
|
|
23
|
+
import {Products} from "../Models/Products";
|
|
24
|
+
import {ProductModels} from "../Models/ProductModels";
|
|
22
25
|
|
|
23
26
|
@controller("/api")
|
|
24
27
|
class ApiController extends Controller {
|
|
@@ -34,22 +37,22 @@ class ApiController extends Controller {
|
|
|
34
37
|
"class": JwtHttpBearerAuth,
|
|
35
38
|
// "auth": this.myCheck
|
|
36
39
|
},
|
|
37
|
-
'access': {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
40
|
+
// 'access': {
|
|
41
|
+
// 'class': AccessControl,
|
|
42
|
+
// 'only': ['login', 'logout', 'signup'],
|
|
43
|
+
// 'rules': [
|
|
44
|
+
// {
|
|
45
|
+
// 'allow': true,
|
|
46
|
+
// 'actions': ['login', 'index'],
|
|
47
|
+
// 'roles': ['?'],
|
|
48
|
+
// },
|
|
49
|
+
// {
|
|
50
|
+
// 'allow': true,
|
|
51
|
+
// 'actions': ['logout', "logout2"],
|
|
52
|
+
// 'roles': ['@'],
|
|
53
|
+
// }
|
|
54
|
+
// ]
|
|
55
|
+
// }
|
|
53
56
|
}]
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -67,9 +70,9 @@ class ApiController extends Controller {
|
|
|
67
70
|
data.Customer["2fa"] = "true";
|
|
68
71
|
|
|
69
72
|
//Customer Model Create
|
|
70
|
-
let customer:
|
|
73
|
+
let customer: CustomerClass = Customer;
|
|
71
74
|
//Order Model Create
|
|
72
|
-
let order:
|
|
75
|
+
let order: OrderClass = Order;
|
|
73
76
|
|
|
74
77
|
|
|
75
78
|
let transaction
|
|
@@ -112,6 +115,13 @@ class ApiController extends Controller {
|
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
|
|
118
|
+
@get("order/list")
|
|
119
|
+
async listOrder(req: Request, res: Response) {
|
|
120
|
+
let product = await Products.findAll({include: [ProductModels.model()]});
|
|
121
|
+
return res.json(product)
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
115
125
|
error(req: Request, res: Response) {
|
|
116
126
|
BaseChyz.logs().info("Error Sayfası")
|
|
117
127
|
return res.send("Post Controller")
|
|
@@ -0,0 +1,100 @@
|
|
|
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} from "../../base/Controller";
|
|
11
|
+
import BaseChyz from "../../BaseChyz";
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import {Request, Response} from "express";
|
|
14
|
+
import {get,post,controller} from "../../decorator";
|
|
15
|
+
|
|
16
|
+
import {ValidationHttpException,ForbiddenHttpException} from "../../base";
|
|
17
|
+
import {KeyCloakHttpBearerAuth} from "../../filters/auth/KeyCloakHttpBearerAuth";
|
|
18
|
+
|
|
19
|
+
import {OrderClass, Order} from "../Models/Order";
|
|
20
|
+
import {CustomerClass, Customer} from "../Models/Customer";
|
|
21
|
+
|
|
22
|
+
@controller("/oauth2.0")
|
|
23
|
+
class ApiController extends Controller {
|
|
24
|
+
|
|
25
|
+
public behaviors(): any[] {
|
|
26
|
+
|
|
27
|
+
return [{
|
|
28
|
+
'authenticator': {
|
|
29
|
+
"class": KeyCloakHttpBearerAuth,
|
|
30
|
+
// "auth": this.myCheck
|
|
31
|
+
}
|
|
32
|
+
}]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@get("/")
|
|
36
|
+
Index(req: Request, res: Response) {
|
|
37
|
+
|
|
38
|
+
BaseChyz.logs().info("Site Controller Burası", this.id)
|
|
39
|
+
return res.json({message: "index sayfası"})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@post("orderCreate")
|
|
43
|
+
async Login(req: Request, res: Response) {
|
|
44
|
+
let data = req.body;
|
|
45
|
+
data.Customer.status = "true";
|
|
46
|
+
data.Customer["2fa"] = "true";
|
|
47
|
+
|
|
48
|
+
//Customer Model Create
|
|
49
|
+
let customer: CustomerClass = Customer;
|
|
50
|
+
//Order Model Create
|
|
51
|
+
let order: OrderClass = Order ;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
let transaction
|
|
55
|
+
try {
|
|
56
|
+
// get transaction
|
|
57
|
+
transaction = await BaseChyz.getComponent("db").transaction();
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
customer.load(data, "Customer");//load customer data
|
|
61
|
+
let cus: any = await customer.save({}, {transaction});
|
|
62
|
+
|
|
63
|
+
if (!cus) {
|
|
64
|
+
throw new ValidationHttpException(customer.errors);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
data.Order.customer_id = cus.id;
|
|
68
|
+
// data.Order.total = 0;
|
|
69
|
+
// data.Order.status = true;
|
|
70
|
+
order.load(data, "Order");
|
|
71
|
+
let res1 = await order.save({}, {transaction});
|
|
72
|
+
if (!res1) {
|
|
73
|
+
throw new ValidationHttpException(order.errors);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// commit
|
|
77
|
+
await transaction.commit();
|
|
78
|
+
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (transaction) {
|
|
81
|
+
await transaction.rollback();
|
|
82
|
+
BaseChyz.warn("Rollback transaction")
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (e instanceof ValidationHttpException)
|
|
86
|
+
throw new ValidationHttpException(e.message)
|
|
87
|
+
else
|
|
88
|
+
throw new ForbiddenHttpException(e.message)
|
|
89
|
+
}
|
|
90
|
+
return res.send("Post Controller")
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
error(req: Request, res: Response) {
|
|
95
|
+
BaseChyz.logs().info("Error Sayfası")
|
|
96
|
+
return res.send("Post Controller")
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = ApiController
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) 2021-2021.. Chy Bilgisayar Bilisim
|
|
3
4
|
* Author: Cihan Ozturk
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* E-mail: cihan@chy.com.tr
|
|
6
|
+
* Github:https://github.com/cihan53/
|
|
7
|
+
*
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
import {Controller} from "../../base/Controller";
|
|
@@ -10,11 +12,7 @@ import BaseChyz from "../../BaseChyz";
|
|
|
10
12
|
// @ts-ignore
|
|
11
13
|
import {Request, Response} from "express";
|
|
12
14
|
import {get} from "../../decorator/get";
|
|
13
|
-
import {post} from "../../decorator/post";
|
|
14
15
|
import {controller} from "../../decorator/controller";
|
|
15
|
-
import {AccessControl} from "../../filters/AccessControl";
|
|
16
|
-
import {JwtHttpBearerAuth} from "../../filters/auth/JwtHttpBearerAuth";
|
|
17
|
-
import Utils from "../../requiments/Utils";
|
|
18
16
|
|
|
19
17
|
@controller("/public")
|
|
20
18
|
class PublicController extends Controller {
|
|
@@ -5,15 +5,16 @@
|
|
|
5
5
|
* Github:https://github.com/cihan53/
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {Controller} from "../../base
|
|
8
|
+
import {Controller} from "../../base";
|
|
9
9
|
import BaseChyz from "../../BaseChyz";
|
|
10
10
|
// @ts-ignore
|
|
11
11
|
import {Request, Response} from "express";
|
|
12
|
-
import {get} from "../../decorator
|
|
13
|
-
import {post} from "../../decorator
|
|
14
|
-
import {controller} from "../../decorator
|
|
12
|
+
import {get} from "../../decorator";
|
|
13
|
+
import {post} from "../../decorator";
|
|
14
|
+
import {controller} from "../../decorator";
|
|
15
15
|
import {User} from "../Models/User";
|
|
16
16
|
import {ForbiddenHttpException} from "../../base";
|
|
17
|
+
import {JwtHttpBearerAuth} from "../../filters/auth";
|
|
17
18
|
|
|
18
19
|
const bcrypt = require('bcrypt');
|
|
19
20
|
const JsonWebToken = require("jsonwebtoken");
|
|
@@ -25,6 +26,16 @@ class SiteController extends Controller {
|
|
|
25
26
|
public myCheck(token) {
|
|
26
27
|
console.log("myyyyyyyyyyyyyyyyyyyyy")
|
|
27
28
|
}
|
|
29
|
+
public behaviors(): any[] {
|
|
30
|
+
return [{
|
|
31
|
+
'authenticator': {
|
|
32
|
+
"class": JwtHttpBearerAuth,
|
|
33
|
+
"except":["index","login"]
|
|
34
|
+
// "auth": this.myCheck
|
|
35
|
+
}
|
|
36
|
+
}]
|
|
37
|
+
}
|
|
38
|
+
|
|
28
39
|
|
|
29
40
|
// public behaviors(): any[] {
|
|
30
41
|
//
|
|
@@ -66,6 +77,7 @@ class SiteController extends Controller {
|
|
|
66
77
|
let username = req.body.username;
|
|
67
78
|
let password = req.body.password;
|
|
68
79
|
|
|
80
|
+
|
|
69
81
|
let user = await UserModel.findOne({where: {username: username}})
|
|
70
82
|
if (user) {
|
|
71
83
|
BaseChyz.debug("Db found user", username)
|
|
@@ -84,7 +96,7 @@ class SiteController extends Controller {
|
|
|
84
96
|
user: user.id,
|
|
85
97
|
ip: ip,
|
|
86
98
|
agent: source,
|
|
87
|
-
}, user.
|
|
99
|
+
}, user.authkey, {expiresIn: '1h'});
|
|
88
100
|
|
|
89
101
|
BaseChyz.debug("Db user create access token", username,"expiresIn","1h")
|
|
90
102
|
return res.json({token: token})
|
|
@@ -106,7 +118,7 @@ class SiteController extends Controller {
|
|
|
106
118
|
// @ts-ignore
|
|
107
119
|
let identity = req.user ?? BaseChyz.getComponent("user").getIdentity();
|
|
108
120
|
// console.log("logout2", identity.id)
|
|
109
|
-
console.log(identity)
|
|
121
|
+
//console.log(identity)
|
|
110
122
|
|
|
111
123
|
BaseChyz.logs().info("Logout Controller")
|
|
112
124
|
return res.send("Logout Controller")
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
import {DataTypes, Model} from "../../base";
|
|
8
|
+
|
|
9
|
+
export class CategoriesClass extends Model {
|
|
10
|
+
[x: string]: any;
|
|
11
|
+
|
|
12
|
+
tableName() {
|
|
13
|
+
return 'categories';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
attributes() {
|
|
18
|
+
return {
|
|
19
|
+
// Model attributes are defined here
|
|
20
|
+
title: {
|
|
21
|
+
type: DataTypes.STRING,
|
|
22
|
+
allowNull: false
|
|
23
|
+
},
|
|
24
|
+
properties: {
|
|
25
|
+
type: DataTypes.STRING,
|
|
26
|
+
allowNull: false
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const Categories = new CategoriesClass();
|
|
36
|
+
export {Categories};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import {DataTypes, Model} from "../../base";
|
|
3
3
|
|
|
4
|
-
export class
|
|
4
|
+
export class CustomerClass extends Model {
|
|
5
5
|
[x: string]: any;
|
|
6
6
|
|
|
7
7
|
public tableName() {
|
|
@@ -15,21 +15,21 @@ export class Customer extends Model {
|
|
|
15
15
|
allowNull: false,
|
|
16
16
|
validate: {
|
|
17
17
|
notEmpty: true,
|
|
18
|
-
is: ["^[a-z0-9A-Z]+$",'i'],
|
|
18
|
+
is: ["^[a-z0-9A-Z]+$", 'i'],
|
|
19
19
|
len: [4, 255],
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
firstname: {
|
|
23
23
|
type: DataTypes.STRING,
|
|
24
24
|
validate: {
|
|
25
|
-
is: ["^[a-z0-9A-Z]+$",'i'],
|
|
25
|
+
is: ["^[a-z0-9A-Z]+$", 'i'],
|
|
26
26
|
len: [4, 255],
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
lastname: {
|
|
30
30
|
type: DataTypes.STRING,
|
|
31
31
|
validate: {
|
|
32
|
-
is: ["^[a-z0-9A-Z]+$",'i'],
|
|
32
|
+
is: ["^[a-z0-9A-Z]+$", 'i'],
|
|
33
33
|
len: [4, 255],
|
|
34
34
|
}
|
|
35
35
|
},
|
|
@@ -50,7 +50,7 @@ export class Customer extends Model {
|
|
|
50
50
|
gsm_phone: {
|
|
51
51
|
type: DataTypes.STRING,
|
|
52
52
|
validate: {
|
|
53
|
-
is: ["^[0-9 +]+$",'i'],
|
|
53
|
+
is: ["^[0-9 +]+$", 'i'],
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
country: {
|
|
@@ -62,20 +62,20 @@ export class Customer extends Model {
|
|
|
62
62
|
address: {
|
|
63
63
|
type: DataTypes.STRING,
|
|
64
64
|
validate: {
|
|
65
|
-
is: ["^[\\w'\\-,.[0-9_\\/\\\\+=\"()<>;:\\[\\] şŞçÇöÖğĞıİüÜ ]{2,}$","i"],
|
|
65
|
+
is: ["^[\\w'\\-,.[0-9_\\/\\\\+=\"()<>;:\\[\\] şŞçÇöÖğĞıİüÜ ]{2,}$", "i"],
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
taxoffice: {
|
|
69
69
|
type: DataTypes.STRING,
|
|
70
70
|
validate: {
|
|
71
|
-
is: ["^[\\w'\\-,.[0-9_\\/\\\\+=\"()<>;:\\[\\] şŞçÇöÖğĞıİüÜ ]{2,}$","i"],
|
|
71
|
+
is: ["^[\\w'\\-,.[0-9_\\/\\\\+=\"()<>;:\\[\\] şŞçÇöÖğĞıİüÜ ]{2,}$", "i"],
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
taxnumber: {
|
|
75
75
|
unique: true,
|
|
76
76
|
type: DataTypes.STRING,
|
|
77
77
|
validate: {
|
|
78
|
-
is:["^[0-9]+$",'i'],
|
|
78
|
+
is: ["^[0-9]+$", 'i'],
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
username: {
|
|
@@ -108,6 +108,8 @@ export class Customer extends Model {
|
|
|
108
108
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
const Customer = new CustomerClass();
|
|
112
|
+
export {Customer};
|
|
111
113
|
|
|
112
114
|
|
|
113
115
|
|
|
@@ -0,0 +1,66 @@
|
|
|
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 {IdentityInterface} from "../../web/IdentityInterface";
|
|
9
|
+
import {DataTypes, Model} from "../../base";
|
|
10
|
+
import BaseChyz from "../../BaseChyz";
|
|
11
|
+
|
|
12
|
+
const JsonWebToken = require("jsonwebtoken");
|
|
13
|
+
|
|
14
|
+
export class KeycloakUser implements IdentityInterface {
|
|
15
|
+
|
|
16
|
+
[x: string]: any;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
findIdentity(id: number) {
|
|
20
|
+
throw new Error("Method not implemented.");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getId(): number {
|
|
24
|
+
throw new Error("Method not implemented.");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getAuthKey(): string {
|
|
28
|
+
throw new Error("Method not implemented.");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
validateAuthKey(authKey: string): boolean {
|
|
32
|
+
throw new Error("Method not implemented.");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public attributes() {
|
|
36
|
+
return {
|
|
37
|
+
// Model attributes are defined here
|
|
38
|
+
username: {
|
|
39
|
+
type: DataTypes.STRING,
|
|
40
|
+
allowNull: false
|
|
41
|
+
},
|
|
42
|
+
password: {
|
|
43
|
+
type: DataTypes.STRING,
|
|
44
|
+
allowNull: false
|
|
45
|
+
},
|
|
46
|
+
user_role: {
|
|
47
|
+
type: DataTypes.STRING,
|
|
48
|
+
allowNull: false
|
|
49
|
+
},
|
|
50
|
+
salt_text: {
|
|
51
|
+
type: DataTypes.STRING
|
|
52
|
+
// allowNull defaults to true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async findIdentityByAccessToken(token, type) {
|
|
58
|
+
console.log(token,type)
|
|
59
|
+
// console.log(this)
|
|
60
|
+
// console.log(BaseChyz)
|
|
61
|
+
return null;
|
|
62
|
+
// return keycloak.protect('realm:user');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|