chyz 1.0.13-rc.10 → 1.0.13-rc.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.
- package/Examples/Controllers/ApiController.ts +9 -6
- package/Examples/Controllers/BasicApiController.ts +121 -0
- package/Examples/Controllers/SiteController.ts +26 -9
- package/Examples/Models/KeycloakUser.ts +4 -0
- package/Examples/Models/User.ts +8 -1
- package/Examples/log/app.log +723 -0
- package/Examples/log/errors.log +85 -0
- package/Examples/yarn.lock +2549 -0
- package/base/BaseError.ts +3 -1
- package/base/Model.ts +31 -25
- package/base/ModelManager.ts +6 -1
- package/dist/base/BaseError.js +5 -1
- package/dist/base/BaseError.js.map +1 -1
- package/dist/base/Model.js +5 -2
- package/dist/base/Model.js.map +1 -1
- package/dist/base/ModelManager.js +0 -8
- package/dist/base/ModelManager.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/index.js +1 -0
- package/dist/filters/auth/index.js.map +1 -1
- package/dist/package.json +1 -2
- package/dist/rbac/AuthManager.js.map +1 -1
- package/filters/auth/HttpBasicAuth.ts +68 -0
- package/filters/auth/index.ts +1 -0
- package/package.json +1 -2
- package/rbac/AuthManager.ts +2 -0
- package/web/IdentityInterface.ts +6 -0
- package/package-lock.json +0 -5259
|
@@ -18,7 +18,7 @@ import {JwtHttpBearerAuth} from "../../filters/auth";
|
|
|
18
18
|
|
|
19
19
|
import {ValidationHttpException} from "../../base";
|
|
20
20
|
import {ForbiddenHttpException} from "../../base";
|
|
21
|
-
|
|
21
|
+
import {ProductsClass} from "../Models/Products";
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
@controller("/api")
|
|
@@ -68,9 +68,9 @@ class ApiController extends Controller {
|
|
|
68
68
|
data.Customer["2fa"] = "true";
|
|
69
69
|
|
|
70
70
|
//Customer Model Create
|
|
71
|
-
let customer
|
|
71
|
+
let customer = ModelManager.Customer.save();
|
|
72
72
|
//Order Model Create
|
|
73
|
-
let order
|
|
73
|
+
let order = ModelManager.Order;
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
let transaction
|
|
@@ -113,20 +113,23 @@ class ApiController extends Controller {
|
|
|
113
113
|
|
|
114
114
|
@get("order/list")
|
|
115
115
|
async listOrder(req: Request, res: Response) {
|
|
116
|
-
|
|
116
|
+
const {Products}: { Products: ProductsClass } = ModelManager;
|
|
117
|
+
let product = await Products.findAll({include: [ModelManager.ProductModels.model()]});
|
|
117
118
|
return res.json(product)
|
|
118
119
|
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
@get("categories")
|
|
122
123
|
async Categories(req: Request, res: Response) {
|
|
123
|
-
let product = await ModelManager.Categories.findAll(
|
|
124
|
+
let product = await ModelManager.Categories.findAll({
|
|
125
|
+
include: [
|
|
124
126
|
{
|
|
125
127
|
model: ModelManager.Products.model(),
|
|
126
128
|
// as: 'product',
|
|
127
129
|
// through: { attributes: [] } // Hide unwanted `PlayerGameTeam` nested object from results
|
|
128
130
|
}
|
|
129
|
-
]
|
|
131
|
+
]
|
|
132
|
+
});
|
|
130
133
|
return res.json(product)
|
|
131
134
|
|
|
132
135
|
}
|
|
@@ -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
|
|
@@ -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,40 @@ 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
|
-
|
|
101
|
-
|
|
100
|
+
platform: "admin",
|
|
101
|
+
role: [
|
|
102
|
+
"admin"
|
|
103
|
+
],
|
|
104
|
+
permissions: [
|
|
105
|
+
"alprboxkoli",
|
|
106
|
+
"edisboxkoli",
|
|
107
|
+
"hubboxkoli",
|
|
108
|
+
"edisboxold",
|
|
109
|
+
"edisboxnew",
|
|
110
|
+
"hubboxold",
|
|
111
|
+
"hubboxnew",
|
|
112
|
+
"alprboxold",
|
|
113
|
+
"alprboxnew"
|
|
114
|
+
],
|
|
115
|
+
}, user.authkey, null);
|
|
116
|
+
|
|
117
|
+
BaseChyz.debug("Db user create access token", username, "expiresIn", "1h")
|
|
102
118
|
return res.json({token: token})
|
|
103
119
|
} else {
|
|
104
120
|
let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
|
|
105
|
-
res.status(500).json(
|
|
121
|
+
res.status(500).json(error.toJSON())
|
|
106
122
|
}
|
|
107
123
|
} else {
|
|
108
124
|
let error: any = new ForbiddenHttpException(BaseChyz.t('You are not allowed to perform this action.'))
|
|
109
|
-
res.status(500).json(
|
|
125
|
+
res.status(500).json(error.toJSON())
|
|
110
126
|
}
|
|
111
127
|
|
|
112
128
|
|
|
@@ -136,4 +152,5 @@ class SiteController extends Controller {
|
|
|
136
152
|
return res.send("Post Controller")
|
|
137
153
|
}
|
|
138
154
|
}
|
|
139
|
-
|
|
155
|
+
|
|
156
|
+
module.exports = SiteController
|
package/Examples/Models/User.ts
CHANGED
|
@@ -28,6 +28,11 @@ export class User extends Model implements IdentityInterface {
|
|
|
28
28
|
throw new Error("Method not implemented.");
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
can(permissionName: string, params: any[], allowCaching: boolean): boolean | null {
|
|
32
|
+
throw new Error("Method not implemented.");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
31
36
|
getAuthKey(): string {
|
|
32
37
|
throw new Error("Method not implemented.");
|
|
33
38
|
}
|
|
@@ -71,8 +76,8 @@ export class User extends Model implements IdentityInterface {
|
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
async findIdentityByAccessToken(token, type) {
|
|
74
|
-
let decoded = JsonWebToken.decode(token, {complete: true})
|
|
75
79
|
|
|
80
|
+
let decoded = JsonWebToken.decode(token, {complete: true})
|
|
76
81
|
if(!decoded.payload.user) {
|
|
77
82
|
return null;
|
|
78
83
|
}
|
|
@@ -97,4 +102,6 @@ export class User extends Model implements IdentityInterface {
|
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
|
|
105
|
+
|
|
106
|
+
|
|
100
107
|
}
|