chyz 2.0.0-rc.8 → 2.0.1-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.d.ts +73 -56
- package/BaseChyz.d.ts.map +1 -1
- package/BaseChyz.js +569 -404
- package/README.md +1 -1
- package/base/ActionFilter.d.ts +32 -32
- package/base/ActionFilter.d.ts.map +1 -1
- package/base/ActionFilter.js +82 -82
- package/base/BadRequestHttpException.d.ts +6 -0
- package/base/BadRequestHttpException.d.ts.map +1 -0
- package/base/BadRequestHttpException.js +17 -0
- package/base/BaseError.d.ts +43 -10
- package/base/BaseError.d.ts.map +1 -1
- package/base/BaseError.js +58 -26
- package/base/Behavior.d.ts +3 -3
- package/base/Behavior.js +7 -7
- package/base/CBaseObject.d.ts +4 -4
- package/base/CBaseObject.d.ts.map +1 -1
- package/base/CBaseObject.js +16 -16
- package/base/CEvents.d.ts +13 -0
- package/base/CEvents.d.ts.map +1 -0
- package/base/CEvents.js +24 -0
- package/base/CRequest.d.ts +1 -1
- package/base/CRequest.js +10 -10
- package/base/CWebController.d.ts +43 -43
- package/base/CWebController.d.ts.map +1 -1
- package/base/CWebController.js +81 -74
- package/base/Component.d.ts +20 -20
- package/base/Component.d.ts.map +1 -1
- package/base/Component.js +57 -57
- package/base/Configurable.d.ts +2 -2
- package/base/Configurable.js +8 -8
- package/base/DataErrorDbException.d.ts +5 -5
- package/base/DataErrorDbException.d.ts.map +1 -1
- package/base/DataErrorDbException.js +17 -17
- package/base/DbConnection.d.ts +12 -12
- package/base/DbConnection.js +53 -53
- package/base/ForbiddenHttpException.d.ts +4 -4
- package/base/ForbiddenHttpException.d.ts.map +1 -1
- package/base/ForbiddenHttpException.js +16 -16
- package/base/InvalidArgumentException.d.ts +5 -5
- package/base/InvalidArgumentException.d.ts.map +1 -1
- package/base/InvalidArgumentException.js +17 -17
- package/base/InvalidConfigException.d.ts +5 -5
- package/base/InvalidConfigException.d.ts.map +1 -1
- package/base/InvalidConfigException.js +17 -17
- package/base/Logs.d.ts +21 -21
- package/base/Logs.d.ts.map +1 -1
- package/base/Logs.js +57 -57
- package/base/Model.d.ts +301 -298
- package/base/Model.d.ts.map +1 -1
- package/base/Model.js +545 -507
- package/base/ModelManager.d.ts +1 -1
- package/base/ModelManager.js +19 -19
- package/base/NotFoundHttpException.d.ts +5 -5
- package/base/NotFoundHttpException.d.ts.map +1 -1
- package/base/NotFoundHttpException.js +17 -17
- package/base/RestClient.d.ts +6 -6
- package/base/RestClient.d.ts.map +1 -1
- package/base/RestClient.js +25 -25
- package/base/UnauthorizedHttpException.d.ts +5 -5
- package/base/UnauthorizedHttpException.d.ts.map +1 -1
- package/base/UnauthorizedHttpException.js +17 -17
- package/base/ValidationHttpException.d.ts +5 -5
- package/base/ValidationHttpException.d.ts.map +1 -1
- package/base/ValidationHttpException.js +17 -17
- package/base/db/Exception.d.ts +6 -6
- package/base/db/Exception.js +15 -15
- package/base/index.d.ts +19 -18
- package/base/index.d.ts.map +1 -1
- package/base/index.js +41 -39
- package/decorator/Middleware.d.ts +3 -3
- package/decorator/Middleware.js +11 -11
- package/decorator/controller.d.ts +2 -2
- package/decorator/controller.js +24 -24
- package/decorator/delete.d.ts +3 -0
- package/decorator/delete.d.ts.map +1 -0
- package/decorator/delete.js +36 -0
- package/decorator/enums/ControllerDecoratorParams.d.ts +5 -5
- package/decorator/enums/ControllerDecoratorParams.js +9 -9
- package/decorator/get.d.ts +2 -2
- package/decorator/get.js +36 -36
- package/decorator/index.d.ts +5 -3
- package/decorator/index.d.ts.map +1 -1
- package/decorator/index.js +13 -9
- package/decorator/post.d.ts +2 -2
- package/decorator/post.js +36 -36
- package/decorator/put.d.ts +3 -0
- package/decorator/put.d.ts.map +1 -0
- package/decorator/put.js +36 -0
- package/filters/AccessControl.d.ts +12 -12
- package/filters/AccessControl.d.ts.map +1 -1
- package/filters/AccessControl.js +83 -83
- package/filters/AccessRule.d.ts +82 -82
- package/filters/AccessRule.d.ts.map +1 -1
- package/filters/AccessRule.js +136 -137
- package/filters/auth/AuthInterface.d.ts +25 -25
- package/filters/auth/AuthInterface.js +2 -2
- package/filters/auth/AuthMethod.d.ts +37 -37
- package/filters/auth/AuthMethod.d.ts.map +1 -1
- package/filters/auth/AuthMethod.js +82 -82
- package/filters/auth/HttpBasicAuth.d.ts +23 -22
- package/filters/auth/HttpBasicAuth.d.ts.map +1 -1
- package/filters/auth/HttpBasicAuth.js +78 -72
- package/filters/auth/HttpBearerAuth.d.ts +17 -17
- package/filters/auth/HttpBearerAuth.d.ts.map +1 -1
- package/filters/auth/HttpBearerAuth.js +33 -32
- package/filters/auth/HttpHeaderAuth.d.ts +18 -14
- package/filters/auth/HttpHeaderAuth.d.ts.map +1 -1
- package/filters/auth/HttpHeaderAuth.js +64 -57
- package/filters/auth/JwtHttpBearerAuth.d.ts +20 -20
- package/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -1
- package/filters/auth/JwtHttpBearerAuth.js +87 -81
- package/filters/auth/KeyCloakHttpBearerAuth.d.ts +22 -22
- package/filters/auth/KeyCloakHttpBearerAuth.js +116 -116
- package/filters/auth/index.d.ts +4 -4
- package/filters/auth/index.js +11 -11
- package/filters/index.d.ts +2 -2
- package/filters/index.js +7 -7
- package/index.d.ts +28 -21
- package/index.d.ts.map +1 -1
- package/index.js +71 -60
- package/model/RouteDefinition.d.ts +6 -6
- package/model/RouteDefinition.js +8 -8
- package/package.json +22 -24
- package/rbac/AuthAssignment.d.ts +18 -18
- package/rbac/AuthAssignment.js +44 -44
- package/rbac/AuthItem.d.ts +26 -26
- package/rbac/AuthItem.js +51 -51
- package/rbac/AuthItemChild.d.ts +18 -18
- package/rbac/AuthItemChild.js +43 -43
- package/rbac/AuthManager.d.ts +111 -111
- package/rbac/AuthManager.d.ts.map +1 -1
- package/rbac/AuthManager.js +356 -355
- package/rbac/index.d.ts +5 -0
- package/rbac/index.d.ts.map +1 -0
- package/rbac/index.js +28 -0
- package/requiments/Glob.d.ts +2 -2
- package/requiments/Glob.js +10 -10
- package/requiments/ReflectUtil.js +24 -24
- package/requiments/Utils.d.ts +1 -8
- package/requiments/Utils.d.ts.map +1 -1
- package/requiments/Utils.js +115 -112
- package/validators/BooleanValidator.js +1 -1
- package/validators/CompareValidator.js +1 -1
- package/validators/DateValidator.js +1 -1
- package/validators/EmailValidator.js +1 -1
- package/validators/Validator.d.ts +17 -17
- package/validators/Validator.js +27 -27
- package/web/IdentityInterface.d.ts +55 -54
- package/web/IdentityInterface.d.ts.map +1 -1
- package/web/IdentityInterface.js +8 -8
- package/web/WebUser.d.ts +71 -71
- package/web/WebUser.js +165 -165
package/web/WebUser.d.ts
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { Component } from "../base/Component";
|
|
2
|
-
import { IdentityInterface } from "./IdentityInterface";
|
|
3
|
-
import { AuthManager } from "../rbac/AuthManager";
|
|
4
|
-
export declare class WebUser extends Component {
|
|
5
|
-
/**
|
|
6
|
-
* @var string the class name of the [[identity]] object.
|
|
7
|
-
*/
|
|
8
|
-
identityClass: any;
|
|
9
|
-
private _identity;
|
|
10
|
-
/**
|
|
11
|
-
* @var CheckAccessInterface|string|array The access checker object to use for checking access or the application
|
|
12
|
-
* component ID of the access checker.
|
|
13
|
-
* If not set the application auth manager will be used.
|
|
14
|
-
* @since 2.0.9
|
|
15
|
-
*/
|
|
16
|
-
accessChecker: any;
|
|
17
|
-
get identity(): any;
|
|
18
|
-
set identity(value: any);
|
|
19
|
-
init(): void;
|
|
20
|
-
getIsGuest(): boolean;
|
|
21
|
-
getIdentity(autoRenew?: boolean): any;
|
|
22
|
-
loginRequired(): void;
|
|
23
|
-
/**
|
|
24
|
-
* Regenerates CSRF token
|
|
25
|
-
*
|
|
26
|
-
* @since 2.0.14.2
|
|
27
|
-
*/
|
|
28
|
-
protected regenerateCsrfToken(): void;
|
|
29
|
-
/**
|
|
30
|
-
* Logs in a user by the given access token.
|
|
31
|
-
* @param token
|
|
32
|
-
* @param type
|
|
33
|
-
*/
|
|
34
|
-
loginByAccessToken(token: any, type?: any): Promise<any>;
|
|
35
|
-
login(identity: IdentityInterface, duration?: number): boolean;
|
|
36
|
-
beforeLogin(identity: any, cookieBased: boolean, duration: number): boolean;
|
|
37
|
-
afterLogin(): void;
|
|
38
|
-
getId(): any;
|
|
39
|
-
/**
|
|
40
|
-
* Checks if the user can perform the operation as specified by the given permission.
|
|
41
|
-
*
|
|
42
|
-
* Note that you must configure "authManager" application component in order to use this method.
|
|
43
|
-
* Otherwise it will always return false.
|
|
44
|
-
*
|
|
45
|
-
* @param string $permissionName the name of the permission (e.g. "edit post") that needs access check.
|
|
46
|
-
* @param array $params name-value pairs that would be passed to the rules associated
|
|
47
|
-
* with the roles and permissions assigned to the user.
|
|
48
|
-
* @param bool $allowCaching whether to allow caching the result of access check.
|
|
49
|
-
* When this parameter is true (default), if the access check of an operation was performed
|
|
50
|
-
* before, its result will be directly returned when calling this method to check the same
|
|
51
|
-
* operation. If this parameter is false, this method will always call
|
|
52
|
-
* [[\yii\rbac\CheckAccessInterface::checkAccess()]] to obtain the up-to-date access result. Note that this
|
|
53
|
-
* caching is effective only within the same request and only works when `$params = []`.
|
|
54
|
-
* @return bool whether the user can perform the operation as specified by the given permission.
|
|
55
|
-
*/
|
|
56
|
-
can(permissionName: string, params?: never[], allowCaching?: boolean): Promise<boolean>;
|
|
57
|
-
/**
|
|
58
|
-
* Returns auth manager associated with the user component.
|
|
59
|
-
*
|
|
60
|
-
* By default this is the `authManager` application component.
|
|
61
|
-
* You may override this method to return a different auth manager instance if needed.
|
|
62
|
-
* @return \yii\rbac\ManagerInterface
|
|
63
|
-
* @since 2.0.6
|
|
64
|
-
*/
|
|
65
|
-
protected getAuthManager(): AuthManager;
|
|
66
|
-
/**
|
|
67
|
-
* Returns the access checker used for checking access.
|
|
68
|
-
* @return CheckAccessInterface
|
|
69
|
-
*/
|
|
70
|
-
protected getAccessChecker(): AuthManager;
|
|
71
|
-
}
|
|
1
|
+
import { Component } from "../base/Component";
|
|
2
|
+
import { IdentityInterface } from "./IdentityInterface";
|
|
3
|
+
import { AuthManager } from "../rbac/AuthManager";
|
|
4
|
+
export declare class WebUser extends Component {
|
|
5
|
+
/**
|
|
6
|
+
* @var string the class name of the [[identity]] object.
|
|
7
|
+
*/
|
|
8
|
+
identityClass: any;
|
|
9
|
+
private _identity;
|
|
10
|
+
/**
|
|
11
|
+
* @var CheckAccessInterface|string|array The access checker object to use for checking access or the application
|
|
12
|
+
* component ID of the access checker.
|
|
13
|
+
* If not set the application auth manager will be used.
|
|
14
|
+
* @since 2.0.9
|
|
15
|
+
*/
|
|
16
|
+
accessChecker: any;
|
|
17
|
+
get identity(): any;
|
|
18
|
+
set identity(value: any);
|
|
19
|
+
init(): void;
|
|
20
|
+
getIsGuest(): boolean;
|
|
21
|
+
getIdentity(autoRenew?: boolean): any;
|
|
22
|
+
loginRequired(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Regenerates CSRF token
|
|
25
|
+
*
|
|
26
|
+
* @since 2.0.14.2
|
|
27
|
+
*/
|
|
28
|
+
protected regenerateCsrfToken(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Logs in a user by the given access token.
|
|
31
|
+
* @param token
|
|
32
|
+
* @param type
|
|
33
|
+
*/
|
|
34
|
+
loginByAccessToken(token: any, type?: any): Promise<any>;
|
|
35
|
+
login(identity: IdentityInterface, duration?: number): boolean;
|
|
36
|
+
beforeLogin(identity: any, cookieBased: boolean, duration: number): boolean;
|
|
37
|
+
afterLogin(): void;
|
|
38
|
+
getId(): any;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if the user can perform the operation as specified by the given permission.
|
|
41
|
+
*
|
|
42
|
+
* Note that you must configure "authManager" application component in order to use this method.
|
|
43
|
+
* Otherwise it will always return false.
|
|
44
|
+
*
|
|
45
|
+
* @param string $permissionName the name of the permission (e.g. "edit post") that needs access check.
|
|
46
|
+
* @param array $params name-value pairs that would be passed to the rules associated
|
|
47
|
+
* with the roles and permissions assigned to the user.
|
|
48
|
+
* @param bool $allowCaching whether to allow caching the result of access check.
|
|
49
|
+
* When this parameter is true (default), if the access check of an operation was performed
|
|
50
|
+
* before, its result will be directly returned when calling this method to check the same
|
|
51
|
+
* operation. If this parameter is false, this method will always call
|
|
52
|
+
* [[\yii\rbac\CheckAccessInterface::checkAccess()]] to obtain the up-to-date access result. Note that this
|
|
53
|
+
* caching is effective only within the same request and only works when `$params = []`.
|
|
54
|
+
* @return bool whether the user can perform the operation as specified by the given permission.
|
|
55
|
+
*/
|
|
56
|
+
can(permissionName: string, params?: never[], allowCaching?: boolean): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Returns auth manager associated with the user component.
|
|
59
|
+
*
|
|
60
|
+
* By default this is the `authManager` application component.
|
|
61
|
+
* You may override this method to return a different auth manager instance if needed.
|
|
62
|
+
* @return \yii\rbac\ManagerInterface
|
|
63
|
+
* @since 2.0.6
|
|
64
|
+
*/
|
|
65
|
+
protected getAuthManager(): AuthManager;
|
|
66
|
+
/**
|
|
67
|
+
* Returns the access checker used for checking access.
|
|
68
|
+
* @return CheckAccessInterface
|
|
69
|
+
*/
|
|
70
|
+
protected getAccessChecker(): AuthManager;
|
|
71
|
+
}
|
|
72
72
|
//# sourceMappingURL=WebUser.d.ts.map
|
package/web/WebUser.js
CHANGED
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.WebUser = void 0;
|
|
16
|
-
/*
|
|
17
|
-
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
18
|
-
* Author: Cihan Ozturk
|
|
19
|
-
* E-mail: cihan@chy.com.tr
|
|
20
|
-
* Github:https://github.com/cihan53/
|
|
21
|
-
*/
|
|
22
|
-
const BaseChyz_1 = __importDefault(require("../BaseChyz"));
|
|
23
|
-
const Component_1 = require("../base/Component");
|
|
24
|
-
const ForbiddenHttpException_1 = require("../base/ForbiddenHttpException");
|
|
25
|
-
const InvalidConfigException_1 = require("../base/InvalidConfigException");
|
|
26
|
-
const Utils_1 = require("../requiments/Utils");
|
|
27
|
-
class WebUser extends Component_1.Component {
|
|
28
|
-
constructor() {
|
|
29
|
-
super(...arguments);
|
|
30
|
-
/**
|
|
31
|
-
* @var CheckAccessInterface|string|array The access checker object to use for checking access or the application
|
|
32
|
-
* component ID of the access checker.
|
|
33
|
-
* If not set the application auth manager will be used.
|
|
34
|
-
* @since 2.0.9
|
|
35
|
-
*/
|
|
36
|
-
this.accessChecker = null;
|
|
37
|
-
}
|
|
38
|
-
get identity() {
|
|
39
|
-
return this._identity;
|
|
40
|
-
}
|
|
41
|
-
set identity(value) {
|
|
42
|
-
this._identity = value;
|
|
43
|
-
}
|
|
44
|
-
init() {
|
|
45
|
-
super.init();
|
|
46
|
-
if (this.identityClass === null) {
|
|
47
|
-
throw new InvalidConfigException_1.InvalidConfigException('User::identityClass must be set.');
|
|
48
|
-
}
|
|
49
|
-
this.identityClass = new this.identityClass();
|
|
50
|
-
}
|
|
51
|
-
getIsGuest() {
|
|
52
|
-
return this.getIdentity() === null;
|
|
53
|
-
}
|
|
54
|
-
getIdentity(autoRenew = true) {
|
|
55
|
-
return this._identity;
|
|
56
|
-
}
|
|
57
|
-
loginRequired() {
|
|
58
|
-
throw new ForbiddenHttpException_1.ForbiddenHttpException(BaseChyz_1.default.t('Login Required'));
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Regenerates CSRF token
|
|
62
|
-
*
|
|
63
|
-
* @since 2.0.14.2
|
|
64
|
-
*/
|
|
65
|
-
regenerateCsrfToken() {
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Logs in a user by the given access token.
|
|
69
|
-
* @param token
|
|
70
|
-
* @param type
|
|
71
|
-
*/
|
|
72
|
-
loginByAccessToken(token, type = null) {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
let $class = this.identityClass;
|
|
75
|
-
if ($class.findIdentityByAccessToken) {
|
|
76
|
-
this.identity = yield $class.findIdentityByAccessToken(token, type);
|
|
77
|
-
if (this.identity && this.login(this.identity)) {
|
|
78
|
-
return this.identity;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
BaseChyz_1.default.error("WebUser::findIdentityByAccessToken undefined");
|
|
83
|
-
}
|
|
84
|
-
return null;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
login(identity, duration = 0) {
|
|
88
|
-
if (this.beforeLogin(identity, false, duration)) {
|
|
89
|
-
}
|
|
90
|
-
return !this.getIsGuest();
|
|
91
|
-
}
|
|
92
|
-
beforeLogin(identity, cookieBased, duration) {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
afterLogin() {
|
|
96
|
-
}
|
|
97
|
-
getId() {
|
|
98
|
-
let identity = this.getIdentity();
|
|
99
|
-
return identity !== null ? identity.id : null;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Checks if the user can perform the operation as specified by the given permission.
|
|
103
|
-
*
|
|
104
|
-
* Note that you must configure "authManager" application component in order to use this method.
|
|
105
|
-
* Otherwise it will always return false.
|
|
106
|
-
*
|
|
107
|
-
* @param string $permissionName the name of the permission (e.g. "edit post") that needs access check.
|
|
108
|
-
* @param array $params name-value pairs that would be passed to the rules associated
|
|
109
|
-
* with the roles and permissions assigned to the user.
|
|
110
|
-
* @param bool $allowCaching whether to allow caching the result of access check.
|
|
111
|
-
* When this parameter is true (default), if the access check of an operation was performed
|
|
112
|
-
* before, its result will be directly returned when calling this method to check the same
|
|
113
|
-
* operation. If this parameter is false, this method will always call
|
|
114
|
-
* [[\yii\rbac\CheckAccessInterface::checkAccess()]] to obtain the up-to-date access result. Note that this
|
|
115
|
-
* caching is effective only within the same request and only works when `$params = []`.
|
|
116
|
-
* @return bool whether the user can perform the operation as specified by the given permission.
|
|
117
|
-
*/
|
|
118
|
-
// public function can($permissionName, $params = [], $allowCaching = true)
|
|
119
|
-
// {
|
|
120
|
-
// if ($allowCaching && empty($params) && isset($this->_access[$permissionName])) {
|
|
121
|
-
// return $this->_access[$permissionName];
|
|
122
|
-
// }
|
|
123
|
-
// if (($accessChecker = $this->getAccessChecker()) === null) {
|
|
124
|
-
// return false;
|
|
125
|
-
// }
|
|
126
|
-
// $access = $accessChecker->checkAccess($this->getId(), $permissionName, $params);
|
|
127
|
-
// if ($allowCaching && empty($params)) {
|
|
128
|
-
// $this->_access[$permissionName] = $access;
|
|
129
|
-
// }
|
|
130
|
-
//
|
|
131
|
-
// return $access;
|
|
132
|
-
// }
|
|
133
|
-
can(permissionName, params = [], allowCaching = true) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
let access;
|
|
136
|
-
let accessChecker;
|
|
137
|
-
if ((accessChecker = this.getAccessChecker()) == null)
|
|
138
|
-
return false;
|
|
139
|
-
access = yield accessChecker.checkAccess(this.getId(), permissionName, params);
|
|
140
|
-
if (allowCaching && Utils_1.Utils.isEmpty(params)) {
|
|
141
|
-
// this._access[$permissionName] = $access;
|
|
142
|
-
}
|
|
143
|
-
return access;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Returns auth manager associated with the user component.
|
|
148
|
-
*
|
|
149
|
-
* By default this is the `authManager` application component.
|
|
150
|
-
* You may override this method to return a different auth manager instance if needed.
|
|
151
|
-
* @return \yii\rbac\ManagerInterface
|
|
152
|
-
* @since 2.0.6
|
|
153
|
-
*/
|
|
154
|
-
getAuthManager() {
|
|
155
|
-
return BaseChyz_1.default.getComponent('authManager');
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Returns the access checker used for checking access.
|
|
159
|
-
* @return CheckAccessInterface
|
|
160
|
-
*/
|
|
161
|
-
getAccessChecker() {
|
|
162
|
-
return this.accessChecker !== null ? this.accessChecker : this.getAuthManager();
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
exports.WebUser = WebUser;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.WebUser = void 0;
|
|
16
|
+
/*
|
|
17
|
+
* Copyright (c) 2021. Chy Bilgisayar Bilisim
|
|
18
|
+
* Author: Cihan Ozturk
|
|
19
|
+
* E-mail: cihan@chy.com.tr
|
|
20
|
+
* Github:https://github.com/cihan53/
|
|
21
|
+
*/
|
|
22
|
+
const BaseChyz_1 = __importDefault(require("../BaseChyz"));
|
|
23
|
+
const Component_1 = require("../base/Component");
|
|
24
|
+
const ForbiddenHttpException_1 = require("../base/ForbiddenHttpException");
|
|
25
|
+
const InvalidConfigException_1 = require("../base/InvalidConfigException");
|
|
26
|
+
const Utils_1 = require("../requiments/Utils");
|
|
27
|
+
class WebUser extends Component_1.Component {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
/**
|
|
31
|
+
* @var CheckAccessInterface|string|array The access checker object to use for checking access or the application
|
|
32
|
+
* component ID of the access checker.
|
|
33
|
+
* If not set the application auth manager will be used.
|
|
34
|
+
* @since 2.0.9
|
|
35
|
+
*/
|
|
36
|
+
this.accessChecker = null;
|
|
37
|
+
}
|
|
38
|
+
get identity() {
|
|
39
|
+
return this._identity;
|
|
40
|
+
}
|
|
41
|
+
set identity(value) {
|
|
42
|
+
this._identity = value;
|
|
43
|
+
}
|
|
44
|
+
init() {
|
|
45
|
+
super.init();
|
|
46
|
+
if (this.identityClass === null) {
|
|
47
|
+
throw new InvalidConfigException_1.InvalidConfigException('User::identityClass must be set.');
|
|
48
|
+
}
|
|
49
|
+
this.identityClass = new this.identityClass();
|
|
50
|
+
}
|
|
51
|
+
getIsGuest() {
|
|
52
|
+
return this.getIdentity() === null;
|
|
53
|
+
}
|
|
54
|
+
getIdentity(autoRenew = true) {
|
|
55
|
+
return this._identity;
|
|
56
|
+
}
|
|
57
|
+
loginRequired() {
|
|
58
|
+
throw new ForbiddenHttpException_1.ForbiddenHttpException(BaseChyz_1.default.t('Login Required'));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Regenerates CSRF token
|
|
62
|
+
*
|
|
63
|
+
* @since 2.0.14.2
|
|
64
|
+
*/
|
|
65
|
+
regenerateCsrfToken() {
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Logs in a user by the given access token.
|
|
69
|
+
* @param token
|
|
70
|
+
* @param type
|
|
71
|
+
*/
|
|
72
|
+
loginByAccessToken(token, type = null) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
let $class = this.identityClass;
|
|
75
|
+
if ($class.findIdentityByAccessToken) {
|
|
76
|
+
this.identity = yield $class.findIdentityByAccessToken(token, type);
|
|
77
|
+
if (this.identity && this.login(this.identity)) {
|
|
78
|
+
return this.identity;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
BaseChyz_1.default.error("WebUser::findIdentityByAccessToken undefined");
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
login(identity, duration = 0) {
|
|
88
|
+
if (this.beforeLogin(identity, false, duration)) {
|
|
89
|
+
}
|
|
90
|
+
return !this.getIsGuest();
|
|
91
|
+
}
|
|
92
|
+
beforeLogin(identity, cookieBased, duration) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
afterLogin() {
|
|
96
|
+
}
|
|
97
|
+
getId() {
|
|
98
|
+
let identity = this.getIdentity();
|
|
99
|
+
return identity !== null ? identity.id : null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Checks if the user can perform the operation as specified by the given permission.
|
|
103
|
+
*
|
|
104
|
+
* Note that you must configure "authManager" application component in order to use this method.
|
|
105
|
+
* Otherwise it will always return false.
|
|
106
|
+
*
|
|
107
|
+
* @param string $permissionName the name of the permission (e.g. "edit post") that needs access check.
|
|
108
|
+
* @param array $params name-value pairs that would be passed to the rules associated
|
|
109
|
+
* with the roles and permissions assigned to the user.
|
|
110
|
+
* @param bool $allowCaching whether to allow caching the result of access check.
|
|
111
|
+
* When this parameter is true (default), if the access check of an operation was performed
|
|
112
|
+
* before, its result will be directly returned when calling this method to check the same
|
|
113
|
+
* operation. If this parameter is false, this method will always call
|
|
114
|
+
* [[\yii\rbac\CheckAccessInterface::checkAccess()]] to obtain the up-to-date access result. Note that this
|
|
115
|
+
* caching is effective only within the same request and only works when `$params = []`.
|
|
116
|
+
* @return bool whether the user can perform the operation as specified by the given permission.
|
|
117
|
+
*/
|
|
118
|
+
// public function can($permissionName, $params = [], $allowCaching = true)
|
|
119
|
+
// {
|
|
120
|
+
// if ($allowCaching && empty($params) && isset($this->_access[$permissionName])) {
|
|
121
|
+
// return $this->_access[$permissionName];
|
|
122
|
+
// }
|
|
123
|
+
// if (($accessChecker = $this->getAccessChecker()) === null) {
|
|
124
|
+
// return false;
|
|
125
|
+
// }
|
|
126
|
+
// $access = $accessChecker->checkAccess($this->getId(), $permissionName, $params);
|
|
127
|
+
// if ($allowCaching && empty($params)) {
|
|
128
|
+
// $this->_access[$permissionName] = $access;
|
|
129
|
+
// }
|
|
130
|
+
//
|
|
131
|
+
// return $access;
|
|
132
|
+
// }
|
|
133
|
+
can(permissionName, params = [], allowCaching = true) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
let access;
|
|
136
|
+
let accessChecker;
|
|
137
|
+
if ((accessChecker = this.getAccessChecker()) == null)
|
|
138
|
+
return false;
|
|
139
|
+
access = yield accessChecker.checkAccess(this.getId(), permissionName, params);
|
|
140
|
+
if (allowCaching && Utils_1.Utils.isEmpty(params)) {
|
|
141
|
+
// this._access[$permissionName] = $access;
|
|
142
|
+
}
|
|
143
|
+
return access;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Returns auth manager associated with the user component.
|
|
148
|
+
*
|
|
149
|
+
* By default this is the `authManager` application component.
|
|
150
|
+
* You may override this method to return a different auth manager instance if needed.
|
|
151
|
+
* @return \yii\rbac\ManagerInterface
|
|
152
|
+
* @since 2.0.6
|
|
153
|
+
*/
|
|
154
|
+
getAuthManager() {
|
|
155
|
+
return BaseChyz_1.default.getComponent('authManager');
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Returns the access checker used for checking access.
|
|
159
|
+
* @return CheckAccessInterface
|
|
160
|
+
*/
|
|
161
|
+
getAccessChecker() {
|
|
162
|
+
return this.accessChecker !== null ? this.accessChecker : this.getAuthManager();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.WebUser = WebUser;
|