cgserver 12.0.8 → 12.2.0
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 +9 -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 +340 -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 +74 -41
- package/dist/lib/Framework/Config/DbConfig.js +14 -14
- package/dist/lib/Framework/Config/FrameworkConfig.js +139 -173
- package/dist/lib/Framework/Config/IServerConfig.js +31 -31
- package/dist/lib/Framework/Config/_error_.js +35 -35
- package/dist/lib/Framework/Core/ByteTool.js +85 -85
- package/dist/lib/Framework/Core/Core.js +724 -688
- package/dist/lib/Framework/Core/Timer.js +116 -116
- package/dist/lib/Framework/Database/Decorator/AutoIncrement.js +10 -11
- package/dist/lib/Framework/Database/Decorator/DBCache.js +98 -65
- package/dist/lib/Framework/Database/Decorator/NotNull.js +10 -11
- package/dist/lib/Framework/Database/Decorator/PrimaryKey.js +10 -11
- package/dist/lib/Framework/Database/Decorator/Property.js +61 -61
- package/dist/lib/Framework/Database/Decorator/Table.js +14 -15
- package/dist/lib/Framework/Database/Decorator/Type.js +19 -20
- package/dist/lib/Framework/Database/MSSql/MSSqlManager.js +86 -53
- package/dist/lib/Framework/Database/Mongo/MongoBaseService.js +141 -141
- package/dist/lib/Framework/Database/Mongo/MongoManager.js +595 -547
- package/dist/lib/Framework/Database/Mongo/MongoServiceManager.js +52 -52
- package/dist/lib/Framework/Database/Mysql/MysqlBaseService.js +280 -280
- package/dist/lib/Framework/Database/Mysql/MysqlManager.js +138 -105
- package/dist/lib/Framework/Database/Redis/RedisManager.js +94 -61
- package/dist/lib/Framework/Decorator/AdminValidate.js +18 -19
- package/dist/lib/Framework/Decorator/AuthorityValidate.js +22 -22
- package/dist/lib/Framework/Decorator/CreatorValidate.js +18 -19
- package/dist/lib/Framework/Decorator/JsonAdminValidate.js +14 -15
- package/dist/lib/Framework/Decorator/JsonAuthorityValidate.js +20 -20
- package/dist/lib/Framework/Decorator/JsonCreatorValidate.js +18 -19
- package/dist/lib/Framework/Decorator/SyncCall.js +41 -42
- package/dist/lib/Framework/Decorator/SyncCallServer.js +77 -77
- package/dist/lib/Framework/Logic/CacheTool.js +106 -73
- package/dist/lib/Framework/Logic/EventTool.js +31 -28
- package/dist/lib/Framework/Logic/HttpTool.js +138 -105
- package/dist/lib/Framework/Logic/Log.js +121 -88
- package/dist/lib/Framework/Logic/SyncQueueTool.js +44 -44
- package/dist/lib/Framework/Server/ProtoFilter/GoogleProtoFilter.js +90 -57
- package/dist/lib/Framework/Server/ProtoFilter/IProtoFilter.js +9 -9
- package/dist/lib/Framework/Server/ProtoFilter/JsonProtoFilter.js +29 -29
- package/dist/lib/Framework/Server/ProtoFilter/ProtoFactory.js +35 -35
- package/dist/lib/Framework/Server/RpcWebSocketServer/CgMq.js +180 -180
- package/dist/lib/Framework/Server/RpcWebSocketServer/IRpc.js +38 -38
- package/dist/lib/Framework/Server/RpcWebSocketServer/IRpcClientWebSocket.js +253 -253
- package/dist/lib/Framework/Server/RpcWebSocketServer/IRpcServerWebSocket.js +94 -94
- package/dist/lib/Framework/Server/SocketServer/IClientSocket.js +44 -44
- package/dist/lib/Framework/Server/SocketServer/IServerSocket.js +114 -81
- package/dist/lib/Framework/Server/SocketServer/ISocket.js +255 -222
- package/dist/lib/Framework/Server/SocketServer/ISocketServer.js +177 -144
- package/dist/lib/Framework/Server/SocketServer/PacketParser.js +40 -40
- package/dist/lib/Framework/Server/WebServer/Controller/BaseController.js +119 -119
- package/dist/lib/Framework/Server/WebServer/Controller/MongoBaseUserController.js +171 -171
- package/dist/lib/Framework/Server/WebServer/Controller/MysqlBaseUserController.js +169 -169
- package/dist/lib/Framework/Server/WebServer/Engine/ControllerManager.js +115 -115
- package/dist/lib/Framework/Server/WebServer/Engine/Engine.js +254 -218
- package/dist/lib/Framework/Server/WebServer/Engine/RazorJs.js +543 -543
- package/dist/lib/Framework/Server/WebServer/Engine/Request.js +226 -226
- package/dist/lib/Framework/Server/WebServer/Engine/Response.js +120 -87
- package/dist/lib/Framework/Server/WebServer/IWebServer.js +55 -55
- package/dist/lib/Framework/Server/WebSocketServer/IClientWebSocket.js +44 -44
- package/dist/lib/Framework/Server/WebSocketServer/IServerWebSocket.js +128 -95
- package/dist/lib/Framework/Server/WebSocketServer/IWebSocket.js +248 -215
- package/dist/lib/Framework/Server/WebSocketServer/IWebSocketServer.js +250 -217
- package/dist/lib/Framework/Service/MongoAccountService.js +339 -339
- package/dist/lib/Framework/Service/MongoCacheService.js +50 -50
- package/dist/lib/Framework/Service/MongoUserService.js +129 -96
- package/dist/lib/Framework/Service/MysqlAccountService.js +411 -411
- package/dist/lib/Framework/Service/MysqlUserService.js +204 -171
- package/dist/lib/Framework/Service/ini.js +36 -36
- package/dist/lib/Framework/ThirdParty/AlipayTool.js +117 -205
- package/dist/lib/Framework/ThirdParty/Alisms.js +61 -50
- package/dist/lib/Framework/ThirdParty/AppleTool.js +271 -235
- package/dist/lib/Framework/ThirdParty/CgRankTool.js +215 -215
- package/dist/lib/Framework/ThirdParty/EmailTool.js +71 -38
- package/dist/lib/Framework/ThirdParty/QQTool.js +162 -129
- package/dist/lib/Framework/ThirdParty/QiniuTool.js +62 -29
- package/dist/lib/Framework/ThirdParty/Rpc.js +79 -79
- package/dist/lib/Framework/ThirdParty/WechatTool.js +167 -134
- package/dist/lib/Framework/cgserver.js +215 -212
- package/dist/lib/Framework/global.js +74 -74
- package/dist/lib/Framework/index.js +38 -5
- package/dist/lib/Framework/index_export_.js +180 -177
- 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 +51 -51
- package/dist/types/Framework/Config/Config.d.ts +9 -9
- package/dist/types/Framework/Config/DbConfig.d.ts +11 -11
- package/dist/types/Framework/Config/FrameworkConfig.d.ts +146 -178
- 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/ByteTool.d.ts +21 -21
- package/dist/types/Framework/Core/Core.d.ts +119 -120
- 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 +22 -22
- 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/MSSql/MSSqlManager.d.ts +26 -26
- package/dist/types/Framework/Database/Mongo/MongoBaseService.d.ts +116 -116
- package/dist/types/Framework/Database/Mongo/MongoManager.d.ts +207 -204
- package/dist/types/Framework/Database/Mongo/MongoServiceManager.d.ts +13 -13
- package/dist/types/Framework/Database/Mysql/MysqlBaseService.d.ts +34 -34
- package/dist/types/Framework/Database/Mysql/MysqlManager.d.ts +30 -30
- package/dist/types/Framework/Database/Redis/RedisManager.d.ts +24 -24
- 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 +11 -12
- package/dist/types/Framework/Logic/HttpTool.d.ts +19 -19
- package/dist/types/Framework/Logic/Log.d.ts +18 -18
- package/dist/types/Framework/Logic/SyncQueueTool.d.ts +21 -21
- package/dist/types/Framework/Server/ProtoFilter/GoogleProtoFilter.d.ts +9 -9
- package/dist/types/Framework/Server/ProtoFilter/IProtoFilter.d.ts +10 -10
- package/dist/types/Framework/Server/ProtoFilter/JsonProtoFilter.d.ts +6 -6
- package/dist/types/Framework/Server/ProtoFilter/ProtoFactory.d.ts +12 -12
- package/dist/types/Framework/Server/RpcWebSocketServer/CgMq.d.ts +59 -59
- package/dist/types/Framework/Server/RpcWebSocketServer/IRpc.d.ts +33 -33
- package/dist/types/Framework/Server/RpcWebSocketServer/IRpcClientWebSocket.d.ts +34 -34
- package/dist/types/Framework/Server/RpcWebSocketServer/IRpcServerWebSocket.d.ts +23 -23
- package/dist/types/Framework/Server/SocketServer/IClientSocket.d.ts +16 -18
- package/dist/types/Framework/Server/SocketServer/IServerSocket.d.ts +27 -29
- package/dist/types/Framework/Server/SocketServer/ISocket.d.ts +78 -81
- package/dist/types/Framework/Server/SocketServer/ISocketServer.d.ts +44 -45
- package/dist/types/Framework/Server/SocketServer/PacketParser.d.ts +8 -10
- package/dist/types/Framework/Server/WebServer/Controller/BaseController.d.ts +34 -34
- package/dist/types/Framework/Server/WebServer/Controller/MongoBaseUserController.d.ts +28 -28
- package/dist/types/Framework/Server/WebServer/Controller/MysqlBaseUserController.d.ts +27 -27
- package/dist/types/Framework/Server/WebServer/Engine/ControllerManager.d.ts +37 -37
- package/dist/types/Framework/Server/WebServer/Engine/Engine.d.ts +42 -44
- package/dist/types/Framework/Server/WebServer/Engine/RazorJs.d.ts +21 -21
- package/dist/types/Framework/Server/WebServer/Engine/Request.d.ts +47 -50
- package/dist/types/Framework/Server/WebServer/Engine/Response.d.ts +26 -26
- package/dist/types/Framework/Server/WebServer/IWebServer.d.ts +22 -22
- package/dist/types/Framework/Server/WebSocketServer/IClientWebSocket.d.ts +17 -17
- package/dist/types/Framework/Server/WebSocketServer/IServerWebSocket.d.ts +37 -38
- package/dist/types/Framework/Server/WebSocketServer/IWebSocket.d.ts +76 -76
- package/dist/types/Framework/Server/WebSocketServer/IWebSocketServer.d.ts +49 -49
- package/dist/types/Framework/Service/MongoAccountService.d.ts +62 -62
- package/dist/types/Framework/Service/MongoCacheService.d.ts +19 -19
- package/dist/types/Framework/Service/MongoUserService.d.ts +31 -31
- package/dist/types/Framework/Service/MysqlAccountService.d.ts +67 -67
- package/dist/types/Framework/Service/MysqlUserService.d.ts +33 -33
- package/dist/types/Framework/Service/ini.d.ts +29 -29
- package/dist/types/Framework/ThirdParty/AlipayTool.d.ts +76 -108
- package/dist/types/Framework/ThirdParty/Alisms.d.ts +23 -13
- package/dist/types/Framework/ThirdParty/AppleTool.d.ts +131 -131
- package/dist/types/Framework/ThirdParty/CgRankTool.d.ts +107 -107
- package/dist/types/Framework/ThirdParty/EmailTool.d.ts +4 -4
- package/dist/types/Framework/ThirdParty/QQTool.d.ts +41 -41
- package/dist/types/Framework/ThirdParty/QiniuTool.d.ts +5 -5
- package/dist/types/Framework/ThirdParty/Rpc.d.ts +28 -28
- package/dist/types/Framework/ThirdParty/WechatTool.d.ts +30 -30
- package/dist/types/Framework/cgserver.d.ts +63 -63
- package/dist/types/Framework/global.d.ts +45 -45
- package/dist/types/Framework/index.d.ts +2 -2
- package/dist/types/Framework/index_export_.d.ts +81 -79
- package/dist/types/test/test.d.ts +1 -1
- package/package.json +8 -4
|
@@ -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 FrameworkConfig_1 = require("../../../Config/FrameworkConfig");
|
|
7
|
-
const MongoCacheService_1 = require("../../../Service/MongoCacheService");
|
|
8
|
-
const ini_1 = require("../../../Service/ini");
|
|
9
|
-
const CacheTool_1 = require("../../../Logic/CacheTool");
|
|
10
|
-
const RedisManager_1 = require("../../../Database/Redis/RedisManager");
|
|
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.redis.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.redis.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.redis.set(this._session_id, user.id).then(() => {
|
|
133
|
-
RedisManager_1.gRedisMgr.redis.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({ key: cm.key }, cm, { upsert: 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 FrameworkConfig_1 = require("../../../Config/FrameworkConfig");
|
|
7
|
+
const MongoCacheService_1 = require("../../../Service/MongoCacheService");
|
|
8
|
+
const ini_1 = require("../../../Service/ini");
|
|
9
|
+
const CacheTool_1 = require("../../../Logic/CacheTool");
|
|
10
|
+
const RedisManager_1 = require("../../../Database/Redis/RedisManager");
|
|
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.redis.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.redis.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.redis.set(this._session_id, user.id).then(() => {
|
|
133
|
+
RedisManager_1.gRedisMgr.redis.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({ key: cm.key }, cm, { upsert: 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,115 +1,115 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gCtrMgr = exports.ControllerManager = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* web服务中mvc的控制器管理器
|
|
6
|
-
*/
|
|
7
|
-
class ControllerManager {
|
|
8
|
-
_static_ctr = {};
|
|
9
|
-
_ctr_cls = {};
|
|
10
|
-
//module ctrname lower normal
|
|
11
|
-
_cache_action_names = {};
|
|
12
|
-
registerController(module_name, ctr_name, cls) {
|
|
13
|
-
module_name = module_name.toLowerCase();
|
|
14
|
-
ctr_name = ctr_name.toLowerCase();
|
|
15
|
-
if (module_name == ctr_name) {
|
|
16
|
-
throw ("模块名称不能和控制器名称相同:" + module_name);
|
|
17
|
-
}
|
|
18
|
-
this._ctr_cls[module_name] = this._ctr_cls[module_name] || {};
|
|
19
|
-
this._ctr_cls[module_name][ctr_name] = cls;
|
|
20
|
-
this._cacheActionName(module_name, ctr_name, cls);
|
|
21
|
-
}
|
|
22
|
-
_cacheActionName(module_name, ctr_name, cls) {
|
|
23
|
-
module_name = module_name.toLowerCase();
|
|
24
|
-
ctr_name = ctr_name.toLowerCase();
|
|
25
|
-
//不能通过cls.name来获取ctr名称,因为混淆之后类名会变化
|
|
26
|
-
let prototype = cls.prototype;
|
|
27
|
-
let map_names = {};
|
|
28
|
-
while (prototype && prototype.constructor.name != "BaseController") {
|
|
29
|
-
let names = Object.getOwnPropertyNames(prototype);
|
|
30
|
-
for (let action_name of names) {
|
|
31
|
-
if (action_name.indexOf("on") != 0
|
|
32
|
-
&& action_name.indexOf("show") != 0) {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
if (map_names[action_name.toLowerCase()]) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
map_names[action_name.toLowerCase()] = action_name;
|
|
39
|
-
}
|
|
40
|
-
prototype = Object.getPrototypeOf(prototype);
|
|
41
|
-
}
|
|
42
|
-
this._cache_action_names[module_name] = this._cache_action_names[module_name] || {};
|
|
43
|
-
this._cache_action_names[module_name][ctr_name] = map_names;
|
|
44
|
-
}
|
|
45
|
-
getActionName(module_name, ctr_name, action_name) {
|
|
46
|
-
module_name = module_name.toLowerCase();
|
|
47
|
-
ctr_name = ctr_name.toLowerCase();
|
|
48
|
-
action_name = action_name.toLowerCase();
|
|
49
|
-
if (!this._cache_action_names[module_name]) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
if (!this._cache_action_names[module_name][ctr_name]) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
return this._cache_action_names[module_name][ctr_name][action_name];
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* 静态ctr,这样,ctr就不会被多次创建
|
|
59
|
-
* @param module_name
|
|
60
|
-
* @param ctr_name
|
|
61
|
-
* @param obj
|
|
62
|
-
*/
|
|
63
|
-
registerStaticController(module_name, ctr_name, obj) {
|
|
64
|
-
module_name = module_name.toLowerCase();
|
|
65
|
-
ctr_name = ctr_name.toLowerCase();
|
|
66
|
-
this._static_ctr[module_name] = this._static_ctr[module_name] || {};
|
|
67
|
-
this._static_ctr[module_name][ctr_name] = obj;
|
|
68
|
-
this._cacheActionNameForStatic(module_name, ctr_name, obj);
|
|
69
|
-
}
|
|
70
|
-
_cacheActionNameForStatic(module_name, ctr_name, obj) {
|
|
71
|
-
module_name = module_name.toLowerCase();
|
|
72
|
-
ctr_name = ctr_name.toLowerCase();
|
|
73
|
-
let prototype = Object.getPrototypeOf(obj);
|
|
74
|
-
let map_names = {};
|
|
75
|
-
while (prototype && prototype.constructor.name != "BaseController") {
|
|
76
|
-
let names = Object.getOwnPropertyNames(prototype);
|
|
77
|
-
for (let func_name of names) {
|
|
78
|
-
let low_name = func_name.toLowerCase();
|
|
79
|
-
if (!map_names[low_name]) //有可能遭遇重载
|
|
80
|
-
{
|
|
81
|
-
map_names[low_name] = func_name;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
prototype = Object.getPrototypeOf(prototype);
|
|
85
|
-
}
|
|
86
|
-
this._cache_action_names[module_name] = this._cache_action_names[module_name] || {};
|
|
87
|
-
this._cache_action_names[module_name][ctr_name] = map_names;
|
|
88
|
-
}
|
|
89
|
-
getStaticCtr(module_name, controller_name) {
|
|
90
|
-
if (module_name) {
|
|
91
|
-
module_name = module_name.toLowerCase();
|
|
92
|
-
}
|
|
93
|
-
if (controller_name) {
|
|
94
|
-
controller_name = controller_name.toLowerCase();
|
|
95
|
-
}
|
|
96
|
-
if (!this._static_ctr[module_name]) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
return this._static_ctr[module_name][controller_name];
|
|
100
|
-
}
|
|
101
|
-
getClass(module_name, controller_name) {
|
|
102
|
-
if (module_name) {
|
|
103
|
-
module_name = module_name.toLowerCase();
|
|
104
|
-
}
|
|
105
|
-
if (controller_name) {
|
|
106
|
-
controller_name = controller_name.toLowerCase();
|
|
107
|
-
}
|
|
108
|
-
if (!this._ctr_cls[module_name]) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
return this._ctr_cls[module_name][controller_name];
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.ControllerManager = ControllerManager;
|
|
115
|
-
exports.gCtrMgr = new ControllerManager();
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gCtrMgr = exports.ControllerManager = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* web服务中mvc的控制器管理器
|
|
6
|
+
*/
|
|
7
|
+
class ControllerManager {
|
|
8
|
+
_static_ctr = {};
|
|
9
|
+
_ctr_cls = {};
|
|
10
|
+
//module ctrname lower normal
|
|
11
|
+
_cache_action_names = {};
|
|
12
|
+
registerController(module_name, ctr_name, cls) {
|
|
13
|
+
module_name = module_name.toLowerCase();
|
|
14
|
+
ctr_name = ctr_name.toLowerCase();
|
|
15
|
+
if (module_name == ctr_name) {
|
|
16
|
+
throw ("模块名称不能和控制器名称相同:" + module_name);
|
|
17
|
+
}
|
|
18
|
+
this._ctr_cls[module_name] = this._ctr_cls[module_name] || {};
|
|
19
|
+
this._ctr_cls[module_name][ctr_name] = cls;
|
|
20
|
+
this._cacheActionName(module_name, ctr_name, cls);
|
|
21
|
+
}
|
|
22
|
+
_cacheActionName(module_name, ctr_name, cls) {
|
|
23
|
+
module_name = module_name.toLowerCase();
|
|
24
|
+
ctr_name = ctr_name.toLowerCase();
|
|
25
|
+
//不能通过cls.name来获取ctr名称,因为混淆之后类名会变化
|
|
26
|
+
let prototype = cls.prototype;
|
|
27
|
+
let map_names = {};
|
|
28
|
+
while (prototype && prototype.constructor.name != "BaseController") {
|
|
29
|
+
let names = Object.getOwnPropertyNames(prototype);
|
|
30
|
+
for (let action_name of names) {
|
|
31
|
+
if (action_name.indexOf("on") != 0
|
|
32
|
+
&& action_name.indexOf("show") != 0) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (map_names[action_name.toLowerCase()]) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
map_names[action_name.toLowerCase()] = action_name;
|
|
39
|
+
}
|
|
40
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
41
|
+
}
|
|
42
|
+
this._cache_action_names[module_name] = this._cache_action_names[module_name] || {};
|
|
43
|
+
this._cache_action_names[module_name][ctr_name] = map_names;
|
|
44
|
+
}
|
|
45
|
+
getActionName(module_name, ctr_name, action_name) {
|
|
46
|
+
module_name = module_name.toLowerCase();
|
|
47
|
+
ctr_name = ctr_name.toLowerCase();
|
|
48
|
+
action_name = action_name.toLowerCase();
|
|
49
|
+
if (!this._cache_action_names[module_name]) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (!this._cache_action_names[module_name][ctr_name]) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return this._cache_action_names[module_name][ctr_name][action_name];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 静态ctr,这样,ctr就不会被多次创建
|
|
59
|
+
* @param module_name
|
|
60
|
+
* @param ctr_name
|
|
61
|
+
* @param obj
|
|
62
|
+
*/
|
|
63
|
+
registerStaticController(module_name, ctr_name, obj) {
|
|
64
|
+
module_name = module_name.toLowerCase();
|
|
65
|
+
ctr_name = ctr_name.toLowerCase();
|
|
66
|
+
this._static_ctr[module_name] = this._static_ctr[module_name] || {};
|
|
67
|
+
this._static_ctr[module_name][ctr_name] = obj;
|
|
68
|
+
this._cacheActionNameForStatic(module_name, ctr_name, obj);
|
|
69
|
+
}
|
|
70
|
+
_cacheActionNameForStatic(module_name, ctr_name, obj) {
|
|
71
|
+
module_name = module_name.toLowerCase();
|
|
72
|
+
ctr_name = ctr_name.toLowerCase();
|
|
73
|
+
let prototype = Object.getPrototypeOf(obj);
|
|
74
|
+
let map_names = {};
|
|
75
|
+
while (prototype && prototype.constructor.name != "BaseController") {
|
|
76
|
+
let names = Object.getOwnPropertyNames(prototype);
|
|
77
|
+
for (let func_name of names) {
|
|
78
|
+
let low_name = func_name.toLowerCase();
|
|
79
|
+
if (!map_names[low_name]) //有可能遭遇重载
|
|
80
|
+
{
|
|
81
|
+
map_names[low_name] = func_name;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
85
|
+
}
|
|
86
|
+
this._cache_action_names[module_name] = this._cache_action_names[module_name] || {};
|
|
87
|
+
this._cache_action_names[module_name][ctr_name] = map_names;
|
|
88
|
+
}
|
|
89
|
+
getStaticCtr(module_name, controller_name) {
|
|
90
|
+
if (module_name) {
|
|
91
|
+
module_name = module_name.toLowerCase();
|
|
92
|
+
}
|
|
93
|
+
if (controller_name) {
|
|
94
|
+
controller_name = controller_name.toLowerCase();
|
|
95
|
+
}
|
|
96
|
+
if (!this._static_ctr[module_name]) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
return this._static_ctr[module_name][controller_name];
|
|
100
|
+
}
|
|
101
|
+
getClass(module_name, controller_name) {
|
|
102
|
+
if (module_name) {
|
|
103
|
+
module_name = module_name.toLowerCase();
|
|
104
|
+
}
|
|
105
|
+
if (controller_name) {
|
|
106
|
+
controller_name = controller_name.toLowerCase();
|
|
107
|
+
}
|
|
108
|
+
if (!this._ctr_cls[module_name]) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
return this._ctr_cls[module_name][controller_name];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.ControllerManager = ControllerManager;
|
|
115
|
+
exports.gCtrMgr = new ControllerManager();
|