cgserver 12.0.0 → 12.0.2
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/dist/lib/Framework/{ThirdParty → Server/RpcWebSocketServer}/CgMq.js +11 -6
- package/dist/lib/Framework/Server/{WebSocketServer → RpcWebSocketServer}/IRpc.js +4 -2
- package/dist/lib/Framework/Server/RpcWebSocketServer/IRpcClientWebSocket.js +253 -0
- package/dist/lib/Framework/Server/{WebSocketServer → RpcWebSocketServer}/IRpcServerWebSocket.js +16 -5
- package/dist/lib/Framework/Server/SocketServer/ISocket.js +3 -3
- package/dist/lib/Framework/Server/SocketServer/ISocketServer.js +17 -17
- package/dist/lib/Framework/Server/WebSocketServer/IClientWebSocket.js +1 -1
- package/dist/lib/Framework/Server/WebSocketServer/IWebSocketServer.js +3 -0
- package/dist/lib/Framework/ThirdParty/Rpc.js +15 -6
- package/dist/lib/Framework/index_export_.js +4 -4
- package/dist/types/Framework/{ThirdParty → Server/RpcWebSocketServer}/CgMq.d.ts +4 -4
- package/dist/types/Framework/{SocketServer → Server/RpcWebSocketServer}/IRpc.d.ts +3 -2
- package/dist/types/Framework/Server/{WebSocketServer → RpcWebSocketServer}/IRpcClientWebSocket.d.ts +6 -1
- package/dist/types/Framework/{SocketServer → Server/RpcWebSocketServer}/IRpcServerWebSocket.d.ts +2 -2
- package/dist/types/Framework/Server/SocketServer/IClientSocket.d.ts +1 -0
- package/dist/types/Framework/Server/SocketServer/IServerSocket.d.ts +1 -0
- package/dist/types/Framework/Server/SocketServer/ISocket.d.ts +2 -1
- package/dist/types/Framework/Server/SocketServer/ISocketServer.d.ts +3 -3
- package/dist/types/Framework/Server/SocketServer/PacketParser.d.ts +1 -0
- package/dist/types/Framework/Server/WebSocketServer/IClientWebSocket.d.ts +2 -2
- package/dist/types/Framework/Server/WebSocketServer/IWebSocketServer.d.ts +4 -1
- package/dist/types/Framework/ThirdParty/Rpc.d.ts +7 -5
- package/dist/types/Framework/index_export_.d.ts +4 -4
- package/package.json +1 -1
- package/dist/lib/Framework/Database/MSSqlManager.js +0 -53
- package/dist/lib/Framework/Database/MysqlBaseService.js +0 -280
- package/dist/lib/Framework/Database/MysqlManager.js +0 -105
- package/dist/lib/Framework/Database/RedisManager.js +0 -60
- package/dist/lib/Framework/Server/WebSocketServer/IRpcClientWebSocket.js +0 -140
- package/dist/lib/Framework/SocketServer/IClientWebSocket.js +0 -44
- package/dist/lib/Framework/SocketServer/IRpc.js +0 -36
- package/dist/lib/Framework/SocketServer/IRpcClientWebSocket.js +0 -140
- package/dist/lib/Framework/SocketServer/IRpcServerWebSocket.js +0 -82
- package/dist/lib/Framework/SocketServer/IServerWebSocket.js +0 -95
- package/dist/lib/Framework/SocketServer/ISocketServer.js +0 -214
- package/dist/lib/Framework/SocketServer/IWebSocket.js +0 -215
- package/dist/lib/Framework/SocketServer/ProtoFilter/GoogleProtoFilter.js +0 -57
- package/dist/lib/Framework/SocketServer/ProtoFilter/IProtoFilter.js +0 -9
- package/dist/lib/Framework/SocketServer/ProtoFilter/JsonProtoFilter.js +0 -29
- package/dist/lib/Framework/SocketServer/ProtoFilter/ProtoFactory.js +0 -35
- package/dist/lib/Framework/ThirdParty/CgRankToo.js +0 -196
- package/dist/lib/Framework/WebServer/Controller/BaseController.js +0 -119
- package/dist/lib/Framework/WebServer/Controller/MongoBaseUserController.js +0 -171
- package/dist/lib/Framework/WebServer/Controller/MysqlBaseUserController.js +0 -169
- package/dist/lib/Framework/WebServer/Engine/ControllerManager.js +0 -115
- package/dist/lib/Framework/WebServer/Engine/Engine.js +0 -218
- package/dist/lib/Framework/WebServer/Engine/RazorJs.js +0 -543
- package/dist/lib/Framework/WebServer/Engine/Request.js +0 -226
- package/dist/lib/Framework/WebServer/Engine/Response.js +0 -87
- package/dist/lib/Framework/WebServer/IWebServer.js +0 -55
- package/dist/types/Framework/Database/MSSqlManager.d.ts +0 -26
- package/dist/types/Framework/Database/MysqlBaseService.d.ts +0 -34
- package/dist/types/Framework/Database/MysqlManager.d.ts +0 -30
- package/dist/types/Framework/Database/RedisManager.d.ts +0 -24
- package/dist/types/Framework/Server/WebSocketServer/IRpc.d.ts +0 -32
- package/dist/types/Framework/Server/WebSocketServer/IRpcServerWebSocket.d.ts +0 -23
- package/dist/types/Framework/SocketServer/IClientWebSocket.d.ts +0 -17
- package/dist/types/Framework/SocketServer/IRpcClientWebSocket.d.ts +0 -29
- package/dist/types/Framework/SocketServer/IServerWebSocket.d.ts +0 -38
- package/dist/types/Framework/SocketServer/ISocketServer.d.ts +0 -46
- package/dist/types/Framework/SocketServer/IWebSocket.d.ts +0 -76
- package/dist/types/Framework/SocketServer/ProtoFilter/GoogleProtoFilter.d.ts +0 -9
- package/dist/types/Framework/SocketServer/ProtoFilter/IProtoFilter.d.ts +0 -10
- package/dist/types/Framework/SocketServer/ProtoFilter/JsonProtoFilter.d.ts +0 -6
- package/dist/types/Framework/SocketServer/ProtoFilter/ProtoFactory.d.ts +0 -12
- package/dist/types/Framework/ThirdParty/CgRankToo.d.ts +0 -103
- package/dist/types/Framework/WebServer/Controller/BaseController.d.ts +0 -34
- package/dist/types/Framework/WebServer/Controller/MongoBaseUserController.d.ts +0 -28
- package/dist/types/Framework/WebServer/Controller/MysqlBaseUserController.d.ts +0 -27
- package/dist/types/Framework/WebServer/Engine/ControllerManager.d.ts +0 -37
- package/dist/types/Framework/WebServer/Engine/Engine.d.ts +0 -44
- package/dist/types/Framework/WebServer/Engine/RazorJs.d.ts +0 -21
- package/dist/types/Framework/WebServer/Engine/Request.d.ts +0 -50
- package/dist/types/Framework/WebServer/Engine/Response.d.ts +0 -26
- package/dist/types/Framework/WebServer/IWebServer.d.ts +0 -22
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GCgRankTool = exports.CgRankTool = exports.CgRankCommandItem = exports.CgRankRankData = exports.CgRankRankItem = exports.CgRankErrcode = void 0;
|
|
4
|
-
const HttpTool_1 = require("../Logic/HttpTool");
|
|
5
|
-
class CgRankErrcode {
|
|
6
|
-
id = 0;
|
|
7
|
-
des = "";
|
|
8
|
-
}
|
|
9
|
-
exports.CgRankErrcode = CgRankErrcode;
|
|
10
|
-
class CgRankRankItem {
|
|
11
|
-
id = "";
|
|
12
|
-
score = 0;
|
|
13
|
-
rank = 0;
|
|
14
|
-
other = {};
|
|
15
|
-
}
|
|
16
|
-
exports.CgRankRankItem = CgRankRankItem;
|
|
17
|
-
class CgRankRankData {
|
|
18
|
-
//每个榜都有一个关键词
|
|
19
|
-
key = "";
|
|
20
|
-
//数据
|
|
21
|
-
maps = {};
|
|
22
|
-
//有序列表
|
|
23
|
-
list = [];
|
|
24
|
-
timeout = -1;
|
|
25
|
-
}
|
|
26
|
-
exports.CgRankRankData = CgRankRankData;
|
|
27
|
-
class CgRankCommandItem {
|
|
28
|
-
id = "";
|
|
29
|
-
score = 0;
|
|
30
|
-
inc = {};
|
|
31
|
-
set = {};
|
|
32
|
-
}
|
|
33
|
-
exports.CgRankCommandItem = CgRankCommandItem;
|
|
34
|
-
class CgRankTool {
|
|
35
|
-
_url = "";
|
|
36
|
-
_password = "";
|
|
37
|
-
init(url, password) {
|
|
38
|
-
this._url = url;
|
|
39
|
-
this._password = password;
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
* @param key 排行榜的关键字
|
|
45
|
-
* @returns
|
|
46
|
-
*/
|
|
47
|
-
async removeRank(key) {
|
|
48
|
-
let msg = {
|
|
49
|
-
cmd: "removeRank",
|
|
50
|
-
key: key,
|
|
51
|
-
password: this._password
|
|
52
|
-
};
|
|
53
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
54
|
-
return rs.body;
|
|
55
|
-
}
|
|
56
|
-
async saveAllRank() {
|
|
57
|
-
let msg = {
|
|
58
|
-
cmd: "saveAllRank",
|
|
59
|
-
password: this._password
|
|
60
|
-
};
|
|
61
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
62
|
-
return rs.body;
|
|
63
|
-
}
|
|
64
|
-
async getRankItem(key, id) {
|
|
65
|
-
let msg = {
|
|
66
|
-
cmd: "getRankItem",
|
|
67
|
-
key: key,
|
|
68
|
-
id: id,
|
|
69
|
-
password: this._password
|
|
70
|
-
};
|
|
71
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
72
|
-
return rs.body;
|
|
73
|
-
}
|
|
74
|
-
async getRankItems(key, ids) {
|
|
75
|
-
let msg = {
|
|
76
|
-
cmd: "getRankItems",
|
|
77
|
-
key: key,
|
|
78
|
-
ids: ids,
|
|
79
|
-
password: this._password
|
|
80
|
-
};
|
|
81
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
82
|
-
return rs.body;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
* @param key
|
|
87
|
-
* @param start
|
|
88
|
-
* @param count 小于等于0表示全部
|
|
89
|
-
*/
|
|
90
|
-
async getRankList(key, start, count) {
|
|
91
|
-
let msg = {
|
|
92
|
-
cmd: "getRankList",
|
|
93
|
-
key: key,
|
|
94
|
-
start: start,
|
|
95
|
-
count: count,
|
|
96
|
-
password: this._password
|
|
97
|
-
};
|
|
98
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
99
|
-
return rs.body;
|
|
100
|
-
}
|
|
101
|
-
async getRankCount(key) {
|
|
102
|
-
let msg = {
|
|
103
|
-
cmd: "getRankCount",
|
|
104
|
-
key: key,
|
|
105
|
-
password: this._password
|
|
106
|
-
};
|
|
107
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
108
|
-
return rs.body;
|
|
109
|
-
}
|
|
110
|
-
async getRevRankList(key, start, count) {
|
|
111
|
-
let msg = {
|
|
112
|
-
cmd: "getRevRankList",
|
|
113
|
-
key: key,
|
|
114
|
-
start: start,
|
|
115
|
-
count: count,
|
|
116
|
-
password: this._password
|
|
117
|
-
};
|
|
118
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
119
|
-
return rs.body;
|
|
120
|
-
}
|
|
121
|
-
async addToRank(key, id, score, other, isreplace = false) {
|
|
122
|
-
let msg = {
|
|
123
|
-
cmd: "addToRank",
|
|
124
|
-
key: key,
|
|
125
|
-
id: id,
|
|
126
|
-
score: score,
|
|
127
|
-
other: other,
|
|
128
|
-
isreplace: isreplace,
|
|
129
|
-
password: this._password
|
|
130
|
-
};
|
|
131
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
132
|
-
return rs.body;
|
|
133
|
-
}
|
|
134
|
-
async addsToRank(key, datas, isreplace = false) {
|
|
135
|
-
let msg = {
|
|
136
|
-
cmd: "addsToRank",
|
|
137
|
-
key: key,
|
|
138
|
-
datas: datas,
|
|
139
|
-
isreplace: isreplace,
|
|
140
|
-
password: this._password
|
|
141
|
-
};
|
|
142
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
143
|
-
return rs.body;
|
|
144
|
-
}
|
|
145
|
-
async removeFromRank(key, id) {
|
|
146
|
-
let msg = {
|
|
147
|
-
cmd: "removeFromRank",
|
|
148
|
-
key: key,
|
|
149
|
-
id: id,
|
|
150
|
-
password: this._password
|
|
151
|
-
};
|
|
152
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
153
|
-
return rs.body;
|
|
154
|
-
}
|
|
155
|
-
async updateInRank(key, command) {
|
|
156
|
-
let msg = {
|
|
157
|
-
cmd: "updateInRank",
|
|
158
|
-
key: key,
|
|
159
|
-
command: command,
|
|
160
|
-
password: this._password
|
|
161
|
-
};
|
|
162
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
163
|
-
return rs.body;
|
|
164
|
-
}
|
|
165
|
-
async updatesInRank(key, commands) {
|
|
166
|
-
let msg = {
|
|
167
|
-
cmd: "updatesInRank",
|
|
168
|
-
key: key,
|
|
169
|
-
commands: commands,
|
|
170
|
-
password: this._password
|
|
171
|
-
};
|
|
172
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
173
|
-
return rs.body;
|
|
174
|
-
}
|
|
175
|
-
async executeCommand(key, commands) {
|
|
176
|
-
let msg = {
|
|
177
|
-
cmd: "executeCommand",
|
|
178
|
-
key: key,
|
|
179
|
-
commands: commands,
|
|
180
|
-
password: this._password
|
|
181
|
-
};
|
|
182
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
183
|
-
return rs.body;
|
|
184
|
-
}
|
|
185
|
-
async anyCall(call, ...args) {
|
|
186
|
-
let msg = {
|
|
187
|
-
cmd: call,
|
|
188
|
-
args: args,
|
|
189
|
-
password: this._password
|
|
190
|
-
};
|
|
191
|
-
let rs = await HttpTool_1.gHttpTool.post({ url: this._url, json: msg });
|
|
192
|
-
return rs.body;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
exports.CgRankTool = CgRankTool;
|
|
196
|
-
exports.GCgRankTool = new CgRankTool();
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseController = void 0;
|
|
4
|
-
class BaseController {
|
|
5
|
-
_request = null;
|
|
6
|
-
get request() {
|
|
7
|
-
return this._request;
|
|
8
|
-
}
|
|
9
|
-
_response = null;
|
|
10
|
-
get response() {
|
|
11
|
-
return this._response;
|
|
12
|
-
}
|
|
13
|
-
//模块名称
|
|
14
|
-
_module = "";
|
|
15
|
-
_ctr_name = "";
|
|
16
|
-
get ctrName() {
|
|
17
|
-
return this._ctr_name;
|
|
18
|
-
}
|
|
19
|
-
_engine = null;
|
|
20
|
-
get postData() {
|
|
21
|
-
if (!this._request) {
|
|
22
|
-
return {};
|
|
23
|
-
}
|
|
24
|
-
return this._request.postData || {};
|
|
25
|
-
}
|
|
26
|
-
get paramData() {
|
|
27
|
-
if (!this._request) {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
return this._request.params || {};
|
|
31
|
-
}
|
|
32
|
-
constructor(req, res, engine) {
|
|
33
|
-
this._engine = engine;
|
|
34
|
-
this._request = req;
|
|
35
|
-
this._response = res;
|
|
36
|
-
//静态控制器,传过来全是空
|
|
37
|
-
if (this._request) {
|
|
38
|
-
this._request.debugInfo();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async init() {
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 方便static ctr使用
|
|
45
|
-
* @param req
|
|
46
|
-
* @param res
|
|
47
|
-
* @param engine
|
|
48
|
-
*/
|
|
49
|
-
initStatic(req, res, engine) {
|
|
50
|
-
this._engine = engine;
|
|
51
|
-
this._request = req;
|
|
52
|
-
this._response = res;
|
|
53
|
-
this._request.debugInfo();
|
|
54
|
-
}
|
|
55
|
-
//填充每个页面需要的通用数据
|
|
56
|
-
_init_data(model) {
|
|
57
|
-
model = model || {};
|
|
58
|
-
model.webName = this._engine.cfg.web_name;
|
|
59
|
-
return { model };
|
|
60
|
-
}
|
|
61
|
-
showJson(model) {
|
|
62
|
-
this._response.renderJson(model);
|
|
63
|
-
}
|
|
64
|
-
show(model) {
|
|
65
|
-
let html = this._engine.getRenderHtml(this._request, this._response, this._init_data(model));
|
|
66
|
-
this._response.renderHtml(html);
|
|
67
|
-
}
|
|
68
|
-
showText(text, noMeta) {
|
|
69
|
-
if (!noMeta) {
|
|
70
|
-
text = "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />" + text;
|
|
71
|
-
}
|
|
72
|
-
this._response.renderHtml(text);
|
|
73
|
-
}
|
|
74
|
-
redirect(module, controller, action, params) {
|
|
75
|
-
module = module || this._module;
|
|
76
|
-
controller = controller || this._ctr_name;
|
|
77
|
-
let url = this.parseFullUrl(module, controller, action);
|
|
78
|
-
params = params || {};
|
|
79
|
-
let str_p = "";
|
|
80
|
-
for (let key in params) {
|
|
81
|
-
str_p += "&" + key + "=" + params[key];
|
|
82
|
-
}
|
|
83
|
-
if (str_p.length > 0) {
|
|
84
|
-
str_p = "?" + str_p.substring(1);
|
|
85
|
-
}
|
|
86
|
-
url += str_p;
|
|
87
|
-
this._response.redirect(url);
|
|
88
|
-
}
|
|
89
|
-
parseFullUrl(module, controller, action) {
|
|
90
|
-
if (typeof action === "undefined" || !action) {
|
|
91
|
-
action = "index";
|
|
92
|
-
if (this._engine.cfg.routs.defaults.action == action) {
|
|
93
|
-
action = null;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
let url = "";
|
|
97
|
-
if (this._engine.cfg.routs.onlyModule) {
|
|
98
|
-
url = this._request.root + "/" + controller;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
url = this._request.root + "/" + module + "/" + controller;
|
|
102
|
-
}
|
|
103
|
-
if (action) {
|
|
104
|
-
url += "/" + action;
|
|
105
|
-
}
|
|
106
|
-
return url;
|
|
107
|
-
}
|
|
108
|
-
get remoteHost() {
|
|
109
|
-
return this._request.remoteHost;
|
|
110
|
-
}
|
|
111
|
-
forceDebug() {
|
|
112
|
-
//静态控制器,传过来全是空
|
|
113
|
-
if (this._request) {
|
|
114
|
-
this._request.debugInfo();
|
|
115
|
-
}
|
|
116
|
-
this._response.debug = true;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
exports.BaseController = BaseController;
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongoBaseUserController = void 0;
|
|
4
|
-
const BaseController_1 = require("./BaseController");
|
|
5
|
-
const FrameworkConfig_1 = require("../../Config/FrameworkConfig");
|
|
6
|
-
const MongoCacheService_1 = require("../../Service/MongoCacheService");
|
|
7
|
-
const ini_1 = require("../../Service/ini");
|
|
8
|
-
const CacheTool_1 = require("../../Logic/CacheTool");
|
|
9
|
-
const RedisManager_1 = require("../../Database/Redis/RedisManager");
|
|
10
|
-
const MongoServiceManager_1 = require("../../Database/Mongo/MongoServiceManager");
|
|
11
|
-
class MongoBaseUserController extends BaseController_1.BaseController {
|
|
12
|
-
_user_session_id = "user_session_id";
|
|
13
|
-
_self_user = null;
|
|
14
|
-
_user = null; //网页内容的所属,比如,查看别人的博客,那这个信息就是作者的
|
|
15
|
-
_session_id = null;
|
|
16
|
-
_userser = null;
|
|
17
|
-
get selfUser() {
|
|
18
|
-
return this._self_user;
|
|
19
|
-
}
|
|
20
|
-
get isSelf() {
|
|
21
|
-
return this._self_user && (this._self_user.id == this._user.id);
|
|
22
|
-
}
|
|
23
|
-
get isLogin() {
|
|
24
|
-
return this._self_user && true;
|
|
25
|
-
}
|
|
26
|
-
get isCreator() {
|
|
27
|
-
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Creator);
|
|
28
|
-
}
|
|
29
|
-
get isAdmin() {
|
|
30
|
-
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Admin || this._self_user.role_group == ini_1.ERoleGroup.Creator);
|
|
31
|
-
}
|
|
32
|
-
get isProxy() {
|
|
33
|
-
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Proxy);
|
|
34
|
-
}
|
|
35
|
-
get isCommon() {
|
|
36
|
-
return this._self_user && (this._self_user.role_group == ini_1.ERoleGroup.Common);
|
|
37
|
-
}
|
|
38
|
-
async init() {
|
|
39
|
-
this._userser = MongoServiceManager_1.gMongoServiceMgr.getService("user");
|
|
40
|
-
this._engine.cfg.session_type = this._engine.cfg.session_type || FrameworkConfig_1.ESessionType.Cache;
|
|
41
|
-
this._session_id = this._request.getCookie(this._user_session_id) || this._request.params.session_id || this._request.postData.session_id;
|
|
42
|
-
let userId = -1;
|
|
43
|
-
if (this._session_id) {
|
|
44
|
-
let user = await this._getUserBySession(this._session_id);
|
|
45
|
-
if (!user) {
|
|
46
|
-
this._update_session();
|
|
47
|
-
//Session不存在清除客户端cookie
|
|
48
|
-
this._response.clearCookie(this._user_session_id);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
this._login(user);
|
|
52
|
-
userId = user.id;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
let params = this._request.params;
|
|
56
|
-
if (params.userId && params.userId != userId + "") {
|
|
57
|
-
this._user = (await this._userser.getById(params.userId));
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
//不是别人的信息就查看自己的
|
|
61
|
-
this._user = this._self_user;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
async _getUserBySession(session) {
|
|
65
|
-
let user = null;
|
|
66
|
-
if (!session) {
|
|
67
|
-
return user;
|
|
68
|
-
}
|
|
69
|
-
//每次强制从cache中先找,提高效率
|
|
70
|
-
//if(this._engine.cfg.session_type==ESessionType.Cache)
|
|
71
|
-
{
|
|
72
|
-
user = CacheTool_1.gCacheTool.get(this._session_id);
|
|
73
|
-
}
|
|
74
|
-
if (user) {
|
|
75
|
-
return user;
|
|
76
|
-
}
|
|
77
|
-
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
78
|
-
let user_id = parseInt((await RedisManager_1.gRedisMgr.redis.get(this._session_id)) || "-1");
|
|
79
|
-
if (user_id > 0) {
|
|
80
|
-
user = (await this._userser.getById(user_id));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
84
|
-
let user_id = (await MongoCacheService_1.gMongoCacheSer.getData(this._session_id)) || -1;
|
|
85
|
-
if (user_id > 0) {
|
|
86
|
-
user = (await this._userser.getById(user_id));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (user) {
|
|
90
|
-
this._login(user);
|
|
91
|
-
}
|
|
92
|
-
return user;
|
|
93
|
-
}
|
|
94
|
-
_logout() {
|
|
95
|
-
if (this._session_id) {
|
|
96
|
-
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
|
|
97
|
-
CacheTool_1.gCacheTool.remove(this._session_id);
|
|
98
|
-
}
|
|
99
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
100
|
-
RedisManager_1.gRedisMgr.redis.del(this._session_id);
|
|
101
|
-
}
|
|
102
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
103
|
-
MongoCacheService_1.gMongoCacheSer.deleteOne({ key: this._session_id });
|
|
104
|
-
}
|
|
105
|
-
this._session_id = null;
|
|
106
|
-
}
|
|
107
|
-
this._response.clearCookie(this._user_session_id);
|
|
108
|
-
}
|
|
109
|
-
_login(user) {
|
|
110
|
-
if (!user) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (!this._session_id) {
|
|
114
|
-
this._session_id = Math.random().toString(36).substring(2) + user.id;
|
|
115
|
-
}
|
|
116
|
-
let time = 0;
|
|
117
|
-
if (this._request.postData.remember == "on") {
|
|
118
|
-
time = this._engine.cfg.cookie.expires.account_remember;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
time = this._engine.cfg.cookie.expires.account;
|
|
122
|
-
}
|
|
123
|
-
this._response.setCookie(this._user_session_id, this._session_id, time);
|
|
124
|
-
//if(this._engine.cfg.session_type==ESessionType.Cache)
|
|
125
|
-
{
|
|
126
|
-
if (time > 24 * 60 * 60) {
|
|
127
|
-
CacheTool_1.gCacheTool.add(this._session_id, user, 24 * 60 * 60 * 1000);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
CacheTool_1.gCacheTool.add(this._session_id, user, time * 1000);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
134
|
-
RedisManager_1.gRedisMgr.redis.set(this._session_id, user.id).then(() => {
|
|
135
|
-
RedisManager_1.gRedisMgr.redis.expire(this._session_id, time);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
139
|
-
let cm = new MongoCacheService_1.MongoCacheModel();
|
|
140
|
-
cm.key = this._session_id;
|
|
141
|
-
cm.data = user.id;
|
|
142
|
-
cm.expireAt = Date.now() + time * 1000;
|
|
143
|
-
MongoCacheService_1.gMongoCacheSer.updateOne({ key: cm.key }, cm, true);
|
|
144
|
-
}
|
|
145
|
-
this._self_user = user;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* 已经被启用
|
|
149
|
-
*/
|
|
150
|
-
async _update_session() {
|
|
151
|
-
}
|
|
152
|
-
async update_user(user_id) {
|
|
153
|
-
let user = (await this._userser.getById(user_id));
|
|
154
|
-
if (this._user && this._user.id == user.id) {
|
|
155
|
-
this._user = user;
|
|
156
|
-
}
|
|
157
|
-
if (this._self_user && this._self_user.id == user.id) {
|
|
158
|
-
this._login(user);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
//填充每个页面需要的通用数据
|
|
162
|
-
_init_data(datas) {
|
|
163
|
-
let data = super._init_data(datas);
|
|
164
|
-
data.model.isLogin = this.isLogin;
|
|
165
|
-
data.model.user = this._user;
|
|
166
|
-
data.model.selfUser = this._self_user;
|
|
167
|
-
data.model.isSelf = this.isSelf;
|
|
168
|
-
return data;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
exports.MongoBaseUserController = MongoBaseUserController;
|
|
@@ -1,169 +0,0 @@
|
|
|
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, 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;
|