chyz 1.0.12-rc.9 → 1.0.13-rc.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.
Files changed (167) hide show
  1. package/{dist/BaseChyz.js → BaseChyz.js} +45 -8
  2. package/BaseChyz.js.map +1 -0
  3. package/{dist/Chyz.js → Chyz.js} +0 -0
  4. package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
  5. package/README.md +80 -28
  6. package/{dist/base → base}/ActionFilter.js +2 -2
  7. package/base/ActionFilter.js.map +1 -0
  8. package/{dist/base → base}/BaseError.js +2 -2
  9. package/base/BaseError.js.map +1 -0
  10. package/{dist/base → base}/BaseObject.js +0 -0
  11. package/{dist/base → base}/BaseObject.js.map +0 -0
  12. package/{dist/base → base}/Behavior.js +0 -0
  13. package/{dist/base → base}/Behavior.js.map +0 -0
  14. package/{dist/base → base}/Component.js +0 -0
  15. package/{dist/base → base}/Component.js.map +0 -0
  16. package/{dist/base → base}/Configurable.js +0 -0
  17. package/{dist/base → base}/Configurable.js.map +0 -0
  18. package/{dist/base → base}/Controller.js +0 -0
  19. package/{dist/base → base}/Controller.js.map +0 -0
  20. package/{dist/base → base}/DataErrorDbException.js +1 -1
  21. package/{dist/base → base}/DataErrorDbException.js.map +1 -1
  22. package/{dist/base → base}/DbConnection.js +0 -0
  23. package/{dist/base → base}/DbConnection.js.map +0 -0
  24. package/{dist/base → base}/ForbiddenHttpException.js +1 -1
  25. package/{dist/base → base}/ForbiddenHttpException.js.map +1 -1
  26. package/{dist/base → base}/InvalidConfigException.js +1 -1
  27. package/{dist/base → base}/InvalidConfigException.js.map +1 -1
  28. package/{dist/base → base}/Model.js +121 -3
  29. package/base/Model.js.map +1 -0
  30. package/{dist/base → base}/NotFoundHttpException.js +1 -1
  31. package/{dist/base → base}/NotFoundHttpException.js.map +1 -1
  32. package/base/RestClient.js +27 -0
  33. package/base/RestClient.js.map +1 -0
  34. package/{dist/base → base}/UnauthorizedHttpException.js +1 -1
  35. package/{dist/base → base}/UnauthorizedHttpException.js.map +1 -1
  36. package/{dist/base → base}/ValidationHttpException.js +1 -1
  37. package/{dist/base → base}/ValidationHttpException.js.map +1 -1
  38. package/{dist/base → base}/db/Exception.js +0 -0
  39. package/{dist/base → base}/db/Exception.js.map +0 -0
  40. package/{dist/base → base}/index.js +2 -0
  41. package/{dist/base → base}/index.js.map +1 -1
  42. package/{dist/decorator → decorator}/Middleware.js +0 -0
  43. package/{dist/decorator → decorator}/Middleware.js.map +0 -0
  44. package/{dist/decorator → decorator}/controller.js +0 -0
  45. package/{dist/decorator → decorator}/controller.js.map +0 -0
  46. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js +0 -0
  47. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js.map +0 -0
  48. package/{dist/decorator → decorator}/get.js +0 -0
  49. package/{dist/decorator → decorator}/get.js.map +0 -0
  50. package/{dist/decorator → decorator}/index.js +0 -0
  51. package/{dist/decorator → decorator}/index.js.map +0 -0
  52. package/{dist/decorator → decorator}/post.js +0 -0
  53. package/{dist/decorator → decorator}/post.js.map +0 -0
  54. package/{dist/filters → filters}/AccessControl.js +2 -2
  55. package/filters/AccessControl.js.map +1 -0
  56. package/{dist/filters → filters}/AccessRule.js +0 -0
  57. package/{dist/filters → filters}/AccessRule.js.map +1 -1
  58. package/{dist/filters → filters}/auth/AuthInterface.js +0 -0
  59. package/{dist/filters → filters}/auth/AuthInterface.js.map +0 -0
  60. package/{dist/filters → filters}/auth/AuthMethod.js +2 -2
  61. package/filters/auth/AuthMethod.js.map +1 -0
  62. package/{dist/filters → filters}/auth/HttpBasicAuth.js +0 -0
  63. package/{dist/filters → filters}/auth/HttpBasicAuth.js.map +0 -0
  64. package/{dist/filters → filters}/auth/HttpBearerAuth.js +0 -0
  65. package/{dist/filters → filters}/auth/HttpBearerAuth.js.map +0 -0
  66. package/{dist/filters → filters}/auth/HttpHeaderAuth.js +0 -0
  67. package/{dist/filters → filters}/auth/HttpHeaderAuth.js.map +1 -1
  68. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +1 -0
  69. package/filters/auth/JwtHttpBearerAuth.js.map +1 -0
  70. package/filters/auth/KeyCloakHttpBearerAuth.js +117 -0
  71. package/filters/auth/KeyCloakHttpBearerAuth.js.map +1 -0
  72. package/{dist/filters → filters}/auth/index.js +0 -0
  73. package/{dist/filters → filters}/auth/index.js.map +0 -0
  74. package/{dist/filters → filters}/index.js +0 -0
  75. package/{dist/filters → filters}/index.js.map +0 -0
  76. package/index.js +28 -0
  77. package/index.js.map +1 -0
  78. package/log/config/log4js.json +55 -0
  79. package/{dist/model → model}/RouteDefinition.js +0 -0
  80. package/{dist/model → model}/RouteDefinition.js.map +0 -0
  81. package/package.json +56 -52
  82. package/{dist/requiments → requiments}/Glob.js +0 -0
  83. package/{dist/requiments → requiments}/Glob.js.map +0 -0
  84. package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
  85. package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
  86. package/{dist/requiments → requiments}/Utils.js +0 -0
  87. package/{dist/requiments → requiments}/Utils.js.map +0 -0
  88. package/{dist/validators → validators}/BooleanValidator.js +0 -0
  89. package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
  90. package/{dist/validators → validators}/CompareValidator.js +0 -0
  91. package/{dist/validators → validators}/CompareValidator.js.map +0 -0
  92. package/{dist/validators → validators}/DateValidator.js +0 -0
  93. package/{dist/validators → validators}/DateValidator.js.map +0 -0
  94. package/{dist/validators → validators}/EmailValidator.js +0 -0
  95. package/{dist/validators → validators}/EmailValidator.js.map +0 -0
  96. package/{dist/validators → validators}/Validator.js +0 -0
  97. package/{dist/validators → validators}/Validator.js.map +0 -0
  98. package/{dist/web → web}/IdentityInterface.js +0 -0
  99. package/{dist/web → web}/IdentityInterface.js.map +0 -0
  100. package/{dist/web/User.js → web/WebUser.js} +12 -7
  101. package/web/WebUser.js.map +1 -0
  102. package/BaseChyz.ts +0 -313
  103. package/Chyz.ts +0 -11
  104. package/Examples/Controllers/ApiController.ts +0 -121
  105. package/Examples/Controllers/PublicController.ts +0 -44
  106. package/Examples/Controllers/SiteController.ts +0 -127
  107. package/Examples/Models/Customer.ts +0 -113
  108. package/Examples/Models/Order.ts +0 -48
  109. package/Examples/Models/OrderItem.ts +0 -26
  110. package/Examples/Models/User.ts +0 -80
  111. package/Examples/index.ts +0 -38
  112. package/Examples/package.json +0 -45
  113. package/Examples/tsconfig.json +0 -20
  114. package/Examples/yarn.lock +0 -2202
  115. package/base/ActionFilter.ts +0 -71
  116. package/base/BaseError.ts +0 -26
  117. package/base/BaseObject.ts +0 -19
  118. package/base/Behavior.ts +0 -6
  119. package/base/Component.ts +0 -66
  120. package/base/Configurable.ts +0 -10
  121. package/base/Controller.ts +0 -84
  122. package/base/DataErrorDbException.ts +0 -16
  123. package/base/DbConnection.ts +0 -51
  124. package/base/ForbiddenHttpException.ts +0 -15
  125. package/base/InvalidConfigException.ts +0 -16
  126. package/base/Model.ts +0 -209
  127. package/base/NotFoundHttpException.ts +0 -14
  128. package/base/UnauthorizedHttpException.ts +0 -16
  129. package/base/ValidationHttpException.ts +0 -14
  130. package/base/db/Exception.ts +0 -14
  131. package/base/index.ts +0 -14
  132. package/decorator/Middleware.ts +0 -9
  133. package/decorator/controller.ts +0 -22
  134. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  135. package/decorator/get.ts +0 -37
  136. package/decorator/index.ts +0 -3
  137. package/decorator/post.ts +0 -36
  138. package/dist/BaseChyz.js.map +0 -1
  139. package/dist/base/ActionFilter.js.map +0 -1
  140. package/dist/base/BaseError.js.map +0 -1
  141. package/dist/base/Model.js.map +0 -1
  142. package/dist/filters/AccessControl.js.map +0 -1
  143. package/dist/filters/auth/AuthMethod.js.map +0 -1
  144. package/dist/filters/auth/JwtHttpBearerAuth.js.map +0 -1
  145. package/dist/web/User.js.map +0 -1
  146. package/filters/AccessControl.ts +0 -64
  147. package/filters/AccessRule.ts +0 -137
  148. package/filters/auth/AuthInterface.ts +0 -34
  149. package/filters/auth/AuthMethod.ts +0 -88
  150. package/filters/auth/HttpBasicAuth.ts +0 -7
  151. package/filters/auth/HttpBearerAuth.ts +0 -31
  152. package/filters/auth/HttpHeaderAuth.ts +0 -53
  153. package/filters/auth/JwtHttpBearerAuth.ts +0 -81
  154. package/filters/auth/index.ts +0 -3
  155. package/filters/index.ts +0 -2
  156. package/model/RouteDefinition.ts +0 -18
  157. package/requiments/Glob.ts +0 -9
  158. package/requiments/ReflectUtil.ts +0 -26
  159. package/requiments/Utils.ts +0 -57
  160. package/tsconfig.json +0 -18
  161. package/validators/BooleanValidator.ts +0 -0
  162. package/validators/CompareValidator.ts +0 -0
  163. package/validators/DateValidator.ts +0 -0
  164. package/validators/EmailValidator.ts +0 -0
  165. package/validators/Validator.ts +0 -27
  166. package/web/IdentityInterface.ts +0 -62
  167. package/web/User.ts +0 -96
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebUser.js","sourceRoot":"","sources":["../../web/WebUser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,2DAAmC;AACnC,iDAA4C;AAC5C,2EAAsE;AACtE,2EAAsE;AAGtE,MAAa,OAAQ,SAAQ,qBAAS;IASlC,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,IAAI,QAAQ,CAAC,KAAK;QACd,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IAC3B,CAAC;IAEM,IAAI;QACP,KAAK,CAAC,IAAI,EAAE,CAAC;QAEb,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,EAAE;YAC7B,MAAM,IAAI,+CAAsB,CAAC,kCAAkC,CAAC,CAAC;SACxE;QAGD,IAAI,CAAC,aAAa,GAAG,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;IAElD,CAAC;IAEM,UAAU;QACb,OAAO,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC;IACvC,CAAC;IAEM,WAAW,CAAC,SAAS,GAAG,IAAI;QAC/B,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAEM,aAAa;QAEhB,MAAM,IAAI,+CAAsB,CAAC,kBAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACnE,CAAC;IAGD;;;;OAIG;IACO,mBAAmB;IAE7B,CAAC;IAED;;;;OAIG;IACU,kBAAkB,CAAC,KAAU,EAAE,OAAY,IAAI;;YAExD,IAAI,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;YAChC,IAAI,MAAM,CAAC,yBAAyB,EAAE;gBAClC,IAAI,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;gBACnE,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;oBAC5C,OAAO,IAAI,CAAC,QAAQ,CAAC;iBACxB;aACJ;iBAAI;gBACD,kBAAQ,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAA;aACjE;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;KAAA;IAEM,KAAK,CAAC,QAA2B,EAAE,QAAQ,GAAG,CAAC;QAElD,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE;SAEhD;QACD,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,CAAA;IAC7B,CAAC;IAEM,WAAW,CAAC,QAAa,EAAE,WAAoB,EAAE,QAAgB;QAEpE,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,UAAU;IAEjB,CAAC;CACJ;AAvFD,0BAuFC"}
package/BaseChyz.ts DELETED
@@ -1,313 +0,0 @@
1
- import 'reflect-metadata';
2
- import {RouteDefinition} from "./model/RouteDefinition";
3
- import {NextFunction, Request, Response} from "express";
4
- import {Controller} from "./base/Controller";
5
- import Utils from "./requiments/Utils";
6
-
7
-
8
- const express = require("express");
9
- const log4js = require("log4js");
10
- const fs = require('fs');
11
- const _ = require('lodash');
12
-
13
- var bodyParser = require('body-parser')
14
- var methodOverride = require('method-override')
15
-
16
- export {Request, Response, NextFunction} from "express";
17
- export default class BaseChyz {
18
- private config: any;
19
- static app: string;
20
- static express = express()
21
- private _port: number = 3001;
22
- static db: any;
23
- static routes: any;
24
- private _logConfig: any = require('./log/config/log4js.json') ?? {}
25
- private _controllerpath: string = "Controllers"
26
- private static controllers: Array<Controller> = []
27
- public static components: any = {}
28
-
29
- get logConfig(): any {
30
- return this._logConfig;
31
- }
32
-
33
- set logConfig(value: any) {
34
- this._logConfig = value;
35
- }
36
-
37
- get controllerpath(): string {
38
- return this._controllerpath;
39
- }
40
-
41
- set controllerpath(value: string) {
42
- this._controllerpath = value;
43
- }
44
-
45
- init() {
46
- this.logProvider().level = log4js.levels.ALL;
47
- this.logProvider().configure(this._logConfig);
48
-
49
- /**
50
- * set request id
51
- */
52
- Object.defineProperty(BaseChyz.express.request, 'reqId', {
53
- configurable: true,
54
- enumerable: true,
55
- writable: true
56
- })
57
-
58
- Object.defineProperty(BaseChyz.express.request, 'user', {
59
- configurable: true,
60
- enumerable: true,
61
- writable: true
62
- })
63
-
64
-
65
- Object.defineProperty(BaseChyz.express.request, 'identity', {
66
- configurable: true,
67
- enumerable: true,
68
- writable: true
69
- })
70
-
71
-
72
- /**
73
- * server port setting
74
- */
75
- if (this.config.hasOwnProperty("port"))
76
- this.port = this.config.port;
77
-
78
- /**
79
- * controller path
80
- */
81
- if (this.config.controllerpath) {
82
- this.controllerpath = this.config.controllerpath
83
- }
84
-
85
- /**
86
- * Express Server
87
- */
88
- this.middleware()
89
-
90
- /**
91
- * Load Controller
92
- */
93
- this.loadController();
94
-
95
-
96
- }
97
-
98
- /**
99
- * Listen port number
100
- * Server port number get
101
- */
102
- get port(): number {
103
- return this._port;
104
- }
105
-
106
- /**
107
- * Listen port number
108
- * Server port number setting
109
- * @param value
110
- */
111
- set port(value: number) {
112
- this._port = value;
113
- }
114
-
115
-
116
- app(config: any = {}): BaseChyz {
117
-
118
- /**
119
- * Config set
120
- */
121
- this.config = config;
122
-
123
- this.init();
124
-
125
- let components = Utils.findKeyValue(config, "components")
126
- if (components) {
127
- for (const componentsKey in components) {
128
- let comp = components[componentsKey];
129
- BaseChyz.debug("Create Component ", componentsKey)
130
- BaseChyz.components[componentsKey] = Utils.createObject(new comp.class, comp);
131
- BaseChyz.components[componentsKey]?.init();
132
- }
133
- }
134
-
135
- return this;
136
- }
137
-
138
-
139
- public logProvider() {
140
- return log4js;
141
- }
142
-
143
- public getLogger(){
144
- return this.logProvider().getLogger(this.constructor.name);
145
- }
146
-
147
- static logs(...args: any[]) {
148
- return log4js.getLogger(this.name);
149
- }
150
-
151
- public static trace(...args: any[]) {
152
- BaseChyz.logs().fatal(...arguments)
153
- }
154
- public static debug(...args: any[]) {
155
- BaseChyz.logs().debug(...arguments)
156
- }
157
- public static info(...args: any[]) {
158
- BaseChyz.logs().info(...arguments)
159
- }
160
- public static warn(...args: any[]) {
161
- BaseChyz.logs().warn(...arguments)
162
- }
163
-
164
- public static error(...args: any[]) {
165
- BaseChyz.logs().error(...arguments)
166
- }
167
-
168
- public static fatal(...args: any[]) {
169
- BaseChyz.logs().fatal(...arguments)
170
- }
171
-
172
-
173
-
174
-
175
- public static warning(...args: any[]) {
176
- BaseChyz.logs().warn(...arguments)
177
- }
178
-
179
- public static t(text: string) {
180
- return text;
181
- }
182
-
183
-
184
- public errorLogger(error: any, req: any, res: any, next: any) { // for logging errors
185
- BaseChyz.error(error)
186
- next(error) // forward to next middleware
187
- }
188
-
189
- public errorResponder(error: any, req: any, res: any, next: any) { // responding to client
190
- if (error.type == 'redirect')
191
- res.redirect('/error')
192
- else if (error.type == 'time-out') // arbitrary condition check
193
- res.status(408).json(error)
194
- else
195
- next(error) // forwarding exceptional case to fail-safe middleware
196
- }
197
-
198
-
199
- public errorHandler(err: any, req: any, res: any, next: any) {
200
- if (res.headersSent) {
201
- return next(err)
202
- }
203
- res.status(500)
204
- res.json('error', {error: err})
205
- }
206
-
207
- public static getComponent(key: any) {
208
- return BaseChyz.components[key] ?? null
209
- }
210
-
211
- /**
212
- * load contoller
213
- */
214
- async loadController() {
215
- let articlesEndpoints: string[] = [];
216
- fs.readdirSync(`${this._controllerpath}/`).forEach((file: string) => {
217
- let controller = require(`${this._controllerpath}/${file}`);
218
-
219
- // This is our instantiated class
220
- const instance: Controller = new controller();
221
-
222
- BaseChyz.controllers.push(instance);
223
-
224
- // The prefix saved to our controller
225
- // @ts-ignore
226
- const prefix = Reflect.getMetadata('prefix', controller);
227
- // Our `routes` array containing all our routes for this controller
228
- // @ts-ignore
229
- const routes: Array<RouteDefinition> = Reflect.getMetadata('routes', controller);
230
- BaseChyz.logs().debug("Controller load ", controller.name, `(${prefix})`)
231
-
232
- if (routes) {
233
- routes.forEach(route => {
234
-
235
- let actionId = route.path == "/" || route.path == "" ? instance.defaultAction : route.path;
236
- route.id = actionId;
237
- BaseChyz.logs().debug("Controller route Path", prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`))
238
-
239
- BaseChyz.express[route.requestMethod](prefix + (route.path.startsWith("/") ? route.path : `/${route.path}`),
240
- async (req: Request, res: Response, next: NextFunction) => {
241
- try {
242
- BaseChyz.debug(`Call Request id ${instance.id}`)
243
- await instance.beforeAction(route, req, res)
244
- next()
245
- } catch (e) {
246
- BaseChyz.error(e);
247
-
248
- res.status(e.statusCode || 500)
249
- res.json({error: {code: e.statusCode || 500, name: e.name, message: e.message}})
250
- // next(e)
251
- }
252
-
253
- },
254
- async (req: Request, res: Response, next: NextFunction) => {
255
- try {
256
- // @ts-ignore
257
- BaseChyz.debug("Request ID ", req.reqId)
258
- // @ts-ignore
259
- await instance[route.methodName](req, res, next);
260
- instance.afterAction(route, req, res);
261
- } catch (e) {
262
- BaseChyz.error(e)
263
- // next(e)
264
- res.status(e.statusCode)
265
- res.json({error: {code: e.statusCode, name: e.name, message: e.message}})
266
- }
267
- })
268
-
269
-
270
- });
271
- }
272
- })
273
- }
274
-
275
- public middleware() {
276
-
277
- BaseChyz.express.use(bodyParser.json())
278
- BaseChyz.express.use(bodyParser.urlencoded({extended: true})); // support encoded bodies
279
- BaseChyz.express.use(methodOverride());
280
- BaseChyz.express.use(this.errorResponder)
281
- BaseChyz.express.use(this.errorHandler)
282
-
283
-
284
- // CORS
285
- BaseChyz.express.use(function (req: any, res: Response, next: any) {
286
- // @ts-ignore
287
- req.reqId = Utils.uniqueId("chyzzzz_")
288
- res.setHeader('Content-Type', 'application/json');
289
- res.setHeader("Access-Control-Allow-Origin", "*");
290
- res.setHeader("Access-Control-Allow-Credentials", "true");
291
- res.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
292
- res.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Origin,Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers,Authorization");
293
- next();
294
- });
295
-
296
-
297
- }
298
-
299
-
300
- public Start() {
301
-
302
- BaseChyz.info("Express Server Starting")
303
- BaseChyz.express.listen(this._port, () => {
304
- BaseChyz.info("Express Server Start ")
305
- BaseChyz.info(`Liten Port ${this._port}`)
306
- })
307
- return this;
308
- }
309
-
310
-
311
- }
312
-
313
-
package/Chyz.ts DELETED
@@ -1,11 +0,0 @@
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 BaseChyz from "./BaseChyz";
9
- const Chyz = new BaseChyz();
10
-
11
- export default Chyz;
@@ -1,121 +0,0 @@
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 {Controller} from "../../base/Controller";
9
- import BaseChyz from "../../BaseChyz";
10
- // @ts-ignore
11
- import {Request, Response} from "express";
12
- import {get} from "../../decorator/get";
13
- import {post} from "../../decorator/post";
14
- import {controller} from "../../decorator/controller";
15
- import {AccessControl} from "../../filters/AccessControl";
16
- import {JwtHttpBearerAuth} from "../../filters/auth/JwtHttpBearerAuth";
17
- import {Order} from "../Models/Order";
18
- import {Customer} from "../Models/Customer";
19
- import {ValidationHttpException} from "../../base/ValidationHttpException";
20
- import {ValidationError} from "sequelize";
21
- import {ForbiddenHttpException} from "../../base";
22
-
23
- @controller("/api")
24
- class ApiController extends Controller {
25
-
26
- public myCheck(token) {
27
- console.log("myyyyyyyyyyyyyyyyyyyyy")
28
- }
29
-
30
- public behaviors(): any[] {
31
-
32
- return [{
33
- 'authenticator': {
34
- "class": JwtHttpBearerAuth,
35
- // "auth": this.myCheck
36
- },
37
- 'access': {
38
- 'class': AccessControl,
39
- 'only': ['login', 'logout', 'signup'],
40
- 'rules': [
41
- {
42
- 'allow': true,
43
- 'actions': ['login', 'index'],
44
- 'roles': ['?'],
45
- },
46
- {
47
- 'allow': true,
48
- 'actions': ['logout', "logout2"],
49
- 'roles': ['@'],
50
- }
51
- ]
52
- }
53
- }]
54
- }
55
-
56
- @get("/")
57
- Index(req: Request, res: Response) {
58
-
59
- BaseChyz.logs().info("Site Controller Burası", this.id)
60
- return res.json({message: "index sayfası"})
61
- }
62
-
63
- @post("orderCreate")
64
- async Login(req: Request, res: Response) {
65
- let data = req.body;
66
- data.Customer.status = "true";
67
- data.Customer["2fa"] = "true";
68
-
69
- //Customer Model Create
70
- let customer: Customer = new Customer();
71
- //Order Model Create
72
- let order: Order = new Order();
73
-
74
-
75
- let transaction
76
- try {
77
- // get transaction
78
- transaction = await BaseChyz.getComponent("db").transaction();
79
-
80
-
81
- customer.load(data, "Customer");//load customer data
82
- let cus: any = await customer.save({}, {transaction});
83
-
84
- if (!cus) {
85
- throw new ValidationHttpException(customer.errors);
86
- }
87
-
88
- data.Order.customer_id = cus.id;
89
- // data.Order.total = 0;
90
- // data.Order.status = true;
91
- order.load(data, "Order");
92
- let res1 = await order.save({}, {transaction});
93
- if (!res1) {
94
- throw new ValidationHttpException(order.errors);
95
- }
96
-
97
- // commit
98
- await transaction.commit();
99
-
100
- } catch (e) {
101
- if (transaction) {
102
- await transaction.rollback();
103
- BaseChyz.warn("Rollback transaction")
104
- }
105
-
106
- if (e instanceof ValidationHttpException)
107
- throw new ValidationHttpException(e.message)
108
- else
109
- throw new ForbiddenHttpException(e.message)
110
- }
111
- return res.send("Post Controller")
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
@@ -1,44 +0,0 @@
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 {Controller} from "../../base/Controller";
9
- import BaseChyz from "../../BaseChyz";
10
- // @ts-ignore
11
- import {Request, Response} from "express";
12
- import {get} from "../../decorator/get";
13
- import {post} from "../../decorator/post";
14
- 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
-
19
- @controller("/public")
20
- class PublicController extends Controller {
21
-
22
- public myCheck(token) {
23
- console.log("myyyyyyyyyyyyyyyyyyyyy")
24
- }
25
-
26
- public behaviors(): any[] {
27
-
28
- return [ ]
29
- }
30
-
31
- @get("/")
32
- Index(req: Request, res: Response) {
33
-
34
- BaseChyz.logs().info("Site Controller Burası", super.id)
35
- return res.json({message: "index sayfası"})
36
- }
37
-
38
-
39
- error(req: Request, res: Response) {
40
- BaseChyz.logs().info("Error Sayfası")
41
- return res.send("Post Controller")
42
- }
43
- }
44
- module.exports=PublicController
@@ -1,127 +0,0 @@
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 {Controller} from "../../base/Controller";
9
- import BaseChyz from "../../BaseChyz";
10
- // @ts-ignore
11
- import {Request, Response} from "express";
12
- import {get} from "../../decorator/get";
13
- import {post} from "../../decorator/post";
14
- import {controller} from "../../decorator/controller";
15
- import {User} from "../Models/User";
16
- import {ForbiddenHttpException} from "../../base";
17
-
18
- const bcrypt = require('bcrypt');
19
- const JsonWebToken = require("jsonwebtoken");
20
-
21
-
22
- @controller("/site")
23
- class SiteController extends Controller {
24
-
25
- public myCheck(token) {
26
- console.log("myyyyyyyyyyyyyyyyyyyyy")
27
- }
28
-
29
- // public behaviors(): any[] {
30
- //
31
- // return [{
32
- // // 'authenticator': {
33
- // // "class": JwtHttpBearerAuth,
34
- // // // "auth": this.myCheck
35
- // // },
36
- // 'access': {
37
- // 'class': AccessControl,
38
- // 'only': ['login', 'logout','index' ],
39
- // 'rules': [
40
- // {
41
- // 'allow': false,
42
- // 'actions': ['login', 'index' ],
43
- // 'roles': ['?'],
44
- // },
45
- // {
46
- // 'allow': true,
47
- // 'actions': ['logout', "logout2"],
48
- // 'roles': ['@'],
49
- // }
50
- // ]
51
- // }
52
- // }]
53
- // }
54
-
55
- @get("index")
56
- Index(req: Request, res: Response) {
57
-
58
- BaseChyz.logs().info("Site Controller Burası", this.id)
59
- return res.json({message: "index sayfası"})
60
- }
61
-
62
- @post("login")
63
- async login(req: Request, res: Response) {
64
- let UserModel: User = new User();
65
- let token
66
- let username = req.body.username;
67
- let password = req.body.password;
68
-
69
- let user = await UserModel.findOne({where: {username: username}})
70
- if (user) {
71
- BaseChyz.debug("Db found user", username)
72
- const match = await bcrypt.compare(password, user.password);
73
- if (match) {
74
- BaseChyz.debug("Db user verify", username)
75
- //login
76
- // @ts-ignore
77
- let xForwardedFor = (req.headers['x-forwarded-for'] || '').replace(/:\d+$/, '');
78
- let ip = xForwardedFor || req.socket.remoteAddress;
79
- var source: string = req.headers['user-agent'] || '';
80
- if (req.headers['x-ucbrowser-ua']) { //special case of UC Browser
81
- source = req.headers['x-ucbrowser-ua']+"";
82
- }
83
- token = await JsonWebToken.sign({
84
- user: user.id,
85
- ip: ip,
86
- agent: source,
87
- }, user.salt_text, {expiresIn: '1h'});
88
-
89
- BaseChyz.debug("Db user create access token", username,"expiresIn","1h")
90
- return res.json({token: token})
91
- } else {
92
- let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
93
- res.status(500).json( error.toJSON())
94
- }
95
- } else {
96
- let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
97
- res.status(500).json( error.toJSON())
98
- }
99
-
100
-
101
- }
102
-
103
- @get("logout")
104
- logout(req: Request, res: Response) {
105
-
106
- // @ts-ignore
107
- let identity = req.user ?? BaseChyz.getComponent("user").getIdentity();
108
- // console.log("logout2", identity.id)
109
- console.log(identity)
110
-
111
- BaseChyz.logs().info("Logout Controller")
112
- return res.send("Logout Controller")
113
- }
114
-
115
- @get("signup")
116
- logout2(req: Request, res: Response) {
117
-
118
-
119
- return res.send("Logout Controller")
120
- }
121
-
122
- error(req: Request, res: Response) {
123
- BaseChyz.logs().info("Error Sayfası")
124
- return res.send("Post Controller")
125
- }
126
- }
127
- module.exports=SiteController