cgserver 6.0.6 → 6.0.9

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.
Files changed (136) hide show
  1. package/dist/lib/AI/AiObject.js +10 -0
  2. package/dist/lib/AI/Astar.js +133 -0
  3. package/dist/lib/AI/BehaviorAI.js +307 -0
  4. package/dist/lib/AI/Entity.js +33 -0
  5. package/dist/lib/AI/Point.js +68 -0
  6. package/dist/lib/AI/TriggerMgr.js +201 -0
  7. package/dist/lib/Config/Config.js +37 -0
  8. package/dist/lib/Config/FrameworkConfig.js +234 -0
  9. package/dist/lib/Config/ServerConfig.js +18 -0
  10. package/dist/lib/Config/_error_.js +35 -0
  11. package/dist/lib/Core/Core.js +561 -0
  12. package/dist/lib/Core/Timer.js +116 -0
  13. package/dist/lib/Database/BaseMongoService.js +79 -0
  14. package/dist/lib/Database/BaseService.js +281 -0
  15. package/dist/lib/Database/Decorator/AutoIncrement.js +11 -0
  16. package/dist/lib/Database/Decorator/DBCache.js +64 -0
  17. package/dist/lib/Database/Decorator/NotNull.js +11 -0
  18. package/dist/lib/Database/Decorator/PrimaryKey.js +11 -0
  19. package/dist/lib/Database/Decorator/Property.js +61 -0
  20. package/dist/lib/Database/Decorator/Table.js +15 -0
  21. package/dist/lib/Database/Decorator/Type.js +20 -0
  22. package/dist/lib/Database/MSSqlManager.js +43 -0
  23. package/dist/lib/Database/MongoManager.js +401 -0
  24. package/dist/lib/Database/MysqlManager.js +180 -0
  25. package/dist/lib/Database/RedisManager.js +408 -0
  26. package/dist/lib/Logic/CacheTool.js +73 -0
  27. package/dist/lib/Logic/HttpTool.js +58 -0
  28. package/dist/lib/Logic/Log.js +77 -0
  29. package/dist/lib/Service/AccountService.js +473 -0
  30. package/dist/lib/Service/MongoAccountService.js +396 -0
  31. package/dist/lib/Service/MongoCacheService.js +27 -0
  32. package/dist/lib/Service/MongoUserService.js +93 -0
  33. package/dist/lib/Service/UserService.js +184 -0
  34. package/dist/lib/Service/ini.js +35 -0
  35. package/dist/lib/SocketServer/IClientWebSocket.js +71 -0
  36. package/dist/lib/SocketServer/IServerWebSocket.js +41 -0
  37. package/dist/lib/SocketServer/ISocketServer.js +190 -0
  38. package/dist/lib/SocketServer/IWebSocket.js +223 -0
  39. package/dist/lib/SocketServer/ProtoFilter/GoogleProtoFilter.js +57 -0
  40. package/dist/lib/SocketServer/ProtoFilter/IProtoFilter.js +8 -0
  41. package/dist/lib/SocketServer/ProtoFilter/JsonProtoFilter.js +29 -0
  42. package/dist/lib/SocketServer/ProtoFilter/ProtoFactory.js +31 -0
  43. package/dist/lib/ThirdParty/AlipayTool.js +122 -0
  44. package/dist/lib/ThirdParty/Alisms.js +46 -0
  45. package/dist/lib/ThirdParty/AppleTool.js +234 -0
  46. package/dist/lib/ThirdParty/EmailTool.js +33 -0
  47. package/dist/lib/ThirdParty/OpenSocial.js +32 -0
  48. package/dist/lib/ThirdParty/QQTool.js +115 -0
  49. package/dist/lib/ThirdParty/QiniuTool.js +21 -0
  50. package/dist/lib/ThirdParty/WechatOATool.js +61 -0
  51. package/dist/lib/ThirdParty/WechatTool.js +74 -0
  52. package/dist/lib/WebServer/Controller/BaseController.js +112 -0
  53. package/dist/lib/WebServer/Controller/BaseUserController.js +168 -0
  54. package/dist/lib/WebServer/Controller/MongoBaseUserController.js +168 -0
  55. package/dist/lib/WebServer/Decorator/AdminValidate.js +19 -0
  56. package/dist/lib/WebServer/Decorator/AuthorityValidate.js +22 -0
  57. package/dist/lib/WebServer/Decorator/CreatorValidate.js +19 -0
  58. package/dist/lib/WebServer/Decorator/JsonAdminValidate.js +15 -0
  59. package/dist/lib/WebServer/Decorator/JsonAuthorityValidate.js +20 -0
  60. package/dist/lib/WebServer/Decorator/JsonCreatorValidate.js +19 -0
  61. package/dist/lib/WebServer/Engine/ControllerManager.js +112 -0
  62. package/dist/lib/WebServer/Engine/Engine.js +135 -0
  63. package/dist/lib/WebServer/Engine/RazorJs.js +544 -0
  64. package/dist/lib/WebServer/Engine/Request.js +214 -0
  65. package/dist/lib/WebServer/Engine/Response.js +94 -0
  66. package/dist/lib/WebServer/IWebServer.js +49 -0
  67. package/dist/lib/cgserver.js +153 -0
  68. package/dist/{AI → types/AI}/AiObject.d.ts +0 -0
  69. package/dist/{AI → types/AI}/Astar.d.ts +0 -0
  70. package/dist/{AI → types/AI}/BehaviorAI.d.ts +0 -0
  71. package/dist/{AI → types/AI}/Entity.d.ts +0 -0
  72. package/dist/{AI → types/AI}/Point.d.ts +0 -0
  73. package/dist/{AI → types/AI}/TriggerMgr.d.ts +0 -0
  74. package/dist/{Config → types/Config}/Config.d.ts +0 -0
  75. package/dist/{Config → types/Config}/FrameworkConfig.d.ts +0 -0
  76. package/dist/{Config → types/Config}/ServerConfig.d.ts +0 -0
  77. package/dist/{Config → types/Config}/_error_.d.ts +0 -0
  78. package/dist/{Core → types/Core}/Core.d.ts +0 -0
  79. package/dist/{Core → types/Core}/Timer.d.ts +0 -0
  80. package/dist/{Database → types/Database}/BaseMongoService.d.ts +0 -0
  81. package/dist/{Database → types/Database}/BaseService.d.ts +0 -0
  82. package/dist/{Database → types/Database}/Decorator/AutoIncrement.d.ts +0 -0
  83. package/dist/{Database → types/Database}/Decorator/DBCache.d.ts +0 -0
  84. package/dist/{Database → types/Database}/Decorator/NotNull.d.ts +0 -0
  85. package/dist/{Database → types/Database}/Decorator/PrimaryKey.d.ts +0 -0
  86. package/dist/{Database → types/Database}/Decorator/Property.d.ts +0 -0
  87. package/dist/{Database → types/Database}/Decorator/Table.d.ts +0 -0
  88. package/dist/{Database → types/Database}/Decorator/Type.d.ts +0 -0
  89. package/dist/{Database → types/Database}/MSSqlManager.d.ts +0 -0
  90. package/dist/{Database → types/Database}/MongoManager.d.ts +0 -0
  91. package/dist/{Database → types/Database}/MysqlManager.d.ts +0 -0
  92. package/dist/{Database → types/Database}/RedisManager.d.ts +0 -0
  93. package/dist/{Logic → types/Logic}/CacheTool.d.ts +0 -0
  94. package/dist/{Logic → types/Logic}/HttpTool.d.ts +0 -0
  95. package/dist/{Logic → types/Logic}/Log.d.ts +0 -0
  96. package/dist/{Service → types/Service}/AccountService.d.ts +0 -0
  97. package/dist/{Service → types/Service}/MongoAccountService.d.ts +0 -0
  98. package/dist/{Service → types/Service}/MongoCacheService.d.ts +0 -0
  99. package/dist/{Service → types/Service}/MongoUserService.d.ts +0 -0
  100. package/dist/{Service → types/Service}/UserService.d.ts +0 -0
  101. package/dist/{Service → types/Service}/ini.d.ts +0 -0
  102. package/dist/{SocketServer → types/SocketServer}/IClientWebSocket.d.ts +0 -0
  103. package/dist/{SocketServer → types/SocketServer}/IServerWebSocket.d.ts +0 -0
  104. package/dist/{SocketServer → types/SocketServer}/ISocketServer.d.ts +0 -0
  105. package/dist/{SocketServer → types/SocketServer}/IWebSocket.d.ts +0 -0
  106. package/dist/{SocketServer → types/SocketServer}/ProtoFilter/GoogleProtoFilter.d.ts +0 -0
  107. package/dist/{SocketServer → types/SocketServer}/ProtoFilter/IProtoFilter.d.ts +0 -0
  108. package/dist/{SocketServer → types/SocketServer}/ProtoFilter/JsonProtoFilter.d.ts +0 -0
  109. package/dist/{SocketServer → types/SocketServer}/ProtoFilter/ProtoFactory.d.ts +0 -0
  110. package/dist/{ThirdParty → types/ThirdParty}/AlipayTool.d.ts +0 -0
  111. package/dist/{ThirdParty → types/ThirdParty}/Alisms.d.ts +0 -0
  112. package/dist/{ThirdParty → types/ThirdParty}/AppleTool.d.ts +0 -0
  113. package/dist/{ThirdParty → types/ThirdParty}/EmailTool.d.ts +0 -0
  114. package/dist/{ThirdParty → types/ThirdParty}/OpenSocial.d.ts +0 -0
  115. package/dist/{ThirdParty → types/ThirdParty}/QQTool.d.ts +0 -0
  116. package/dist/{ThirdParty → types/ThirdParty}/QiniuTool.d.ts +0 -0
  117. package/dist/{ThirdParty → types/ThirdParty}/WechatOATool.d.ts +0 -0
  118. package/dist/{ThirdParty → types/ThirdParty}/WechatTool.d.ts +0 -0
  119. package/dist/{WebServer → types/WebServer}/Controller/BaseController.d.ts +0 -0
  120. package/dist/{WebServer → types/WebServer}/Controller/BaseUserController.d.ts +0 -0
  121. package/dist/{WebServer → types/WebServer}/Controller/MongoBaseUserController.d.ts +0 -0
  122. package/dist/{WebServer → types/WebServer}/Decorator/AdminValidate.d.ts +0 -0
  123. package/dist/{WebServer → types/WebServer}/Decorator/AuthorityValidate.d.ts +0 -0
  124. package/dist/{WebServer → types/WebServer}/Decorator/CreatorValidate.d.ts +0 -0
  125. package/dist/{WebServer → types/WebServer}/Decorator/JsonAdminValidate.d.ts +0 -0
  126. package/dist/{WebServer → types/WebServer}/Decorator/JsonAuthorityValidate.d.ts +0 -0
  127. package/dist/{WebServer → types/WebServer}/Decorator/JsonCreatorValidate.d.ts +0 -0
  128. package/dist/{WebServer → types/WebServer}/Engine/ControllerManager.d.ts +0 -0
  129. package/dist/{WebServer → types/WebServer}/Engine/Engine.d.ts +0 -0
  130. package/dist/{WebServer → types/WebServer}/Engine/RazorJs.d.ts +0 -0
  131. package/dist/{WebServer → types/WebServer}/Engine/Request.d.ts +0 -0
  132. package/dist/{WebServer → types/WebServer}/Engine/Response.d.ts +0 -0
  133. package/dist/{WebServer → types/WebServer}/IWebServer.d.ts +0 -0
  134. package/dist/{cgserver.d.ts → types/cgserver.d.ts} +0 -0
  135. package/package.json +3 -2
  136. package/dist/cgserver.js +0 -1037
@@ -0,0 +1,473 @@
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 BaseService_1 = require("./../Database/BaseService");
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 BaseService_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 = 0;
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 BaseService_1.BaseService {
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 = 1;
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;