cgserver 6.4.13 → 6.5.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.
|
@@ -76,14 +76,18 @@ class MongoManager {
|
|
|
76
76
|
}
|
|
77
77
|
onConnect() {
|
|
78
78
|
this._mongo_init_succ = true;
|
|
79
|
-
Log_1.GLog.info("
|
|
79
|
+
Log_1.GLog.info("mongo has connected!");
|
|
80
80
|
}
|
|
81
81
|
onEnd() {
|
|
82
82
|
this._mongo_init_succ = false;
|
|
83
|
-
Log_1.GLog.
|
|
83
|
+
Log_1.GLog.error("mongo has ended!", true);
|
|
84
|
+
Log_1.GLog.info("mongo try reconnect", true);
|
|
85
|
+
this.init();
|
|
84
86
|
}
|
|
85
87
|
onError(err) {
|
|
86
|
-
Log_1.GLog.
|
|
88
|
+
Log_1.GLog.error("Error " + err);
|
|
89
|
+
Log_1.GLog.info("mongo try reconnect", true);
|
|
90
|
+
this.init();
|
|
87
91
|
}
|
|
88
92
|
async getAutoIds(key) {
|
|
89
93
|
if (!this._mongo) {
|
|
@@ -25,7 +25,7 @@ class AsyncQueueItem {
|
|
|
25
25
|
if (!funcitem.func) {
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
28
|
-
let rs = await cgserver_1.core.safeCall(funcitem.func, funcitem.thisArg, funcitem.params);
|
|
28
|
+
let rs = await cgserver_1.core.safeCall(funcitem.func, funcitem.thisArg, ...funcitem.params);
|
|
29
29
|
await cgserver_1.core.safeCall(funcitem.resolve, null, rs);
|
|
30
30
|
}
|
|
31
31
|
this.running = false;
|
|
@@ -39,29 +39,14 @@ class BaseUserController extends BaseController_1.BaseController {
|
|
|
39
39
|
this._session_id = this._request.getCookie(this._user_session_id) || this._request.params.session_id || this._request.postData.session_id;
|
|
40
40
|
let userId = -1;
|
|
41
41
|
if (this._session_id) {
|
|
42
|
-
let user =
|
|
43
|
-
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
|
|
44
|
-
user = CacheTool_1.GCacheTool.get(this._session_id);
|
|
45
|
-
}
|
|
46
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
47
|
-
let user_id = parseInt((await RedisManager_1.GRedisMgr.get(this._session_id)) || "-1");
|
|
48
|
-
if (user_id > 0) {
|
|
49
|
-
user = (await UserService_1.GUserSer.getById(user_id));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
53
|
-
let user_id = (await MongoCacheService_1.GMongoCacheSer.getData(this._session_id)) || -1;
|
|
54
|
-
if (user_id > 0) {
|
|
55
|
-
user = (await UserService_1.GUserSer.getById(user_id));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
42
|
+
let user = await this._getUserBySession(this._session_id);
|
|
58
43
|
if (!user) {
|
|
59
44
|
this._update_session();
|
|
60
45
|
//Session不存在清除客户端cookie
|
|
61
46
|
this._response.clearCookie(this._user_session_id);
|
|
62
47
|
}
|
|
63
48
|
else {
|
|
64
|
-
|
|
49
|
+
this._login(user);
|
|
65
50
|
userId = user.id;
|
|
66
51
|
}
|
|
67
52
|
}
|
|
@@ -74,6 +59,33 @@ class BaseUserController extends BaseController_1.BaseController {
|
|
|
74
59
|
this._user = this._self_user;
|
|
75
60
|
}
|
|
76
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 UserService_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 UserService_1.GUserSer.getById(user_id));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return user;
|
|
88
|
+
}
|
|
77
89
|
_logout() {
|
|
78
90
|
if (this._session_id) {
|
|
79
91
|
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
|
|
@@ -104,10 +116,16 @@ class BaseUserController extends BaseController_1.BaseController {
|
|
|
104
116
|
time = this._engine.cfg.cookie.expires.account;
|
|
105
117
|
}
|
|
106
118
|
this._response.setCookie(this._user_session_id, this._session_id, time);
|
|
107
|
-
if
|
|
108
|
-
|
|
119
|
+
//if(this._engine.cfg.session_type==ESessionType.Cache)
|
|
120
|
+
{
|
|
121
|
+
if (time > 24 * 60 * 60) {
|
|
122
|
+
CacheTool_1.GCacheTool.add(this._session_id, user, 24 * 60 * 60 * 1000);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
CacheTool_1.GCacheTool.add(this._session_id, user, time * 1000);
|
|
126
|
+
}
|
|
109
127
|
}
|
|
110
|
-
|
|
128
|
+
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
111
129
|
RedisManager_1.GRedisMgr.set(this._session_id, user.id).then(() => {
|
|
112
130
|
RedisManager_1.GRedisMgr.expire(this._session_id, time);
|
|
113
131
|
});
|
|
@@ -122,29 +140,9 @@ class BaseUserController extends BaseController_1.BaseController {
|
|
|
122
140
|
this._self_user = user;
|
|
123
141
|
}
|
|
124
142
|
/**
|
|
125
|
-
*
|
|
143
|
+
* 已经被启用
|
|
126
144
|
*/
|
|
127
145
|
async _update_session() {
|
|
128
|
-
if (!this._session_id) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
let user_id = -1;
|
|
132
|
-
let um = null;
|
|
133
|
-
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
|
|
134
|
-
um = CacheTool_1.GCacheTool.get(this._session_id);
|
|
135
|
-
if (um) {
|
|
136
|
-
user_id = um.id;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
140
|
-
user_id = parseInt((await RedisManager_1.GRedisMgr.get(this._session_id)) || "-1");
|
|
141
|
-
}
|
|
142
|
-
if (user_id < 0) {
|
|
143
|
-
this._session_id = null;
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
um = (await UserService_1.GUserSer.getById(user_id));
|
|
147
|
-
this._login(um);
|
|
148
146
|
}
|
|
149
147
|
async update_user(user_id) {
|
|
150
148
|
let user = (await UserService_1.GUserSer.getById(user_id));
|
|
@@ -13,10 +13,11 @@ export declare class BaseUserController<T extends UserModel> extends BaseControl
|
|
|
13
13
|
get isProxy(): boolean;
|
|
14
14
|
get isCommon(): boolean;
|
|
15
15
|
init(): Promise<void>;
|
|
16
|
+
protected _getUserBySession(session: string): Promise<T>;
|
|
16
17
|
protected _logout(): void;
|
|
17
18
|
protected _login(user: T): void;
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* 已经被启用
|
|
20
21
|
*/
|
|
21
22
|
protected _update_session(): Promise<void>;
|
|
22
23
|
update_user(user_id: number): Promise<void>;
|