cgserver 6.5.0 → 6.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,8 +6,8 @@ const CacheTool_1 = require("../../Logic/CacheTool");
|
|
|
6
6
|
const FrameworkConfig_1 = require("../../Config/FrameworkConfig");
|
|
7
7
|
const RedisManager_1 = require("../../Database/RedisManager");
|
|
8
8
|
const MongoCacheService_1 = require("../../Service/MongoCacheService");
|
|
9
|
-
const MongoUserService_1 = require("../../Service/MongoUserService");
|
|
10
9
|
const ini_1 = require("../../Service/ini");
|
|
10
|
+
const MongoUserService_1 = require("../../Service/MongoUserService");
|
|
11
11
|
class MongoBaseUserController extends BaseController_1.BaseController {
|
|
12
12
|
_user_session_id = "user_session_id";
|
|
13
13
|
_self_user = null;
|
|
@@ -39,29 +39,14 @@ class MongoBaseUserController 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 MongoUserService_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 MongoUserService_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,36 @@ class MongoBaseUserController 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 MongoUserService_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 MongoUserService_1.GUserSer.getById(user_id));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (user) {
|
|
88
|
+
this._login(user);
|
|
89
|
+
}
|
|
90
|
+
return user;
|
|
91
|
+
}
|
|
77
92
|
_logout() {
|
|
78
93
|
if (this._session_id) {
|
|
79
94
|
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Cache) {
|
|
@@ -94,7 +109,7 @@ class MongoBaseUserController extends BaseController_1.BaseController {
|
|
|
94
109
|
return;
|
|
95
110
|
}
|
|
96
111
|
if (!this._session_id) {
|
|
97
|
-
this._session_id = Math.random().toString(36).
|
|
112
|
+
this._session_id = Math.random().toString(36).substring(2) + user.id;
|
|
98
113
|
}
|
|
99
114
|
let time = 0;
|
|
100
115
|
if (this._request.postData.remember == "on") {
|
|
@@ -104,10 +119,16 @@ class MongoBaseUserController extends BaseController_1.BaseController {
|
|
|
104
119
|
time = this._engine.cfg.cookie.expires.account;
|
|
105
120
|
}
|
|
106
121
|
this._response.setCookie(this._user_session_id, this._session_id, time);
|
|
107
|
-
if
|
|
108
|
-
|
|
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
|
+
}
|
|
109
130
|
}
|
|
110
|
-
|
|
131
|
+
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
111
132
|
RedisManager_1.GRedisMgr.set(this._session_id, user.id).then(() => {
|
|
112
133
|
RedisManager_1.GRedisMgr.expire(this._session_id, time);
|
|
113
134
|
});
|
|
@@ -122,29 +143,9 @@ class MongoBaseUserController extends BaseController_1.BaseController {
|
|
|
122
143
|
this._self_user = user;
|
|
123
144
|
}
|
|
124
145
|
/**
|
|
125
|
-
*
|
|
146
|
+
* 已经被启用
|
|
126
147
|
*/
|
|
127
148
|
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 MongoUserService_1.GUserSer.getById(user_id));
|
|
147
|
-
this._login(um);
|
|
148
149
|
}
|
|
149
150
|
async update_user(user_id) {
|
|
150
151
|
let user = (await MongoUserService_1.GUserSer.getById(user_id));
|
|
@@ -13,10 +13,11 @@ export declare class MongoBaseUserController<T extends UserModel> extends BaseCo
|
|
|
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>;
|