cgserver 8.2.2545 → 8.3.4

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.
@@ -42,12 +42,9 @@ class UserService extends MongoBaseService_1.MongoBaseService {
42
42
  super("user", type);
43
43
  exports.GUserSer = this;
44
44
  }
45
- _newUserModel() {
46
- return (new MongoUserModel());
47
- }
48
45
  async _createNewUser(account_id, nickname, sex, logo, group) {
49
46
  group = group || ini_1.ERoleGroup.Common;
50
- let um = this._newUserModel();
47
+ let um = new this._t_type();
51
48
  um.account_id = account_id;
52
49
  um.nickname = nickname;
53
50
  if (!um.nickname || um.nickname.length == 0) {
@@ -24,8 +24,6 @@ class MysqlUserModel extends MysqlBaseService_1.BaseModel {
24
24
  role_group = 4;
25
25
  role = 0;
26
26
  phone = "";
27
- wechat = "";
28
- qq = "";
29
27
  email = "";
30
28
  about = "";
31
29
  pre_user_id = -1;
@@ -73,14 +71,6 @@ __decorate([
73
71
  NotNull_1.NotNull,
74
72
  (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "")
75
73
  ], MysqlUserModel.prototype, "phone", void 0);
76
- __decorate([
77
- NotNull_1.NotNull,
78
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "")
79
- ], MysqlUserModel.prototype, "wechat", void 0);
80
- __decorate([
81
- NotNull_1.NotNull,
82
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "")
83
- ], MysqlUserModel.prototype, "qq", void 0);
84
74
  __decorate([
85
75
  NotNull_1.NotNull,
86
76
  (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "")
@@ -125,12 +115,9 @@ class MysqlUserService extends MysqlBaseService_1.MysqlBaseService {
125
115
  super(type);
126
116
  exports.GUserSer = this;
127
117
  }
128
- _newUserModel() {
129
- return (new MysqlUserModel());
130
- }
131
118
  async _createNewUser(account_id, nickname, sex, logo, group) {
132
119
  group = group || ini_1.ERoleGroup.Common;
133
- let um = this._newUserModel();
120
+ let um = new this._t_type();
134
121
  um.account_id = account_id;
135
122
  um.nickname = nickname;
136
123
  if (!um.nickname || um.nickname.length == 0) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SyncCall = void 0;
3
+ exports.SyncCall2 = exports.SyncCall = void 0;
4
4
  const SyncQueueTool_1 = require("../../Logic/SyncQueueTool");
5
5
  /**
6
6
  * 异步函数变为同步函数,当前进程有效
@@ -19,3 +19,23 @@ function SyncCall(target, propertyName, descriptor) {
19
19
  };
20
20
  }
21
21
  exports.SyncCall = SyncCall;
22
+ /**
23
+ * 异步函数变为同步函数,当前进程有效
24
+ * @param param_index 动态参数的索引
25
+ */
26
+ function SyncCall2(param_index) {
27
+ return (target, propertyName, descriptor) => {
28
+ let method = descriptor.value;
29
+ descriptor.value = function () {
30
+ let key = propertyName;
31
+ if (param_index != undefined && param_index < arguments.length) {
32
+ key = propertyName + "_" + arguments[param_index];
33
+ }
34
+ let ret = SyncQueueTool_1.GSyncQueueTool.add(key, async () => {
35
+ return await method.apply(target, arguments);
36
+ });
37
+ return ret;
38
+ };
39
+ };
40
+ }
41
+ exports.SyncCall2 = SyncCall2;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SyncCallServer = void 0;
3
+ exports.SyncCallServer2 = exports.SyncCallServer = void 0;
4
4
  const Core_1 = require("../../Core/Core");
5
5
  const SyncQueueTool_1 = require("../../Logic/SyncQueueTool");
6
6
  const MongoCacheService_1 = require("../../Service/MongoCacheService");
@@ -10,11 +10,47 @@ const MongoCacheService_1 = require("../../Service/MongoCacheService");
10
10
  * 只支持mongo模式
11
11
  * @returns
12
12
  */
13
- let SyncCallServer = function () {
13
+ function SyncCallServer(target, propertyName, descriptor) {
14
+ let method = descriptor.value;
15
+ descriptor.value = async () => {
16
+ let key = "sync_" + method.name;
17
+ let func = async () => {
18
+ let item = await MongoCacheService_1.GMongoCacheSer.getData(key);
19
+ let ret = null;
20
+ while (item) {
21
+ await Core_1.core.sleep(200);
22
+ item = await MongoCacheService_1.GMongoCacheSer.getData(key);
23
+ }
24
+ //10秒后过期,避免卡死
25
+ let mcm = await MongoCacheService_1.GMongoCacheSer.addData(key, true, Date.now() + 10 * 1000);
26
+ if (!mcm) {
27
+ await func();
28
+ }
29
+ return;
30
+ };
31
+ await func();
32
+ let ret = SyncQueueTool_1.GSyncQueueTool.add(method.name, async () => {
33
+ return await method.apply(self, arguments);
34
+ });
35
+ await MongoCacheService_1.GMongoCacheSer.deleteOne({ key });
36
+ return ret;
37
+ };
38
+ }
39
+ exports.SyncCallServer = SyncCallServer;
40
+ /**
41
+ * 异步函数变为同步函数
42
+ * 服务器间的异步,效率低
43
+ * 只支持mongo模式
44
+ * @returns
45
+ */
46
+ let SyncCallServer2 = function (params_index) {
14
47
  return function (target, propertyName, descriptor) {
15
48
  let method = descriptor.value;
16
49
  descriptor.value = async () => {
17
50
  let key = "sync_" + method.name;
51
+ if (params_index != undefined && params_index < arguments.length) {
52
+ key = key + "_" + arguments[params_index];
53
+ }
18
54
  let func = async () => {
19
55
  let item = await MongoCacheService_1.GMongoCacheSer.getData(key);
20
56
  let ret = null;
@@ -38,4 +74,4 @@ let SyncCallServer = function () {
38
74
  };
39
75
  };
40
76
  };
41
- exports.SyncCallServer = SyncCallServer;
77
+ exports.SyncCallServer2 = SyncCallServer2;
@@ -24,6 +24,12 @@ class CgServer {
24
24
  }
25
25
  init() {
26
26
  process.on("uncaughtException", this.onUnCaughtException.bind(this));
27
+ process.on("exit", this.onExit.bind(this));
28
+ //ctrl+c
29
+ process.on("SIGINT", this.onExit.bind(this));
30
+ //kill pid
31
+ process.on("SIGUSR1", this.onExit.bind(this));
32
+ process.on("SIGUSR2", this.onExit.bind(this));
27
33
  process.env.TZ = "Asia/Shanghai";
28
34
  EventTool_1.GEventTool.on("socket_server_init_done", this.onStart.bind(this));
29
35
  EventTool_1.GEventTool.on("web_server_init_done", this.onStart.bind(this));
@@ -58,6 +64,20 @@ class CgServer {
58
64
  Core_1.core.safeCall(events[i]);
59
65
  }
60
66
  }
67
+ async onExit() {
68
+ let events = this._events["exit"] || [];
69
+ let exit = true;
70
+ for (let i = 0; i < events.length; ++i) {
71
+ //只要有一个函数返回true,就不退出
72
+ let ret = await Core_1.core.safeCall(events[i]);
73
+ if (ret === true) {
74
+ exit = false;
75
+ }
76
+ }
77
+ if (exit) {
78
+ process.exit(0);
79
+ }
80
+ }
61
81
  addListener(event, func) {
62
82
  this._events[event] = this._events[event] || [];
63
83
  this._events[event].push(func);
@@ -76,6 +96,10 @@ class CgServer {
76
96
  }
77
97
  onUnCaughtException(e) {
78
98
  Log_1.GLog.error(e.stack);
99
+ let events = this._events["uncaughtexception"] || [];
100
+ for (let i = 0; i < events.length; ++i) {
101
+ Core_1.core.safeCall(events[i]);
102
+ }
79
103
  }
80
104
  addWebServer(server) {
81
105
  this._webservers.push(server);
@@ -28,7 +28,6 @@ export declare class UserService<T extends MongoUserModel> extends MongoBaseServ
28
28
  constructor(type: {
29
29
  new (): T;
30
30
  });
31
- protected _newUserModel(): T;
32
31
  protected _createNewUser(account_id: number, nickname: string, sex: number, logo: string, group?: ERoleGroup): Promise<T>;
33
32
  add(account_id: number, nickname: string, sex: number, logo: string, group?: ERoleGroup): Promise<T>;
34
33
  getByAccountId(account_id: number): Promise<T>;
@@ -10,8 +10,6 @@ export declare class MysqlUserModel extends BaseModel {
10
10
  role_group: number;
11
11
  role: number;
12
12
  phone: string;
13
- wechat: string;
14
- qq: string;
15
13
  email: string;
16
14
  about: string;
17
15
  pre_user_id: number;
@@ -27,7 +25,6 @@ export declare class MysqlUserService<T extends MysqlUserModel> extends MysqlBas
27
25
  constructor(type: {
28
26
  new (): T;
29
27
  });
30
- protected _newUserModel(): T;
31
28
  protected _createNewUser(account_id: number, nickname: string, sex: number, logo: string, group?: ERoleGroup): Promise<T>;
32
29
  updateBaseInfoByAccount(account_id: number, nickname: string, sex: number, logo: string): Promise<string>;
33
30
  add(account_id: number, nickname: string, sex: number, logo: string, group?: ERoleGroup): Promise<any>;
@@ -5,3 +5,8 @@
5
5
  * @param descriptor
6
6
  */
7
7
  export declare function SyncCall(target: any, propertyName: string, descriptor: TypedPropertyDescriptor<Function>): void;
8
+ /**
9
+ * 异步函数变为同步函数,当前进程有效
10
+ * @param param_index 动态参数的索引
11
+ */
12
+ export declare function SyncCall2(param_index?: number): (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<Function>) => void;
@@ -4,4 +4,11 @@
4
4
  * 只支持mongo模式
5
5
  * @returns
6
6
  */
7
- export declare let SyncCallServer: () => (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<Function>) => void;
7
+ export declare function SyncCallServer(target: any, propertyName: string, descriptor: TypedPropertyDescriptor<Function>): void;
8
+ /**
9
+ * 异步函数变为同步函数
10
+ * 服务器间的异步,效率低
11
+ * 只支持mongo模式
12
+ * @returns
13
+ */
14
+ export declare let SyncCallServer2: (params_index?: number) => (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<Function>) => void;
@@ -14,8 +14,9 @@ declare class CgServer {
14
14
  init(): void;
15
15
  protected _done: number;
16
16
  onStart(): void;
17
- addListener(event: "start", func: () => void): void;
18
- removeListener(event: "start", func: () => void): boolean;
17
+ onExit(): Promise<void>;
18
+ addListener(event: "start" | "exit" | "uncaughtexception", func: () => void): void;
19
+ removeListener(event: "start" | "exit" | "uncaughtexception", func: () => void): boolean;
19
20
  onUnCaughtException(e: any): void;
20
21
  addWebServer(server: IWebServer): void;
21
22
  addSocketServer(server: ISocketServer): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "8.2.2545",
3
+ "version": "8.3.4",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",
package/debug.log DELETED
@@ -1,8 +0,0 @@
1
- [0704/133635.639:ERROR:registration_protocol_win.cc(107)] CreateFile: ϵͳ�Ҳ���ָ�����ļ��� (0x2)
2
- [0704/133639.210:ERROR:registration_protocol_win.cc(107)] CreateFile: ϵͳ�Ҳ���ָ�����ļ��� (0x2)
3
- [0704/133639.327:ERROR:registration_protocol_win.cc(107)] CreateFile: ϵͳ�Ҳ���ָ�����ļ��� (0x2)
4
- [0705/134804.446:ERROR:registration_protocol_win.cc(107)] CreateFile: ϵͳ�Ҳ���ָ�����ļ��� (0x2)
5
- [0705/134805.911:ERROR:registration_protocol_win.cc(107)] CreateFile: ϵͳ�Ҳ���ָ�����ļ��� (0x2)
6
- [0705/134805.944:ERROR:registration_protocol_win.cc(107)] CreateFile: ϵͳ�Ҳ���ָ�����ļ��� (0x2)
7
- [0705/155200.976:ERROR:registration_protocol_win.cc(107)] CreateFile: ϵͳ�Ҳ���ָ�����ļ��� (0x2)
8
- [0705/155201.034:ERROR:registration_protocol_win.cc(107)] CreateFile: ϵͳ�Ҳ���ָ�����ļ��� (0x2)
@@ -1,473 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AccountService = exports.GAccountSer = exports.AccountModel = void 0;
10
- const Property_1 = require("./../Database/Decorator/Property");
11
- const MysqlBaseService_1 = require("../Database/MysqlBaseService");
12
- const CacheTool_1 = require("../Logic/CacheTool");
13
- const _error_1 = require("../Config/_error_");
14
- const OpenSocial_1 = require("../ThirdParty/OpenSocial");
15
- const UserService_1 = require("./UserService");
16
- const QQTool_1 = require("../ThirdParty/QQTool");
17
- const WechatTool_1 = require("../ThirdParty/WechatTool");
18
- const Table_1 = require("../Database/Decorator/Table");
19
- const PrimaryKey_1 = require("../Database/Decorator/PrimaryKey");
20
- const NotNull_1 = require("../Database/Decorator/NotNull");
21
- const Type_1 = require("../Database/Decorator/Type");
22
- const AutoIncrement_1 = require("../Database/Decorator/AutoIncrement");
23
- const ini_1 = require("./ini");
24
- let AccountModel = class AccountModel extends MysqlBaseService_1.BaseModel {
25
- id = -1;
26
- phone = "";
27
- email = "";
28
- name = "";
29
- password = "";
30
- unionid = ""; //第三方
31
- openid = "";
32
- create_time = -1;
33
- create_ip = "";
34
- login_time = -1;
35
- login_ip = "";
36
- from = 0;
37
- state = ini_1.EAccountState.Waitting;
38
- };
39
- __decorate([
40
- (0, Type_1.Type)(Property_1.EPropertyType.Int),
41
- NotNull_1.NotNull,
42
- PrimaryKey_1.PrimaryKey,
43
- AutoIncrement_1.AutoIncrement
44
- ], AccountModel.prototype, "id", void 0);
45
- __decorate([
46
- NotNull_1.NotNull,
47
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar)
48
- ], AccountModel.prototype, "phone", void 0);
49
- __decorate([
50
- NotNull_1.NotNull,
51
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar)
52
- ], AccountModel.prototype, "email", void 0);
53
- __decorate([
54
- NotNull_1.NotNull,
55
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar)
56
- ], AccountModel.prototype, "name", void 0);
57
- __decorate([
58
- NotNull_1.NotNull,
59
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar)
60
- ], AccountModel.prototype, "password", void 0);
61
- __decorate([
62
- NotNull_1.NotNull,
63
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "", 128)
64
- ], AccountModel.prototype, "unionid", void 0);
65
- __decorate([
66
- NotNull_1.NotNull,
67
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "", 128)
68
- ], AccountModel.prototype, "openid", void 0);
69
- __decorate([
70
- NotNull_1.NotNull,
71
- (0, Type_1.Type)(Property_1.EPropertyType.BigInt)
72
- ], AccountModel.prototype, "create_time", void 0);
73
- __decorate([
74
- NotNull_1.NotNull,
75
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar)
76
- ], AccountModel.prototype, "create_ip", void 0);
77
- __decorate([
78
- NotNull_1.NotNull,
79
- (0, Type_1.Type)(Property_1.EPropertyType.BigInt)
80
- ], AccountModel.prototype, "login_time", void 0);
81
- __decorate([
82
- NotNull_1.NotNull,
83
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar)
84
- ], AccountModel.prototype, "login_ip", void 0);
85
- __decorate([
86
- NotNull_1.NotNull,
87
- (0, Type_1.Type)(Property_1.EPropertyType.Int)
88
- ], AccountModel.prototype, "from", void 0);
89
- __decorate([
90
- NotNull_1.NotNull,
91
- (0, Type_1.Type)(Property_1.EPropertyType.Int)
92
- ], AccountModel.prototype, "state", void 0);
93
- AccountModel = __decorate([
94
- (0, Table_1.Table)("account", 1, "账号")
95
- ], AccountModel);
96
- exports.AccountModel = AccountModel;
97
- //暂时不实例化,方便重写
98
- exports.GAccountSer = null;
99
- class AccountService extends MysqlBaseService_1.MysqlBaseService {
100
- _account_cache_key_pre = "table_account_";
101
- _account_cache_time_sec = 1 * 60 * 60 * 1000;
102
- constructor() {
103
- super(AccountModel);
104
- exports.GAccountSer = this;
105
- }
106
- _getNewModel() {
107
- return new AccountModel();
108
- }
109
- /**
110
- * 注册新账号
111
- * @param unionid
112
- * @param openid
113
- * @param ip
114
- * @param from
115
- */
116
- async add(unionid, openid, ip, from) {
117
- let account = this._getNewModel();
118
- switch (from) {
119
- case ini_1.EAccountFrom.OpenSocial:
120
- case ini_1.EAccountFrom.WeChat:
121
- case ini_1.EAccountFrom.QQ:
122
- case ini_1.EAccountFrom.Apple:
123
- case ini_1.EAccountFrom.Google:
124
- {
125
- account.unionid = unionid;
126
- account.openid = openid;
127
- break;
128
- }
129
- case ini_1.EAccountFrom.Email:
130
- {
131
- account.email = unionid;
132
- account.password = openid;
133
- break;
134
- }
135
- case ini_1.EAccountFrom.Phone:
136
- case ini_1.EAccountFrom.QuickPhone:
137
- {
138
- account.phone = unionid;
139
- account.password = openid;
140
- break;
141
- }
142
- case ini_1.EAccountFrom.Name:
143
- case ini_1.EAccountFrom.Guest:
144
- {
145
- account.name = unionid;
146
- account.password = openid;
147
- break;
148
- }
149
- }
150
- account.create_time = Date.now();
151
- account.create_ip = ip;
152
- account.login_time = Date.now();
153
- account.login_ip = ip;
154
- account.from = from;
155
- account.state = ini_1.EAccountState.Waitting;
156
- delete account.id;
157
- let sr = await this.insert(account);
158
- if (sr.error
159
- || !sr.results.insertId) {
160
- return null;
161
- }
162
- account.id = sr.results.insertId;
163
- return account;
164
- }
165
- /**
166
- * 通过第三方信息获取账号
167
- * @param unionid
168
- * @param openid
169
- */
170
- async getByThird(unionid, openid) {
171
- let key = this._account_cache_key_pre + unionid;
172
- let am = CacheTool_1.GCacheTool.get(key);
173
- if (am) {
174
- return am;
175
- }
176
- am = await this.get(null, "unionid=? and openid=?", [unionid, openid]);
177
- if (am) {
178
- CacheTool_1.GCacheTool.add(key, am, this._account_cache_time_sec);
179
- }
180
- return am;
181
- }
182
- /**
183
- * 通过第三方信息获取账号
184
- * @param unionid
185
- */
186
- async getByUnionid(unionid) {
187
- let key = this._account_cache_key_pre + unionid;
188
- let am = CacheTool_1.GCacheTool.get(key);
189
- if (am) {
190
- return am;
191
- }
192
- am = await this.get(null, "unionid=?", [unionid]);
193
- if (am) {
194
- CacheTool_1.GCacheTool.add(key, am, this._account_cache_time_sec);
195
- }
196
- return am;
197
- }
198
- async getByPhone(phone) {
199
- let key = this._account_cache_key_pre + phone;
200
- let am = CacheTool_1.GCacheTool.get(key);
201
- if (am) {
202
- return am;
203
- }
204
- am = await this.get(null, "phone=?", [phone]);
205
- if (am) {
206
- CacheTool_1.GCacheTool.add(key, am, this._account_cache_time_sec);
207
- }
208
- return am;
209
- }
210
- /**
211
- * 登陆接口
212
- * @param unionid
213
- * @param openid
214
- * @param ip
215
- * @param from
216
- * @param access_token qq、wechat使用
217
- */
218
- async login(unionid, openid, ip, from, access_token, extra) {
219
- let rs = { errcode: null, account: null, is_new: false };
220
- if (!unionid || !openid) {
221
- rs.errcode = _error_1.EErrorCode.Wrong_Params;
222
- return rs;
223
- }
224
- let login_rs = await this._login(unionid, openid, from);
225
- rs.account = login_rs.account;
226
- rs.errcode = login_rs.errcode;
227
- if (rs.errcode) {
228
- return rs;
229
- }
230
- let account = rs.account;
231
- let extra_info = extra;
232
- if (!account) {
233
- switch (from) {
234
- case ini_1.EAccountFrom.OpenSocial:
235
- case ini_1.EAccountFrom.QQ:
236
- case ini_1.EAccountFrom.WeChat:
237
- case ini_1.EAccountFrom.Guest:
238
- case ini_1.EAccountFrom.QuickPhone:
239
- case ini_1.EAccountFrom.Apple:
240
- case ini_1.EAccountFrom.Google:
241
- {
242
- account = await this.add(unionid, openid, ip, from);
243
- break;
244
- }
245
- default:
246
- {
247
- rs.errcode = _error_1.EErrorCode.No_Account;
248
- return rs;
249
- }
250
- }
251
- }
252
- if (!account) {
253
- rs.errcode = _error_1.EErrorCode.No_Account;
254
- return rs;
255
- }
256
- let user = await UserService_1.GUserSer.getByAccountId(account.id);
257
- if (!user) {
258
- switch (from) {
259
- case ini_1.EAccountFrom.OpenSocial:
260
- case ini_1.EAccountFrom.QQ:
261
- case ini_1.EAccountFrom.WeChat:
262
- case ini_1.EAccountFrom.Apple:
263
- case ini_1.EAccountFrom.Google:
264
- {
265
- if (!extra_info) {
266
- if (from == ini_1.EAccountFrom.OpenSocial) {
267
- let body = await OpenSocial_1.GOpenSocial.getUser(unionid, openid);
268
- if (body && body.errcode) {
269
- rs.errcode = body.errcode;
270
- return rs;
271
- }
272
- else if (body && body.user) {
273
- extra_info =
274
- {
275
- logo: body.user.logo,
276
- sex: body.user.sex,
277
- nickname: body.user.nickname
278
- };
279
- }
280
- }
281
- else if (from == ini_1.EAccountFrom.QQ) {
282
- let userInfo = await QQTool_1.GQQTool.getUserInfo(access_token, openid);
283
- if (userInfo.ret) {
284
- rs.errcode = _error_1.EErrorCode.Server_Error;
285
- return rs;
286
- }
287
- extra_info =
288
- {
289
- logo: userInfo.figureurl_qq,
290
- sex: (userInfo.gender == "男" ? 1 : 0),
291
- nickname: userInfo.nickname
292
- };
293
- }
294
- else if (from == ini_1.EAccountFrom.WeChat) {
295
- let userInfo = await WechatTool_1.GWechatTool.getUserInfo(access_token, openid);
296
- if (userInfo.errcode) {
297
- rs.errcode = _error_1.EErrorCode.Server_Error;
298
- return rs;
299
- }
300
- extra_info =
301
- {
302
- logo: userInfo.headimgurl,
303
- sex: (userInfo.sex == 1 ? 1 : 0),
304
- nickname: userInfo.nickname
305
- };
306
- }
307
- else if (from == ini_1.EAccountFrom.Apple || from == ini_1.EAccountFrom.Google) {
308
- extra_info =
309
- {
310
- logo: "32",
311
- sex: 0,
312
- nickname: "noname"
313
- };
314
- }
315
- }
316
- let user = await UserService_1.GUserSer.add(account.id, extra_info.nickname, extra_info.sex, extra_info.logo);
317
- if (!user) {
318
- this.removeById(account.id);
319
- rs.errcode = _error_1.EErrorCode.User_Create_Failed;
320
- return rs;
321
- }
322
- break;
323
- }
324
- case ini_1.EAccountFrom.QuickPhone:
325
- case ini_1.EAccountFrom.Guest:
326
- {
327
- let user = null;
328
- if (extra_info) {
329
- user = await UserService_1.GUserSer.add(account.id, extra_info.nickname, extra_info.sex, extra_info.logo);
330
- }
331
- else {
332
- user = await UserService_1.GUserSer.add(account.id, null, null, null);
333
- }
334
- if (!user) {
335
- this.removeById(account.id);
336
- rs.errcode = _error_1.EErrorCode.User_Create_Failed;
337
- return rs;
338
- }
339
- break;
340
- }
341
- default:
342
- {
343
- rs.errcode = _error_1.EErrorCode.No_Account;
344
- return rs;
345
- }
346
- }
347
- rs.is_new = true;
348
- if (extra) {
349
- await UserService_1.GUserSer.updateBaseInfoByAccount(account.id, extra_info.nickname, extra_info.sex, extra_info.logo);
350
- }
351
- }
352
- if (user && extra_info) {
353
- await UserService_1.GUserSer.updateProperty("nickname=?,sex=?,logo=?", "id=?", [extra_info.nickname, extra_info.sex || 0, extra_info.logo, user.id]);
354
- }
355
- rs.account = account;
356
- return rs;
357
- }
358
- async _login(unionid, openid, from) {
359
- let rs = { errcode: null, account: null };
360
- if (from == ini_1.EAccountFrom.QQ
361
- || from == ini_1.EAccountFrom.WeChat
362
- || from == ini_1.EAccountFrom.OpenSocial
363
- || from == ini_1.EAccountFrom.Apple
364
- || from == ini_1.EAccountFrom.Google) {
365
- rs.account = await this.getByThird(unionid, openid);
366
- }
367
- else if (from == ini_1.EAccountFrom.QuickPhone) {
368
- let key = "phone_code_" + unionid;
369
- let code = CacheTool_1.GCacheTool.get(key);
370
- if (!code || code != openid) {
371
- rs.errcode = _error_1.EErrorCode.Wrong_Phone_Code;
372
- return rs;
373
- }
374
- rs.account = await this.getByPhone(unionid);
375
- }
376
- else if (from == ini_1.EAccountFrom.Phone) {
377
- rs.account = await this.get(null, "phone=? and password=?", [unionid, openid]);
378
- if (!rs.account) {
379
- rs.errcode = _error_1.EErrorCode.Login_Failed;
380
- }
381
- }
382
- else if (from == ini_1.EAccountFrom.Email) {
383
- rs.account = await this.get(null, "email=? and password=?", [unionid, openid]);
384
- if (!rs.account) {
385
- rs.errcode = _error_1.EErrorCode.Login_Failed;
386
- }
387
- }
388
- else if (from == ini_1.EAccountFrom.Name || from == ini_1.EAccountFrom.Guest) {
389
- rs.account = await this.get(null, "name=? and password=?", [unionid, openid]);
390
- if (!rs.account && from == ini_1.EAccountFrom.Name) {
391
- rs.errcode = _error_1.EErrorCode.Login_Failed;
392
- }
393
- }
394
- return rs;
395
- }
396
- /**
397
- * 修改密码
398
- * @param unionid
399
- * @param openid
400
- * @param new_pwd
401
- */
402
- async updatePwd(unionid, openid, new_pwd) {
403
- let rs = await OpenSocial_1.GOpenSocial.updatePwd(unionid, openid, new_pwd);
404
- return rs;
405
- }
406
- async register(type, key, password, ip, extra) {
407
- let rs = { user: null, errcode: null };
408
- extra = extra || {};
409
- let am = this._getNewModel();
410
- switch (type) {
411
- case ini_1.EAccountFrom.Phone:
412
- {
413
- am.phone = key;
414
- let temp = await this.get("id", "phone=?", [key]);
415
- if (temp) {
416
- rs.errcode = _error_1.EErrorCode.Account_Phone_Exist;
417
- return rs;
418
- }
419
- break;
420
- }
421
- case ini_1.EAccountFrom.Email:
422
- {
423
- am.email = key;
424
- let temp = await this.get("id", "email=?", [key]);
425
- if (temp) {
426
- rs.errcode = _error_1.EErrorCode.Account_Email_Exist;
427
- return rs;
428
- }
429
- break;
430
- }
431
- case ini_1.EAccountFrom.Name:
432
- {
433
- am.name = key;
434
- let temp = await this.get("id", "name=?", [key]);
435
- if (temp) {
436
- rs.errcode = _error_1.EErrorCode.Account_Name_Exist;
437
- return rs;
438
- }
439
- break;
440
- }
441
- default:
442
- {
443
- rs.errcode = _error_1.EErrorCode.Account_Type_Error;
444
- return rs;
445
- }
446
- }
447
- am.password = password;
448
- am.create_time = Date.now();
449
- am.create_ip = ip;
450
- am.login_time = Date.now();
451
- am.login_ip = ip;
452
- let sr = await this.insert(am);
453
- if (sr.results.insertId) {
454
- am.id = sr.results.insertId;
455
- }
456
- else {
457
- am = null;
458
- }
459
- if (!am) {
460
- rs.errcode = _error_1.EErrorCode.Mysql_Error;
461
- return rs;
462
- }
463
- let user = await UserService_1.GUserSer.add(am.id, extra.nickname, extra.sex, extra.logo);
464
- if (!user) {
465
- this.removeById(am.id);
466
- rs.errcode = _error_1.EErrorCode.User_Create_Failed;
467
- return rs;
468
- }
469
- rs.user = user;
470
- return rs;
471
- }
472
- }
473
- exports.AccountService = AccountService;
@@ -1,184 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.UserService = exports.GUserSer = exports.UserModel = void 0;
10
- const _ = require("underscore");
11
- const MysqlBaseService_1 = require("../Database/MysqlBaseService");
12
- const PrimaryKey_1 = require("../Database/Decorator/PrimaryKey");
13
- const NotNull_1 = require("../Database/Decorator/NotNull");
14
- const Property_1 = require("../Database/Decorator/Property");
15
- const Type_1 = require("../Database/Decorator/Type");
16
- const ini_1 = require("./ini");
17
- class UserModel extends MysqlBaseService_1.BaseModel {
18
- id = -1;
19
- account_id = -1;
20
- nickname = "";
21
- sex = -1;
22
- logo = "";
23
- state = ini_1.EUserState.Waitting;
24
- role_group = 4;
25
- role = 0;
26
- phone = "";
27
- wechat = "";
28
- qq = "";
29
- email = "";
30
- about = "";
31
- pre_user_id = -1;
32
- exp = 0;
33
- level = 1; //等级
34
- vip_exp = 0;
35
- vip_level = 0; //等级
36
- is_robot = 0;
37
- create_time = 0;
38
- }
39
- __decorate([
40
- (0, Type_1.Type)(Property_1.EPropertyType.Int),
41
- NotNull_1.NotNull,
42
- PrimaryKey_1.PrimaryKey
43
- ], UserModel.prototype, "id", void 0);
44
- __decorate([
45
- NotNull_1.NotNull,
46
- (0, Type_1.Type)(Property_1.EPropertyType.Int, -1)
47
- ], UserModel.prototype, "account_id", void 0);
48
- __decorate([
49
- NotNull_1.NotNull,
50
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "noname", 32)
51
- ], UserModel.prototype, "nickname", void 0);
52
- __decorate([
53
- NotNull_1.NotNull,
54
- (0, Type_1.Type)(Property_1.EPropertyType.SmallInt, 0)
55
- ], UserModel.prototype, "sex", void 0);
56
- __decorate([
57
- NotNull_1.NotNull,
58
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "", 255)
59
- ], UserModel.prototype, "logo", void 0);
60
- __decorate([
61
- NotNull_1.NotNull,
62
- (0, Type_1.Type)(Property_1.EPropertyType.Int, 0)
63
- ], UserModel.prototype, "state", void 0);
64
- __decorate([
65
- NotNull_1.NotNull,
66
- (0, Type_1.Type)(Property_1.EPropertyType.Int, 4)
67
- ], UserModel.prototype, "role_group", void 0);
68
- __decorate([
69
- NotNull_1.NotNull,
70
- (0, Type_1.Type)(Property_1.EPropertyType.Int, 0)
71
- ], UserModel.prototype, "role", void 0);
72
- __decorate([
73
- NotNull_1.NotNull,
74
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "")
75
- ], UserModel.prototype, "phone", void 0);
76
- __decorate([
77
- NotNull_1.NotNull,
78
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "")
79
- ], UserModel.prototype, "wechat", void 0);
80
- __decorate([
81
- NotNull_1.NotNull,
82
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "")
83
- ], UserModel.prototype, "qq", void 0);
84
- __decorate([
85
- NotNull_1.NotNull,
86
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "")
87
- ], UserModel.prototype, "email", void 0);
88
- __decorate([
89
- NotNull_1.NotNull,
90
- (0, Type_1.Type)(Property_1.EPropertyType.Varchar, "", 512)
91
- ], UserModel.prototype, "about", void 0);
92
- __decorate([
93
- NotNull_1.NotNull,
94
- (0, Type_1.Type)(Property_1.EPropertyType.Int, -1)
95
- ], UserModel.prototype, "pre_user_id", void 0);
96
- __decorate([
97
- NotNull_1.NotNull,
98
- (0, Type_1.Type)(Property_1.EPropertyType.Int, 0)
99
- ], UserModel.prototype, "exp", void 0);
100
- __decorate([
101
- NotNull_1.NotNull,
102
- (0, Type_1.Type)(Property_1.EPropertyType.Int, 1)
103
- ], UserModel.prototype, "level", void 0);
104
- __decorate([
105
- NotNull_1.NotNull,
106
- (0, Type_1.Type)(Property_1.EPropertyType.Int, 0)
107
- ], UserModel.prototype, "vip_exp", void 0);
108
- __decorate([
109
- NotNull_1.NotNull,
110
- (0, Type_1.Type)(Property_1.EPropertyType.Int, 0)
111
- ], UserModel.prototype, "vip_level", void 0);
112
- __decorate([
113
- NotNull_1.NotNull,
114
- (0, Type_1.Type)(Property_1.EPropertyType.TinyInt, 0)
115
- ], UserModel.prototype, "is_robot", void 0);
116
- __decorate([
117
- NotNull_1.NotNull,
118
- (0, Type_1.Type)(Property_1.EPropertyType.BigInt, 0)
119
- ], UserModel.prototype, "create_time", void 0);
120
- exports.UserModel = UserModel;
121
- //暂时不实例化,方便重写
122
- exports.GUserSer = null;
123
- class UserService extends MysqlBaseService_1.MysqlBaseService {
124
- constructor(type) {
125
- super(type);
126
- exports.GUserSer = this;
127
- }
128
- _newUserModel() {
129
- return (new UserModel());
130
- }
131
- async _createNewUser(account_id, nickname, sex, logo, group) {
132
- group = group || ini_1.ERoleGroup.Common;
133
- let um = this._newUserModel();
134
- um.account_id = account_id;
135
- um.nickname = nickname;
136
- if (!um.nickname || um.nickname.length == 0) {
137
- um.nickname = "noname";
138
- }
139
- um.sex = sex || 0;
140
- um.logo = logo || "";
141
- um.account_id = account_id;
142
- um.state = ini_1.EUserState.Waitting;
143
- um.role_group = group;
144
- um.role = 0;
145
- //随机userid
146
- let id = 0;
147
- do {
148
- id = _.random(1000000, 9999999);
149
- let p = await this.get("id", "id=?", [id]);
150
- if (!p) {
151
- break;
152
- }
153
- } while (true);
154
- um.id = id;
155
- return um;
156
- }
157
- async updateBaseInfoByAccount(account_id, nickname, sex, logo) {
158
- let sr = await this.updateProperty("nickname=?,sex=?,logo=?", "account_id=?", [nickname, sex, logo, account_id]);
159
- if (sr.error && sr.results.affectedRows <= 0) {
160
- return "更新失败";
161
- }
162
- return;
163
- }
164
- async add(account_id, nickname, sex, logo, group) {
165
- let um = await this._createNewUser(account_id, nickname, sex, logo, group);
166
- let sr = await this.insert(um);
167
- if (sr.error || sr.results.length <= 0) {
168
- return null;
169
- }
170
- return um;
171
- }
172
- async updateRoleGroup(user_id, role_group) {
173
- let sr = await this.updateProperty("role_group=?", "id=?", [role_group, user_id]);
174
- if (sr.error && sr.results.affectedRows <= 0) {
175
- return "更新失败";
176
- }
177
- return;
178
- }
179
- async getByAccountId(account_id) {
180
- let pm = await this.get(null, "account_id=?", [account_id]);
181
- return pm;
182
- }
183
- }
184
- exports.UserService = UserService;
@@ -1,169 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseUserController = void 0;
4
- const BaseController_1 = require("./BaseController");
5
- const UserService_1 = require("../../Service/UserService");
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 BaseUserController 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 UserService_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 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
- 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 UserService_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.BaseUserController = BaseUserController;
@@ -1,77 +0,0 @@
1
- import { BaseModel, MysqlBaseService } from '../Database/MysqlBaseService';
2
- import { UserModel } from './UserService';
3
- import { EAccountFrom } from './ini';
4
- export declare class AccountModel extends BaseModel {
5
- id: number;
6
- phone: string;
7
- email: string;
8
- name: string;
9
- password: string;
10
- unionid: string;
11
- openid: string;
12
- create_time: number;
13
- create_ip: string;
14
- login_time: number;
15
- login_ip: string;
16
- from: number;
17
- state: number;
18
- }
19
- export declare let GAccountSer: AccountService;
20
- export declare class AccountService extends MysqlBaseService<AccountModel> {
21
- protected _account_cache_key_pre: string;
22
- protected _account_cache_time_sec: number;
23
- constructor();
24
- protected _getNewModel(): AccountModel;
25
- /**
26
- * 注册新账号
27
- * @param unionid
28
- * @param openid
29
- * @param ip
30
- * @param from
31
- */
32
- add(unionid: string, openid: string, ip: string, from: EAccountFrom): Promise<AccountModel>;
33
- /**
34
- * 通过第三方信息获取账号
35
- * @param unionid
36
- * @param openid
37
- */
38
- getByThird(unionid: string, openid: string): Promise<AccountModel>;
39
- /**
40
- * 通过第三方信息获取账号
41
- * @param unionid
42
- */
43
- getByUnionid(unionid: string): Promise<AccountModel>;
44
- getByPhone(phone: string): Promise<AccountModel>;
45
- /**
46
- * 登陆接口
47
- * @param unionid
48
- * @param openid
49
- * @param ip
50
- * @param from
51
- * @param access_token qq、wechat使用
52
- */
53
- login(unionid: string, openid: string, ip: string, from: EAccountFrom, access_token?: string, extra?: {
54
- nickname: string;
55
- sex: number;
56
- logo: string;
57
- }): Promise<{
58
- errcode: any;
59
- account: AccountModel;
60
- is_new: boolean;
61
- }>;
62
- protected _login(unionid: string, openid: string, from: EAccountFrom): Promise<{
63
- errcode: any;
64
- account: AccountModel;
65
- }>;
66
- /**
67
- * 修改密码
68
- * @param unionid
69
- * @param openid
70
- * @param new_pwd
71
- */
72
- updatePwd(unionid: string, openid: string, new_pwd: string): Promise<any>;
73
- register(type: EAccountFrom, key: string, password: string, ip: string, extra?: any): Promise<{
74
- user: UserModel;
75
- errcode: any;
76
- }>;
77
- }
@@ -1,36 +0,0 @@
1
- import { MysqlBaseService, BaseModel } from "../Database/MysqlBaseService";
2
- import { ERoleGroup } from "./ini";
3
- export declare class UserModel extends BaseModel {
4
- id: number;
5
- account_id: number;
6
- nickname: string;
7
- sex: number;
8
- logo: string;
9
- state: number;
10
- role_group: number;
11
- role: number;
12
- phone: string;
13
- wechat: string;
14
- qq: string;
15
- email: string;
16
- about: string;
17
- pre_user_id: number;
18
- exp: number;
19
- level: number;
20
- vip_exp: number;
21
- vip_level: number;
22
- is_robot: number;
23
- create_time: number;
24
- }
25
- export declare let GUserSer: UserService<UserModel>;
26
- export declare class UserService<T extends UserModel> extends MysqlBaseService<T> {
27
- constructor(type: {
28
- new (): T;
29
- });
30
- protected _newUserModel(): T;
31
- protected _createNewUser(account_id: number, nickname: string, sex: number, logo: string, group?: ERoleGroup): Promise<T>;
32
- updateBaseInfoByAccount(account_id: number, nickname: string, sex: number, logo: string): Promise<string>;
33
- add(account_id: number, nickname: string, sex: number, logo: string, group?: ERoleGroup): Promise<any>;
34
- updateRoleGroup(user_id: number, role_group: ERoleGroup): Promise<string>;
35
- getByAccountId(account_id: number): Promise<T>;
36
- }
@@ -1,27 +0,0 @@
1
- import { BaseController } from './BaseController';
2
- import { UserModel } from '../../Service/UserService';
3
- export declare class BaseUserController<T extends UserModel> extends BaseController {
4
- protected _user_session_id: string;
5
- protected _self_user: T;
6
- protected _user: T;
7
- protected _session_id: string;
8
- get selfUser(): T;
9
- get isSelf(): boolean;
10
- get isLogin(): boolean;
11
- get isCreator(): boolean;
12
- get isAdmin(): boolean;
13
- get isProxy(): boolean;
14
- get isCommon(): boolean;
15
- init(): Promise<void>;
16
- protected _getUserBySession(session: string): Promise<T>;
17
- protected _logout(): void;
18
- protected _login(user: T): void;
19
- /**
20
- * 已经被启用
21
- */
22
- protected _update_session(): Promise<void>;
23
- update_user(user_id: number): Promise<void>;
24
- protected _init_data(datas: any): {
25
- model: any;
26
- };
27
- }