cgserver 8.6.8 → 8.6.10
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/README.md +4 -0
- package/dist/lib/Framework/AI/AiObject.js +10 -10
- package/dist/lib/Framework/AI/Astar.js +133 -133
- package/dist/lib/Framework/AI/BehaviorAI.js +307 -307
- package/dist/lib/Framework/AI/Entity.js +33 -33
- package/dist/lib/Framework/AI/Point.js +68 -68
- package/dist/lib/Framework/AI/TriggerMgr.js +201 -201
- package/dist/lib/Framework/Config/Config.js +53 -53
- package/dist/lib/Framework/Config/DbConfig.js +14 -0
- package/dist/lib/Framework/Config/FrameworkConfig.js +207 -240
- package/dist/lib/Framework/Config/IServerConfig.js +26 -26
- package/dist/lib/Framework/Config/_error_.js +35 -35
- package/dist/lib/Framework/Core/Core.js +639 -639
- package/dist/lib/Framework/Core/Timer.js +116 -116
- package/dist/lib/Framework/Database/Decorator/AutoIncrement.js +11 -11
- package/dist/lib/Framework/Database/Decorator/DBCache.js +64 -64
- package/dist/lib/Framework/Database/Decorator/NotNull.js +11 -11
- package/dist/lib/Framework/Database/Decorator/PrimaryKey.js +11 -11
- package/dist/lib/Framework/Database/Decorator/Property.js +61 -61
- package/dist/lib/Framework/Database/Decorator/Table.js +15 -15
- package/dist/lib/Framework/Database/Decorator/Type.js +20 -20
- package/dist/lib/Framework/Database/MSSqlManager.js +53 -43
- package/dist/lib/Framework/Database/MongoBaseService.js +117 -117
- package/dist/lib/Framework/Database/MongoManager.js +462 -462
- package/dist/lib/Framework/Database/MysqlBaseService.js +281 -281
- package/dist/lib/Framework/Database/MysqlManager.js +179 -180
- package/dist/lib/Framework/Database/RedisManager.js +61 -53
- package/dist/lib/Framework/Decorator/AdminValidate.js +19 -19
- package/dist/lib/Framework/Decorator/AuthorityValidate.js +22 -22
- package/dist/lib/Framework/Decorator/CreatorValidate.js +19 -19
- package/dist/lib/Framework/Decorator/JsonAdminValidate.js +15 -15
- package/dist/lib/Framework/Decorator/JsonAuthorityValidate.js +20 -20
- package/dist/lib/Framework/Decorator/JsonCreatorValidate.js +19 -19
- package/dist/lib/Framework/Decorator/SyncCall.js +42 -42
- package/dist/lib/Framework/Decorator/SyncCallServer.js +77 -77
- package/dist/lib/Framework/Logic/CacheTool.js +73 -73
- package/dist/lib/Framework/Logic/EventTool.js +27 -27
- package/dist/lib/Framework/Logic/HttpTool.js +75 -75
- package/dist/lib/Framework/Logic/Log.js +140 -140
- package/dist/lib/Framework/Logic/SyncQueueTool.js +43 -43
- package/dist/lib/Framework/Service/MongoAccountService.js +367 -367
- package/dist/lib/Framework/Service/MongoCacheService.js +42 -42
- package/dist/lib/Framework/Service/MongoUserService.js +100 -100
- package/dist/lib/Framework/Service/MysqlAccountService.js +441 -441
- package/dist/lib/Framework/Service/MysqlUserService.js +171 -171
- package/dist/lib/Framework/Service/ini.js +36 -36
- package/dist/lib/Framework/SocketServer/IClientWebSocket.js +44 -44
- package/dist/lib/Framework/SocketServer/IRpc.js +12 -12
- package/dist/lib/Framework/SocketServer/IRpcClientWebSocket.js +63 -63
- package/dist/lib/Framework/SocketServer/IRpcServerWebSocket.js +63 -63
- package/dist/lib/Framework/SocketServer/IServerWebSocket.js +75 -75
- package/dist/lib/Framework/SocketServer/ISocketServer.js +205 -202
- package/dist/lib/Framework/SocketServer/IWebSocket.js +195 -195
- package/dist/lib/Framework/SocketServer/ProtoFilter/GoogleProtoFilter.js +57 -57
- package/dist/lib/Framework/SocketServer/ProtoFilter/IProtoFilter.js +8 -8
- package/dist/lib/Framework/SocketServer/ProtoFilter/JsonProtoFilter.js +29 -29
- package/dist/lib/Framework/SocketServer/ProtoFilter/ProtoFactory.js +31 -31
- package/dist/lib/Framework/ThirdParty/AlipayTool.js +203 -203
- package/dist/lib/Framework/ThirdParty/Alisms.js +46 -46
- package/dist/lib/Framework/ThirdParty/AppleTool.js +234 -234
- package/dist/lib/Framework/ThirdParty/CgMq.js +132 -132
- package/dist/lib/Framework/ThirdParty/EmailTool.js +33 -33
- package/dist/lib/Framework/ThirdParty/OpenSocial.js +32 -32
- package/dist/lib/Framework/ThirdParty/QQTool.js +118 -118
- package/dist/lib/Framework/ThirdParty/QiniuTool.js +21 -21
- package/dist/lib/Framework/ThirdParty/Rpc.js +63 -63
- package/dist/lib/Framework/ThirdParty/WechatOATool.js +61 -61
- package/dist/lib/Framework/ThirdParty/WechatTool.js +74 -74
- package/dist/lib/Framework/WebServer/Controller/BaseController.js +112 -112
- package/dist/lib/Framework/WebServer/Controller/MongoBaseUserController.js +169 -169
- package/dist/lib/Framework/WebServer/Controller/MysqlBaseUserController.js +169 -169
- package/dist/lib/Framework/WebServer/Engine/ControllerManager.js +112 -112
- package/dist/lib/Framework/WebServer/Engine/Engine.js +152 -152
- package/dist/lib/Framework/WebServer/Engine/RazorJs.js +544 -544
- package/dist/lib/Framework/WebServer/Engine/Request.js +237 -237
- package/dist/lib/Framework/WebServer/Engine/Response.js +100 -100
- package/dist/lib/Framework/WebServer/IWebServer.js +59 -54
- package/dist/lib/Framework/cgserver.js +121 -111
- package/dist/lib/Framework/index.js +201 -191
- package/dist/lib/test/test.js +21 -21
- package/dist/types/Framework/AI/AiObject.d.ts +5 -5
- package/dist/types/Framework/AI/Astar.d.ts +38 -38
- package/dist/types/Framework/AI/BehaviorAI.d.ts +24 -24
- package/dist/types/Framework/AI/Entity.d.ts +12 -12
- package/dist/types/Framework/AI/Point.d.ts +17 -17
- package/dist/types/Framework/AI/TriggerMgr.d.ts +52 -52
- package/dist/types/Framework/Config/Config.d.ts +12 -12
- package/dist/types/Framework/Config/DbConfig.d.ts +10 -0
- package/dist/types/Framework/Config/FrameworkConfig.d.ts +203 -228
- package/dist/types/Framework/Config/IServerConfig.d.ts +9 -9
- package/dist/types/Framework/Config/_error_.d.ts +99 -99
- package/dist/types/Framework/Core/Core.d.ts +108 -108
- package/dist/types/Framework/Core/Timer.d.ts +16 -16
- package/dist/types/Framework/Database/Decorator/AutoIncrement.d.ts +1 -1
- package/dist/types/Framework/Database/Decorator/DBCache.d.ts +23 -23
- package/dist/types/Framework/Database/Decorator/NotNull.d.ts +1 -1
- package/dist/types/Framework/Database/Decorator/PrimaryKey.d.ts +1 -1
- package/dist/types/Framework/Database/Decorator/Property.d.ts +57 -57
- package/dist/types/Framework/Database/Decorator/Table.d.ts +1 -1
- package/dist/types/Framework/Database/Decorator/Type.d.ts +1 -1
- package/dist/types/Framework/Database/MSSqlManager.d.ts +27 -17
- package/dist/types/Framework/Database/MongoBaseService.d.ts +81 -81
- package/dist/types/Framework/Database/MongoManager.d.ts +156 -156
- package/dist/types/Framework/Database/MysqlBaseService.d.ts +34 -34
- package/dist/types/Framework/Database/MysqlManager.d.ts +53 -41
- package/dist/types/Framework/Database/RedisManager.d.ts +24 -17
- package/dist/types/Framework/Decorator/AdminValidate.d.ts +1 -1
- package/dist/types/Framework/Decorator/AuthorityValidate.d.ts +2 -2
- package/dist/types/Framework/Decorator/CreatorValidate.d.ts +1 -1
- package/dist/types/Framework/Decorator/JsonAdminValidate.d.ts +1 -1
- package/dist/types/Framework/Decorator/JsonAuthorityValidate.d.ts +2 -2
- package/dist/types/Framework/Decorator/JsonCreatorValidate.d.ts +1 -1
- package/dist/types/Framework/Decorator/SyncCall.d.ts +12 -12
- package/dist/types/Framework/Decorator/SyncCallServer.d.ts +14 -14
- package/dist/types/Framework/Logic/CacheTool.d.ts +27 -27
- package/dist/types/Framework/Logic/EventTool.d.ts +13 -13
- package/dist/types/Framework/Logic/HttpTool.d.ts +15 -15
- package/dist/types/Framework/Logic/Log.d.ts +25 -25
- package/dist/types/Framework/Logic/SyncQueueTool.d.ts +21 -21
- package/dist/types/Framework/Service/MongoAccountService.d.ts +69 -69
- package/dist/types/Framework/Service/MongoCacheService.d.ts +14 -14
- package/dist/types/Framework/Service/MongoUserService.d.ts +35 -35
- package/dist/types/Framework/Service/MysqlAccountService.d.ts +74 -74
- package/dist/types/Framework/Service/MysqlUserService.d.ts +33 -33
- package/dist/types/Framework/Service/ini.d.ts +29 -29
- package/dist/types/Framework/SocketServer/IClientWebSocket.d.ts +17 -17
- package/dist/types/Framework/SocketServer/IRpc.d.ts +8 -8
- package/dist/types/Framework/SocketServer/IRpcClientWebSocket.d.ts +16 -16
- package/dist/types/Framework/SocketServer/IRpcServerWebSocket.d.ts +16 -16
- package/dist/types/Framework/SocketServer/IServerWebSocket.d.ts +28 -28
- package/dist/types/Framework/SocketServer/ISocketServer.d.ts +45 -45
- package/dist/types/Framework/SocketServer/IWebSocket.d.ts +60 -60
- package/dist/types/Framework/SocketServer/ProtoFilter/GoogleProtoFilter.d.ts +9 -9
- package/dist/types/Framework/SocketServer/ProtoFilter/IProtoFilter.d.ts +9 -9
- package/dist/types/Framework/SocketServer/ProtoFilter/JsonProtoFilter.d.ts +6 -6
- package/dist/types/Framework/SocketServer/ProtoFilter/ProtoFactory.d.ts +8 -8
- package/dist/types/Framework/ThirdParty/AlipayTool.d.ts +109 -109
- package/dist/types/Framework/ThirdParty/Alisms.d.ts +14 -14
- package/dist/types/Framework/ThirdParty/AppleTool.d.ts +131 -131
- package/dist/types/Framework/ThirdParty/CgMq.d.ts +51 -51
- package/dist/types/Framework/ThirdParty/EmailTool.d.ts +5 -5
- package/dist/types/Framework/ThirdParty/OpenSocial.d.ts +7 -7
- package/dist/types/Framework/ThirdParty/QQTool.d.ts +41 -41
- package/dist/types/Framework/ThirdParty/QiniuTool.d.ts +6 -6
- package/dist/types/Framework/ThirdParty/Rpc.d.ts +20 -20
- package/dist/types/Framework/ThirdParty/WechatOATool.d.ts +13 -13
- package/dist/types/Framework/ThirdParty/WechatTool.d.ts +20 -20
- package/dist/types/Framework/WebServer/Controller/BaseController.d.ts +33 -33
- package/dist/types/Framework/WebServer/Controller/MongoBaseUserController.d.ts +27 -27
- package/dist/types/Framework/WebServer/Controller/MysqlBaseUserController.d.ts +27 -27
- package/dist/types/Framework/WebServer/Engine/ControllerManager.d.ts +35 -35
- package/dist/types/Framework/WebServer/Engine/Engine.d.ts +21 -21
- package/dist/types/Framework/WebServer/Engine/RazorJs.d.ts +21 -21
- package/dist/types/Framework/WebServer/Engine/Request.d.ts +35 -35
- package/dist/types/Framework/WebServer/Engine/Response.d.ts +30 -30
- package/dist/types/Framework/WebServer/IWebServer.d.ts +20 -20
- package/dist/types/Framework/cgserver.d.ts +27 -25
- package/dist/types/Framework/index.d.ts +91 -86
- package/dist/types/test/test.d.ts +1 -1
- package/package.json +29 -32
|
@@ -1,169 +1,169 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MysqlBaseUserController = void 0;
|
|
4
|
-
const BaseController_1 = require("./BaseController");
|
|
5
|
-
const MysqlUserService_1 = require("../../Service/MysqlUserService");
|
|
6
|
-
const CacheTool_1 = require("../../Logic/CacheTool");
|
|
7
|
-
const FrameworkConfig_1 = require("../../Config/FrameworkConfig");
|
|
8
|
-
const RedisManager_1 = require("../../Database/RedisManager");
|
|
9
|
-
const MongoCacheService_1 = require("../../Service/MongoCacheService");
|
|
10
|
-
const ini_1 = require("../../Service/ini");
|
|
11
|
-
class MysqlBaseUserController extends BaseController_1.BaseController {
|
|
12
|
-
_user_session_id = "user_session_id";
|
|
13
|
-
_self_user = null;
|
|
14
|
-
_user = null; //网页内容的所属,比如,查看别人的博客,那这个信息就是作者的
|
|
15
|
-
_session_id = null;
|
|
16
|
-
get selfUser() {
|
|
17
|
-
return this._self_user;
|
|
18
|
-
}
|
|
19
|
-
get isSelf() {
|
|
20
|
-
return this._self_user && (this._self_user.id == this._user.id);
|
|
21
|
-
}
|
|
22
|
-
get isLogin() {
|
|
23
|
-
return this._self_user && true;
|
|
24
|
-
}
|
|
25
|
-
get isCreator() {
|
|
26
|
-
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Creator);
|
|
27
|
-
}
|
|
28
|
-
get isAdmin() {
|
|
29
|
-
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Admin || this._self_user.role_group == ini_1.ERoleGroup.Creator);
|
|
30
|
-
}
|
|
31
|
-
get isProxy() {
|
|
32
|
-
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Proxy);
|
|
33
|
-
}
|
|
34
|
-
get isCommon() {
|
|
35
|
-
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Common);
|
|
36
|
-
}
|
|
37
|
-
async init() {
|
|
38
|
-
this._engine.cfg.session_type = this._engine.cfg.session_type || FrameworkConfig_1.ESessionType.Cache;
|
|
39
|
-
this._session_id = this._request.getCookie(this._user_session_id) || this._request.params.session_id || this._request.postData.session_id;
|
|
40
|
-
let userId = -1;
|
|
41
|
-
if (this._session_id) {
|
|
42
|
-
let user = await this._getUserBySession(this._session_id);
|
|
43
|
-
if (!user) {
|
|
44
|
-
this._update_session();
|
|
45
|
-
//Session不存在清除客户端cookie
|
|
46
|
-
this._response.clearCookie(this._user_session_id);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
this._login(user);
|
|
50
|
-
userId = user.id;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
let params = this._request.params;
|
|
54
|
-
if (params.userId && params.userId != userId + "") {
|
|
55
|
-
this._user = (await MysqlUserService_1.GUserSer.getById(params.userId));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
//不是别人的信息就查看自己的
|
|
59
|
-
this._user = this._self_user;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async _getUserBySession(session) {
|
|
63
|
-
let user = null;
|
|
64
|
-
if (!session) {
|
|
65
|
-
return user;
|
|
66
|
-
}
|
|
67
|
-
//每次强制从cache中先找,提高效率
|
|
68
|
-
//if(this._engine.cfg.session_type==ESessionType.Cache)
|
|
69
|
-
{
|
|
70
|
-
user = CacheTool_1.GCacheTool.get(this._session_id);
|
|
71
|
-
}
|
|
72
|
-
if (user) {
|
|
73
|
-
return user;
|
|
74
|
-
}
|
|
75
|
-
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
76
|
-
let user_id = parseInt((await RedisManager_1.GRedisMgr.get(this._session_id)) || "-1");
|
|
77
|
-
if (user_id > 0) {
|
|
78
|
-
user = (await MysqlUserService_1.GUserSer.getById(user_id));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
82
|
-
let user_id = (await MongoCacheService_1.GMongoCacheSer.getData(this._session_id)) || -1;
|
|
83
|
-
if (user_id > 0) {
|
|
84
|
-
user = (await MysqlUserService_1.GUserSer.getById(user_id));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (user) {
|
|
88
|
-
this._login(user);
|
|
89
|
-
}
|
|
90
|
-
return user;
|
|
91
|
-
}
|
|
92
|
-
_logout() {
|
|
93
|
-
if (this._session_id) {
|
|
94
|
-
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
|
|
95
|
-
CacheTool_1.GCacheTool.remove(this._session_id);
|
|
96
|
-
}
|
|
97
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
98
|
-
RedisManager_1.GRedisMgr.del(this._session_id);
|
|
99
|
-
}
|
|
100
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
101
|
-
MongoCacheService_1.GMongoCacheSer.deleteOne({ key: this._session_id });
|
|
102
|
-
}
|
|
103
|
-
this._session_id = null;
|
|
104
|
-
}
|
|
105
|
-
this._response.clearCookie(this._user_session_id);
|
|
106
|
-
}
|
|
107
|
-
_login(user) {
|
|
108
|
-
if (!user) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (!this._session_id) {
|
|
112
|
-
this._session_id = Math.random().toString(36).substring(2) + user.id;
|
|
113
|
-
}
|
|
114
|
-
let time = 0;
|
|
115
|
-
if (this._request.postData.remember == "on") {
|
|
116
|
-
time = this._engine.cfg.cookie.expires.account_remember;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
time = this._engine.cfg.cookie.expires.account;
|
|
120
|
-
}
|
|
121
|
-
this._response.setCookie(this._user_session_id, this._session_id, time);
|
|
122
|
-
//if(this._engine.cfg.session_type==ESessionType.Cache)
|
|
123
|
-
{
|
|
124
|
-
if (time > 24 * 60 * 60) {
|
|
125
|
-
CacheTool_1.GCacheTool.add(this._session_id, user, 24 * 60 * 60 * 1000);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
CacheTool_1.GCacheTool.add(this._session_id, user, time * 1000);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
132
|
-
RedisManager_1.GRedisMgr.set(this._session_id, user.id).then(() => {
|
|
133
|
-
RedisManager_1.GRedisMgr.expire(this._session_id, time);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
137
|
-
let cm = new MongoCacheService_1.MongoCacheModel();
|
|
138
|
-
cm.key = this._session_id;
|
|
139
|
-
cm.data = user.id;
|
|
140
|
-
cm.expireAt = Date.now() + time * 1000;
|
|
141
|
-
MongoCacheService_1.GMongoCacheSer.updateOne(cm, { key: cm.key }, true);
|
|
142
|
-
}
|
|
143
|
-
this._self_user = user;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* 已经被启用
|
|
147
|
-
*/
|
|
148
|
-
async _update_session() {
|
|
149
|
-
}
|
|
150
|
-
async update_user(user_id) {
|
|
151
|
-
let user = (await MysqlUserService_1.GUserSer.getById(user_id));
|
|
152
|
-
if (this._user && this._user.id == user.id) {
|
|
153
|
-
this._user = user;
|
|
154
|
-
}
|
|
155
|
-
if (this._self_user && this._self_user.id == user.id) {
|
|
156
|
-
this._login(user);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
//填充每个页面需要的通用数据
|
|
160
|
-
_init_data(datas) {
|
|
161
|
-
let data = super._init_data(datas);
|
|
162
|
-
data.model.isLogin = this.isLogin;
|
|
163
|
-
data.model.user = this._user;
|
|
164
|
-
data.model.selfUser = this._self_user;
|
|
165
|
-
data.model.isSelf = this.isSelf;
|
|
166
|
-
return data;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.MysqlBaseUserController = MysqlBaseUserController;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MysqlBaseUserController = void 0;
|
|
4
|
+
const BaseController_1 = require("./BaseController");
|
|
5
|
+
const MysqlUserService_1 = require("../../Service/MysqlUserService");
|
|
6
|
+
const CacheTool_1 = require("../../Logic/CacheTool");
|
|
7
|
+
const FrameworkConfig_1 = require("../../Config/FrameworkConfig");
|
|
8
|
+
const RedisManager_1 = require("../../Database/RedisManager");
|
|
9
|
+
const MongoCacheService_1 = require("../../Service/MongoCacheService");
|
|
10
|
+
const ini_1 = require("../../Service/ini");
|
|
11
|
+
class MysqlBaseUserController extends BaseController_1.BaseController {
|
|
12
|
+
_user_session_id = "user_session_id";
|
|
13
|
+
_self_user = null;
|
|
14
|
+
_user = null; //网页内容的所属,比如,查看别人的博客,那这个信息就是作者的
|
|
15
|
+
_session_id = null;
|
|
16
|
+
get selfUser() {
|
|
17
|
+
return this._self_user;
|
|
18
|
+
}
|
|
19
|
+
get isSelf() {
|
|
20
|
+
return this._self_user && (this._self_user.id == this._user.id);
|
|
21
|
+
}
|
|
22
|
+
get isLogin() {
|
|
23
|
+
return this._self_user && true;
|
|
24
|
+
}
|
|
25
|
+
get isCreator() {
|
|
26
|
+
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Creator);
|
|
27
|
+
}
|
|
28
|
+
get isAdmin() {
|
|
29
|
+
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Admin || this._self_user.role_group == ini_1.ERoleGroup.Creator);
|
|
30
|
+
}
|
|
31
|
+
get isProxy() {
|
|
32
|
+
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Proxy);
|
|
33
|
+
}
|
|
34
|
+
get isCommon() {
|
|
35
|
+
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Common);
|
|
36
|
+
}
|
|
37
|
+
async init() {
|
|
38
|
+
this._engine.cfg.session_type = this._engine.cfg.session_type || FrameworkConfig_1.ESessionType.Cache;
|
|
39
|
+
this._session_id = this._request.getCookie(this._user_session_id) || this._request.params.session_id || this._request.postData.session_id;
|
|
40
|
+
let userId = -1;
|
|
41
|
+
if (this._session_id) {
|
|
42
|
+
let user = await this._getUserBySession(this._session_id);
|
|
43
|
+
if (!user) {
|
|
44
|
+
this._update_session();
|
|
45
|
+
//Session不存在清除客户端cookie
|
|
46
|
+
this._response.clearCookie(this._user_session_id);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this._login(user);
|
|
50
|
+
userId = user.id;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
let params = this._request.params;
|
|
54
|
+
if (params.userId && params.userId != userId + "") {
|
|
55
|
+
this._user = (await MysqlUserService_1.GUserSer.getById(params.userId));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
//不是别人的信息就查看自己的
|
|
59
|
+
this._user = this._self_user;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async _getUserBySession(session) {
|
|
63
|
+
let user = null;
|
|
64
|
+
if (!session) {
|
|
65
|
+
return user;
|
|
66
|
+
}
|
|
67
|
+
//每次强制从cache中先找,提高效率
|
|
68
|
+
//if(this._engine.cfg.session_type==ESessionType.Cache)
|
|
69
|
+
{
|
|
70
|
+
user = CacheTool_1.GCacheTool.get(this._session_id);
|
|
71
|
+
}
|
|
72
|
+
if (user) {
|
|
73
|
+
return user;
|
|
74
|
+
}
|
|
75
|
+
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
76
|
+
let user_id = parseInt((await RedisManager_1.GRedisMgr.get(this._session_id)) || "-1");
|
|
77
|
+
if (user_id > 0) {
|
|
78
|
+
user = (await MysqlUserService_1.GUserSer.getById(user_id));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
82
|
+
let user_id = (await MongoCacheService_1.GMongoCacheSer.getData(this._session_id)) || -1;
|
|
83
|
+
if (user_id > 0) {
|
|
84
|
+
user = (await MysqlUserService_1.GUserSer.getById(user_id));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (user) {
|
|
88
|
+
this._login(user);
|
|
89
|
+
}
|
|
90
|
+
return user;
|
|
91
|
+
}
|
|
92
|
+
_logout() {
|
|
93
|
+
if (this._session_id) {
|
|
94
|
+
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
|
|
95
|
+
CacheTool_1.GCacheTool.remove(this._session_id);
|
|
96
|
+
}
|
|
97
|
+
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
98
|
+
RedisManager_1.GRedisMgr.del(this._session_id);
|
|
99
|
+
}
|
|
100
|
+
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
101
|
+
MongoCacheService_1.GMongoCacheSer.deleteOne({ key: this._session_id });
|
|
102
|
+
}
|
|
103
|
+
this._session_id = null;
|
|
104
|
+
}
|
|
105
|
+
this._response.clearCookie(this._user_session_id);
|
|
106
|
+
}
|
|
107
|
+
_login(user) {
|
|
108
|
+
if (!user) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (!this._session_id) {
|
|
112
|
+
this._session_id = Math.random().toString(36).substring(2) + user.id;
|
|
113
|
+
}
|
|
114
|
+
let time = 0;
|
|
115
|
+
if (this._request.postData.remember == "on") {
|
|
116
|
+
time = this._engine.cfg.cookie.expires.account_remember;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
time = this._engine.cfg.cookie.expires.account;
|
|
120
|
+
}
|
|
121
|
+
this._response.setCookie(this._user_session_id, this._session_id, time);
|
|
122
|
+
//if(this._engine.cfg.session_type==ESessionType.Cache)
|
|
123
|
+
{
|
|
124
|
+
if (time > 24 * 60 * 60) {
|
|
125
|
+
CacheTool_1.GCacheTool.add(this._session_id, user, 24 * 60 * 60 * 1000);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
CacheTool_1.GCacheTool.add(this._session_id, user, time * 1000);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
132
|
+
RedisManager_1.GRedisMgr.set(this._session_id, user.id).then(() => {
|
|
133
|
+
RedisManager_1.GRedisMgr.expire(this._session_id, time);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
137
|
+
let cm = new MongoCacheService_1.MongoCacheModel();
|
|
138
|
+
cm.key = this._session_id;
|
|
139
|
+
cm.data = user.id;
|
|
140
|
+
cm.expireAt = Date.now() + time * 1000;
|
|
141
|
+
MongoCacheService_1.GMongoCacheSer.updateOne(cm, { key: cm.key }, true);
|
|
142
|
+
}
|
|
143
|
+
this._self_user = user;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 已经被启用
|
|
147
|
+
*/
|
|
148
|
+
async _update_session() {
|
|
149
|
+
}
|
|
150
|
+
async update_user(user_id) {
|
|
151
|
+
let user = (await MysqlUserService_1.GUserSer.getById(user_id));
|
|
152
|
+
if (this._user && this._user.id == user.id) {
|
|
153
|
+
this._user = user;
|
|
154
|
+
}
|
|
155
|
+
if (this._self_user && this._self_user.id == user.id) {
|
|
156
|
+
this._login(user);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//填充每个页面需要的通用数据
|
|
160
|
+
_init_data(datas) {
|
|
161
|
+
let data = super._init_data(datas);
|
|
162
|
+
data.model.isLogin = this.isLogin;
|
|
163
|
+
data.model.user = this._user;
|
|
164
|
+
data.model.selfUser = this._self_user;
|
|
165
|
+
data.model.isSelf = this.isSelf;
|
|
166
|
+
return data;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.MysqlBaseUserController = MysqlBaseUserController;
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GCtrMgr = void 0;
|
|
4
|
-
exports.GCtrMgr = null;
|
|
5
|
-
class ControllerManager {
|
|
6
|
-
_static_ctr = {};
|
|
7
|
-
_ctr_cls = {};
|
|
8
|
-
//module ctrname lower normal
|
|
9
|
-
_cache_action_names = {};
|
|
10
|
-
registerController(module_name, ctr_name, cls) {
|
|
11
|
-
module_name = module_name.toLowerCase();
|
|
12
|
-
ctr_name = ctr_name.toLowerCase();
|
|
13
|
-
if (module_name == ctr_name) {
|
|
14
|
-
throw ("模块名称不能和控制器名称相同:" + module_name);
|
|
15
|
-
}
|
|
16
|
-
this._ctr_cls[module_name] = this._ctr_cls[module_name] || {};
|
|
17
|
-
this._ctr_cls[module_name][ctr_name] = cls;
|
|
18
|
-
this._cacheActionName(module_name, ctr_name, cls);
|
|
19
|
-
}
|
|
20
|
-
_cacheActionName(module_name, ctr_name, cls) {
|
|
21
|
-
module_name = module_name.toLowerCase();
|
|
22
|
-
ctr_name = ctr_name.toLowerCase();
|
|
23
|
-
//不能通过cls.name来获取ctr名称,因为混淆之后类名会变化
|
|
24
|
-
let prototype = cls.prototype;
|
|
25
|
-
let map_names = {};
|
|
26
|
-
while (prototype && prototype.constructor.name != "BaseController") {
|
|
27
|
-
let names = Object.getOwnPropertyNames(prototype);
|
|
28
|
-
for (let action_name of names) {
|
|
29
|
-
if (action_name.indexOf("on") != 0
|
|
30
|
-
&& action_name.indexOf("show") != 0) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (map_names[action_name.toLowerCase()]) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
map_names[action_name.toLowerCase()] = action_name;
|
|
37
|
-
}
|
|
38
|
-
prototype = Object.getPrototypeOf(prototype);
|
|
39
|
-
}
|
|
40
|
-
this._cache_action_names[module_name] = this._cache_action_names[module_name] || {};
|
|
41
|
-
this._cache_action_names[module_name][ctr_name] = map_names;
|
|
42
|
-
}
|
|
43
|
-
getActionName(module_name, ctr_name, action_name) {
|
|
44
|
-
module_name = module_name.toLowerCase();
|
|
45
|
-
ctr_name = ctr_name.toLowerCase();
|
|
46
|
-
action_name = action_name.toLowerCase();
|
|
47
|
-
if (!this._cache_action_names[module_name]) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
if (!this._cache_action_names[module_name][ctr_name]) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return this._cache_action_names[module_name][ctr_name][action_name];
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* 静态ctr,这样,ctr就不会被多次创建
|
|
57
|
-
* @param module_name
|
|
58
|
-
* @param ctr_name
|
|
59
|
-
* @param obj
|
|
60
|
-
*/
|
|
61
|
-
registerStaticController(module_name, ctr_name, obj) {
|
|
62
|
-
module_name = module_name.toLowerCase();
|
|
63
|
-
ctr_name = ctr_name.toLowerCase();
|
|
64
|
-
this._static_ctr[module_name] = this._static_ctr[module_name] || {};
|
|
65
|
-
this._static_ctr[module_name][ctr_name] = obj;
|
|
66
|
-
this._cacheActionNameForStatic(module_name, ctr_name, obj);
|
|
67
|
-
}
|
|
68
|
-
_cacheActionNameForStatic(module_name, ctr_name, obj) {
|
|
69
|
-
module_name = module_name.toLowerCase();
|
|
70
|
-
ctr_name = ctr_name.toLowerCase();
|
|
71
|
-
let prototype = Object.getPrototypeOf(obj);
|
|
72
|
-
let map_names = {};
|
|
73
|
-
while (prototype && prototype.constructor.name != "BaseController") {
|
|
74
|
-
let names = Object.getOwnPropertyNames(prototype);
|
|
75
|
-
for (let func_name of names) {
|
|
76
|
-
let low_name = func_name.toLowerCase();
|
|
77
|
-
if (!map_names[low_name]) //有可能遭遇重载
|
|
78
|
-
{
|
|
79
|
-
map_names[low_name] = func_name;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
prototype = Object.getPrototypeOf(prototype);
|
|
83
|
-
}
|
|
84
|
-
this._cache_action_names[module_name] = this._cache_action_names[module_name] || {};
|
|
85
|
-
this._cache_action_names[module_name][ctr_name] = map_names;
|
|
86
|
-
}
|
|
87
|
-
getStaticCtr(module_name, controller_name) {
|
|
88
|
-
if (module_name) {
|
|
89
|
-
module_name = module_name.toLowerCase();
|
|
90
|
-
}
|
|
91
|
-
if (controller_name) {
|
|
92
|
-
controller_name = controller_name.toLowerCase();
|
|
93
|
-
}
|
|
94
|
-
if (!this._static_ctr[module_name]) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
return this._static_ctr[module_name][controller_name];
|
|
98
|
-
}
|
|
99
|
-
getClass(module_name, controller_name) {
|
|
100
|
-
if (module_name) {
|
|
101
|
-
module_name = module_name.toLowerCase();
|
|
102
|
-
}
|
|
103
|
-
if (controller_name) {
|
|
104
|
-
controller_name = controller_name.toLowerCase();
|
|
105
|
-
}
|
|
106
|
-
if (!this._ctr_cls[module_name]) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
return this._ctr_cls[module_name][controller_name];
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
exports.GCtrMgr = new ControllerManager();
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GCtrMgr = void 0;
|
|
4
|
+
exports.GCtrMgr = null;
|
|
5
|
+
class ControllerManager {
|
|
6
|
+
_static_ctr = {};
|
|
7
|
+
_ctr_cls = {};
|
|
8
|
+
//module ctrname lower normal
|
|
9
|
+
_cache_action_names = {};
|
|
10
|
+
registerController(module_name, ctr_name, cls) {
|
|
11
|
+
module_name = module_name.toLowerCase();
|
|
12
|
+
ctr_name = ctr_name.toLowerCase();
|
|
13
|
+
if (module_name == ctr_name) {
|
|
14
|
+
throw ("模块名称不能和控制器名称相同:" + module_name);
|
|
15
|
+
}
|
|
16
|
+
this._ctr_cls[module_name] = this._ctr_cls[module_name] || {};
|
|
17
|
+
this._ctr_cls[module_name][ctr_name] = cls;
|
|
18
|
+
this._cacheActionName(module_name, ctr_name, cls);
|
|
19
|
+
}
|
|
20
|
+
_cacheActionName(module_name, ctr_name, cls) {
|
|
21
|
+
module_name = module_name.toLowerCase();
|
|
22
|
+
ctr_name = ctr_name.toLowerCase();
|
|
23
|
+
//不能通过cls.name来获取ctr名称,因为混淆之后类名会变化
|
|
24
|
+
let prototype = cls.prototype;
|
|
25
|
+
let map_names = {};
|
|
26
|
+
while (prototype && prototype.constructor.name != "BaseController") {
|
|
27
|
+
let names = Object.getOwnPropertyNames(prototype);
|
|
28
|
+
for (let action_name of names) {
|
|
29
|
+
if (action_name.indexOf("on") != 0
|
|
30
|
+
&& action_name.indexOf("show") != 0) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (map_names[action_name.toLowerCase()]) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
map_names[action_name.toLowerCase()] = action_name;
|
|
37
|
+
}
|
|
38
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
39
|
+
}
|
|
40
|
+
this._cache_action_names[module_name] = this._cache_action_names[module_name] || {};
|
|
41
|
+
this._cache_action_names[module_name][ctr_name] = map_names;
|
|
42
|
+
}
|
|
43
|
+
getActionName(module_name, ctr_name, action_name) {
|
|
44
|
+
module_name = module_name.toLowerCase();
|
|
45
|
+
ctr_name = ctr_name.toLowerCase();
|
|
46
|
+
action_name = action_name.toLowerCase();
|
|
47
|
+
if (!this._cache_action_names[module_name]) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (!this._cache_action_names[module_name][ctr_name]) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return this._cache_action_names[module_name][ctr_name][action_name];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 静态ctr,这样,ctr就不会被多次创建
|
|
57
|
+
* @param module_name
|
|
58
|
+
* @param ctr_name
|
|
59
|
+
* @param obj
|
|
60
|
+
*/
|
|
61
|
+
registerStaticController(module_name, ctr_name, obj) {
|
|
62
|
+
module_name = module_name.toLowerCase();
|
|
63
|
+
ctr_name = ctr_name.toLowerCase();
|
|
64
|
+
this._static_ctr[module_name] = this._static_ctr[module_name] || {};
|
|
65
|
+
this._static_ctr[module_name][ctr_name] = obj;
|
|
66
|
+
this._cacheActionNameForStatic(module_name, ctr_name, obj);
|
|
67
|
+
}
|
|
68
|
+
_cacheActionNameForStatic(module_name, ctr_name, obj) {
|
|
69
|
+
module_name = module_name.toLowerCase();
|
|
70
|
+
ctr_name = ctr_name.toLowerCase();
|
|
71
|
+
let prototype = Object.getPrototypeOf(obj);
|
|
72
|
+
let map_names = {};
|
|
73
|
+
while (prototype && prototype.constructor.name != "BaseController") {
|
|
74
|
+
let names = Object.getOwnPropertyNames(prototype);
|
|
75
|
+
for (let func_name of names) {
|
|
76
|
+
let low_name = func_name.toLowerCase();
|
|
77
|
+
if (!map_names[low_name]) //有可能遭遇重载
|
|
78
|
+
{
|
|
79
|
+
map_names[low_name] = func_name;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
83
|
+
}
|
|
84
|
+
this._cache_action_names[module_name] = this._cache_action_names[module_name] || {};
|
|
85
|
+
this._cache_action_names[module_name][ctr_name] = map_names;
|
|
86
|
+
}
|
|
87
|
+
getStaticCtr(module_name, controller_name) {
|
|
88
|
+
if (module_name) {
|
|
89
|
+
module_name = module_name.toLowerCase();
|
|
90
|
+
}
|
|
91
|
+
if (controller_name) {
|
|
92
|
+
controller_name = controller_name.toLowerCase();
|
|
93
|
+
}
|
|
94
|
+
if (!this._static_ctr[module_name]) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
return this._static_ctr[module_name][controller_name];
|
|
98
|
+
}
|
|
99
|
+
getClass(module_name, controller_name) {
|
|
100
|
+
if (module_name) {
|
|
101
|
+
module_name = module_name.toLowerCase();
|
|
102
|
+
}
|
|
103
|
+
if (controller_name) {
|
|
104
|
+
controller_name = controller_name.toLowerCase();
|
|
105
|
+
}
|
|
106
|
+
if (!this._ctr_cls[module_name]) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
return this._ctr_cls[module_name][controller_name];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.GCtrMgr = new ControllerManager();
|