loginByMobile处理mergedUser情况
This commit is contained in:
parent
6e20f5f6e7
commit
e3797247a2
|
|
@ -94,13 +94,87 @@ function tryMakeChangeLoginWay(userId, context) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function dealWithUserState(user, context, tokenData) {
|
||||||
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||||
|
var _a, _b, user2;
|
||||||
|
var _c, _d;
|
||||||
|
return tslib_1.__generator(this, function (_e) {
|
||||||
|
switch (_e.label) {
|
||||||
|
case 0:
|
||||||
|
_a = user.userState;
|
||||||
|
switch (_a) {
|
||||||
|
case 'disabled': return [3 /*break*/, 1];
|
||||||
|
case 'shadow': return [3 /*break*/, 2];
|
||||||
|
case 'merged': return [3 /*break*/, 4];
|
||||||
|
}
|
||||||
|
return [3 /*break*/, 7];
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
throw new Exception_1.OakUserDisabledException();
|
||||||
|
}
|
||||||
|
_e.label = 2;
|
||||||
|
case 2:
|
||||||
|
_c = {
|
||||||
|
userId: user.id
|
||||||
|
};
|
||||||
|
_d = {};
|
||||||
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
|
case 3: return [2 /*return*/, (_c.user = (_d.id = _e.sent(),
|
||||||
|
_d.action = 'activate',
|
||||||
|
_d.data = {},
|
||||||
|
_d),
|
||||||
|
_c)];
|
||||||
|
case 4:
|
||||||
|
(0, assert_1.assert)(user === null || user === void 0 ? void 0 : user.refId);
|
||||||
|
return [4 /*yield*/, context.select('user', {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
userState: 1,
|
||||||
|
refId: 1,
|
||||||
|
wechatUser$user: {
|
||||||
|
$entity: 'wechatUser',
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
userSystem$user: {
|
||||||
|
$entity: 'userSystem',
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
systemId: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: user.refId,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
dontCollect: true,
|
||||||
|
})];
|
||||||
|
case 5:
|
||||||
|
_b = tslib_1.__read.apply(void 0, [_e.sent(), 1]), user2 = _b[0];
|
||||||
|
return [4 /*yield*/, dealWithUserState(user2, context, tokenData)];
|
||||||
|
case 6: return [2 /*return*/, _e.sent()];
|
||||||
|
case 7:
|
||||||
|
{
|
||||||
|
(0, assert_1.assert)(user.userState === 'normal');
|
||||||
|
return [2 /*return*/, {
|
||||||
|
userId: user.id,
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
_e.label = 8;
|
||||||
|
case 8: return [2 /*return*/];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
function setupMobile(mobile, env, context) {
|
function setupMobile(mobile, env, context) {
|
||||||
var _a;
|
var _a;
|
||||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||||
var currentToken, applicationId, systemId, result2, _b, mobileRow, userId, user, userState, _c, tokenData, user, userState, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, mobileData, _p, _q, _r, userData, _s, _t, _u, mobileData, tokenData, _v, _w, _x, _y, _z, _0;
|
var currentToken, applicationId, systemId, result2, _b, mobileRow, userId, user, userState, _c, tokenData, user, userState, _d, _e, _f, _g, _h, _j, _k, _l, _m, mobileData, _o, _p, _q, userData, _r, _s, _t, mobileData, tokenData, _u, _v, _w, _x, _y, _z;
|
||||||
var _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
|
var _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
|
||||||
return tslib_1.__generator(this, function (_15) {
|
return tslib_1.__generator(this, function (_12) {
|
||||||
switch (_15.label) {
|
switch (_12.label) {
|
||||||
case 0:
|
case 0:
|
||||||
currentToken = context.getToken(true);
|
currentToken = context.getToken(true);
|
||||||
applicationId = context.getApplicationId();
|
applicationId = context.getApplicationId();
|
||||||
|
|
@ -114,6 +188,7 @@ function setupMobile(mobile, env, context) {
|
||||||
user: {
|
user: {
|
||||||
id: 1,
|
id: 1,
|
||||||
userState: 1,
|
userState: 1,
|
||||||
|
refId: 1,
|
||||||
wechatUser$user: {
|
wechatUser$user: {
|
||||||
$entity: 'wechatUser',
|
$entity: 'wechatUser',
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -135,8 +210,8 @@ function setupMobile(mobile, env, context) {
|
||||||
}
|
}
|
||||||
}, { dontCollect: true })];
|
}, { dontCollect: true })];
|
||||||
case 1:
|
case 1:
|
||||||
result2 = _15.sent();
|
result2 = _12.sent();
|
||||||
if (!(result2.length > 0)) return [3 /*break*/, 23];
|
if (!(result2.length > 0)) return [3 /*break*/, 19];
|
||||||
// 此手机号已经存在
|
// 此手机号已经存在
|
||||||
(0, assert_1.assert)(result2.length === 1);
|
(0, assert_1.assert)(result2.length === 1);
|
||||||
_b = tslib_1.__read(result2, 1), mobileRow = _b[0];
|
_b = tslib_1.__read(result2, 1), mobileRow = _b[0];
|
||||||
|
|
@ -156,13 +231,13 @@ function setupMobile(mobile, env, context) {
|
||||||
{
|
{
|
||||||
throw new Exception_1.OakUserDisabledException();
|
throw new Exception_1.OakUserDisabledException();
|
||||||
}
|
}
|
||||||
_15.label = 4;
|
_12.label = 4;
|
||||||
case 4:
|
case 4:
|
||||||
// 直接合并
|
// 直接合并
|
||||||
return [4 /*yield*/, (0, user_1.mergeUser)({ from: userId, to: currentToken.userId }, context, true)];
|
return [4 /*yield*/, (0, user_1.mergeUser)({ from: userId, to: currentToken.userId }, context, true)];
|
||||||
case 5:
|
case 5:
|
||||||
// 直接合并
|
// 直接合并
|
||||||
_15.sent();
|
_12.sent();
|
||||||
return [2 /*return*/, currentToken.id];
|
return [2 /*return*/, currentToken.id];
|
||||||
case 6:
|
case 6:
|
||||||
/* assert(userState === 'normal');
|
/* assert(userState === 'normal');
|
||||||
|
|
@ -173,170 +248,142 @@ function setupMobile(mobile, env, context) {
|
||||||
/* assert(userState === 'normal');
|
/* assert(userState === 'normal');
|
||||||
throw await makeDistinguishException<ED, Cxt>(userId as string, context, '该手机号已被一个有效用户占用,请联系管理员处理'); */
|
throw await makeDistinguishException<ED, Cxt>(userId as string, context, '该手机号已被一个有效用户占用,请联系管理员处理'); */
|
||||||
// 直接合并
|
// 直接合并
|
||||||
_15.sent();
|
_12.sent();
|
||||||
return [2 /*return*/, currentToken.id];
|
return [2 /*return*/, currentToken.id];
|
||||||
case 8: return [3 /*break*/, 22];
|
case 8: return [3 /*break*/, 18];
|
||||||
case 9:
|
case 9:
|
||||||
_1 = {};
|
_0 = {};
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
case 10:
|
case 10:
|
||||||
tokenData = (_1.id = _15.sent(),
|
tokenData = (_0.id = _12.sent(),
|
||||||
_1.applicationId = applicationId,
|
_0.applicationId = applicationId,
|
||||||
_1.playerId = mobileRow.userId,
|
_0.playerId = mobileRow.userId,
|
||||||
_1.env = env,
|
_0.env = env,
|
||||||
_1.entity = 'mobile',
|
_0.entity = 'mobile',
|
||||||
_1.entityId = mobileRow.id,
|
_0.entityId = mobileRow.id,
|
||||||
_1);
|
_0);
|
||||||
user = mobileRow.user;
|
user = mobileRow.user;
|
||||||
userState = user.userState;
|
userState = user.userState;
|
||||||
_d = userState;
|
// 可能出现多次merge的情况
|
||||||
switch (_d) {
|
_e = (_d = Object).assign;
|
||||||
case 'disabled': return [3 /*break*/, 11];
|
_f = [tokenData];
|
||||||
case 'shadow': return [3 /*break*/, 12];
|
return [4 /*yield*/, dealWithUserState(user, context, tokenData)];
|
||||||
}
|
|
||||||
return [3 /*break*/, 14];
|
|
||||||
case 11:
|
case 11:
|
||||||
{
|
// 可能出现多次merge的情况
|
||||||
throw new Exception_1.OakUserDisabledException();
|
_e.apply(_d, _f.concat([_12.sent()]));
|
||||||
}
|
_h = (_g = context).operate;
|
||||||
_15.label = 12;
|
_j = ['token'];
|
||||||
case 12:
|
_1 = {};
|
||||||
_f = (_e = Object).assign;
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
_g = [tokenData];
|
case 12: return [4 /*yield*/, _h.apply(_g, _j.concat([(_1.id = _12.sent(),
|
||||||
_2 = {
|
_1.data = tokenData,
|
||||||
userId: mobileRow.userId
|
_1.action = 'create',
|
||||||
};
|
_1), {
|
||||||
|
dontCollect: true,
|
||||||
|
}]))];
|
||||||
|
case 13:
|
||||||
|
_12.sent();
|
||||||
|
if (!(((_a = user === null || user === void 0 ? void 0 : user.userSystem$user) === null || _a === void 0 ? void 0 : _a.length) == 0)) return [3 /*break*/, 17];
|
||||||
|
_l = (_k = context).operate;
|
||||||
|
_m = ['userSystem'];
|
||||||
|
_2 = {};
|
||||||
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
|
case 14:
|
||||||
|
_2.id = _12.sent(),
|
||||||
|
_2.action = 'create';
|
||||||
_3 = {};
|
_3 = {};
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
case 13:
|
case 15: return [4 /*yield*/, _l.apply(_k, _m.concat([(_2.data = (_3.id = _12.sent(),
|
||||||
_f.apply(_e, _g.concat([(_2.user = (_3.id = _15.sent(),
|
_3.userId = user.id,
|
||||||
_3.action = 'activate',
|
_3.systemId = systemId,
|
||||||
_3.data = {},
|
|
||||||
_3),
|
_3),
|
||||||
_2)]));
|
_2), {
|
||||||
return [3 /*break*/, 15];
|
dontCollect: true,
|
||||||
case 14:
|
}]))];
|
||||||
{
|
case 16:
|
||||||
(0, assert_1.assert)(userState === 'normal');
|
_12.sent();
|
||||||
Object.assign(tokenData, {
|
_12.label = 17;
|
||||||
userId: mobileRow.userId,
|
case 17: return [2 /*return*/, tokenData.id];
|
||||||
});
|
case 18: return [3 /*break*/, 34];
|
||||||
}
|
case 19:
|
||||||
_15.label = 15;
|
if (!currentToken) return [3 /*break*/, 23];
|
||||||
case 15:
|
|
||||||
_j = (_h = context).operate;
|
|
||||||
_k = ['token'];
|
|
||||||
_4 = {};
|
_4 = {};
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
case 16: return [4 /*yield*/, _j.apply(_h, _k.concat([(_4.id = _15.sent(),
|
case 20:
|
||||||
_4.data = tokenData,
|
mobileData = (_4.id = _12.sent(),
|
||||||
_4.action = 'create',
|
_4.mobile = mobile,
|
||||||
_4), {
|
_4.userId = currentToken.userId,
|
||||||
dontCollect: true,
|
_4);
|
||||||
}]))];
|
_p = (_o = context).operate;
|
||||||
case 17:
|
_q = ['mobile'];
|
||||||
_15.sent();
|
|
||||||
if (!(((_a = user === null || user === void 0 ? void 0 : user.userSystem$user) === null || _a === void 0 ? void 0 : _a.length) == 0)) return [3 /*break*/, 21];
|
|
||||||
_m = (_l = context).operate;
|
|
||||||
_o = ['userSystem'];
|
|
||||||
_5 = {};
|
_5 = {};
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
case 18:
|
case 21: return [4 /*yield*/, _p.apply(_o, _q.concat([(_5.id = _12.sent(),
|
||||||
_5.id = _15.sent(),
|
_5.action = 'create',
|
||||||
_5.action = 'create';
|
_5.data = mobileData,
|
||||||
|
_5), {}]))];
|
||||||
|
case 22:
|
||||||
|
_12.sent();
|
||||||
|
return [2 /*return*/, currentToken.id];
|
||||||
|
case 23:
|
||||||
_6 = {};
|
_6 = {};
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
case 19: return [4 /*yield*/, _m.apply(_l, _o.concat([(_5.data = (_6.id = _15.sent(),
|
case 24:
|
||||||
_6.userId = user.id,
|
userData = (_6.id = _12.sent(),
|
||||||
_6.systemId = systemId,
|
_6.userState = 'normal',
|
||||||
_6),
|
_6);
|
||||||
_5), {
|
_s = (_r = context).operate;
|
||||||
dontCollect: true,
|
_t = ['user'];
|
||||||
}]))];
|
|
||||||
case 20:
|
|
||||||
_15.sent();
|
|
||||||
_15.label = 21;
|
|
||||||
case 21: return [2 /*return*/, tokenData.id];
|
|
||||||
case 22: return [3 /*break*/, 38];
|
|
||||||
case 23:
|
|
||||||
if (!currentToken) return [3 /*break*/, 27];
|
|
||||||
_7 = {};
|
_7 = {};
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
case 24:
|
case 25: return [4 /*yield*/, _s.apply(_r, _t.concat([(_7.id = _12.sent(),
|
||||||
mobileData = (_7.id = _15.sent(),
|
_7.action = 'create',
|
||||||
_7.mobile = mobile,
|
_7.data = userData,
|
||||||
_7.userId = currentToken.userId,
|
_7), {}]))];
|
||||||
_7);
|
case 26:
|
||||||
_q = (_p = context).operate;
|
_12.sent();
|
||||||
_r = ['mobile'];
|
|
||||||
_8 = {};
|
_8 = {};
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
case 25: return [4 /*yield*/, _q.apply(_p, _r.concat([(_8.id = _15.sent(),
|
|
||||||
_8.action = 'create',
|
|
||||||
_8.data = mobileData,
|
|
||||||
_8), {}]))];
|
|
||||||
case 26:
|
|
||||||
_15.sent();
|
|
||||||
return [2 /*return*/, currentToken.id];
|
|
||||||
case 27:
|
case 27:
|
||||||
|
mobileData = (_8.id = _12.sent(),
|
||||||
|
_8.mobile = mobile,
|
||||||
|
_8.userId = userData.id,
|
||||||
|
_8);
|
||||||
_9 = {};
|
_9 = {};
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
case 28:
|
case 28:
|
||||||
userData = (_9.id = _15.sent(),
|
tokenData = (_9.id = _12.sent(),
|
||||||
_9.userState = 'normal',
|
_9.userId = userData.id,
|
||||||
|
_9.playerId = userData.id,
|
||||||
|
_9.env = env,
|
||||||
|
_9.entity = 'mobile',
|
||||||
|
_9.entityId = mobileData.id,
|
||||||
_9);
|
_9);
|
||||||
_t = (_s = context).operate;
|
_v = (_u = context).operate;
|
||||||
_u = ['user'];
|
_w = ['token'];
|
||||||
_10 = {};
|
_10 = {};
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
case 29: return [4 /*yield*/, _t.apply(_s, _u.concat([(_10.id = _15.sent(),
|
case 29: return [4 /*yield*/, _v.apply(_u, _w.concat([(_10.id = _12.sent(),
|
||||||
_10.action = 'create',
|
_10.action = 'create',
|
||||||
_10.data = userData,
|
_10.data = tokenData,
|
||||||
_10), {}]))];
|
_10), { dontCollect: true }]))];
|
||||||
case 30:
|
case 30:
|
||||||
_15.sent();
|
_12.sent();
|
||||||
|
return [4 /*yield*/, context.setTokenValue(tokenData.id)];
|
||||||
|
case 31:
|
||||||
|
_12.sent();
|
||||||
|
_y = (_x = context).operate;
|
||||||
|
_z = ['mobile'];
|
||||||
_11 = {};
|
_11 = {};
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
case 31:
|
case 32: return [4 /*yield*/, _y.apply(_x, _z.concat([(_11.id = _12.sent(),
|
||||||
mobileData = (_11.id = _15.sent(),
|
_11.action = 'create',
|
||||||
_11.mobile = mobile,
|
_11.data = mobileData,
|
||||||
_11.userId = userData.id,
|
_11), { dontCollect: true }]))];
|
||||||
_11);
|
case 33:
|
||||||
_12 = {};
|
_12.sent();
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
||||||
case 32:
|
|
||||||
tokenData = (_12.id = _15.sent(),
|
|
||||||
_12.userId = userData.id,
|
|
||||||
_12.playerId = userData.id,
|
|
||||||
_12.env = env,
|
|
||||||
_12.entity = 'mobile',
|
|
||||||
_12.entityId = mobileData.id,
|
|
||||||
_12);
|
|
||||||
_w = (_v = context).operate;
|
|
||||||
_x = ['token'];
|
|
||||||
_13 = {};
|
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
||||||
case 33: return [4 /*yield*/, _w.apply(_v, _x.concat([(_13.id = _15.sent(),
|
|
||||||
_13.action = 'create',
|
|
||||||
_13.data = tokenData,
|
|
||||||
_13), { dontCollect: true }]))];
|
|
||||||
case 34:
|
|
||||||
_15.sent();
|
|
||||||
return [4 /*yield*/, context.setTokenValue(tokenData.id)];
|
|
||||||
case 35:
|
|
||||||
_15.sent();
|
|
||||||
_z = (_y = context).operate;
|
|
||||||
_0 = ['mobile'];
|
|
||||||
_14 = {};
|
|
||||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
||||||
case 36: return [4 /*yield*/, _z.apply(_y, _0.concat([(_14.id = _15.sent(),
|
|
||||||
_14.action = 'create',
|
|
||||||
_14.data = mobileData,
|
|
||||||
_14), { dontCollect: true }]))];
|
|
||||||
case 37:
|
|
||||||
_15.sent();
|
|
||||||
return [2 /*return*/, tokenData.id];
|
return [2 /*return*/, tokenData.id];
|
||||||
case 38: return [2 /*return*/];
|
case 34: return [2 /*return*/];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,59 @@ async function tryMakeChangeLoginWay<ED extends EntityDict, Cxt extends BackendR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function dealWithUserState(user: Partial<EntityDict['user']['Schema']>, context: BackendRuntimeContext<EntityDict>, tokenData: EntityDict['token']['CreateSingle']['data']): Promise<Partial<EntityDict['token']['CreateSingle']['data']>> {
|
||||||
|
switch (user.userState) {
|
||||||
|
case 'disabled': {
|
||||||
|
throw new OakUserDisabledException();
|
||||||
|
}
|
||||||
|
case 'shadow': {
|
||||||
|
return {
|
||||||
|
userId: user.id,
|
||||||
|
user: {
|
||||||
|
id: await generateNewIdAsync(),
|
||||||
|
action: 'activate',
|
||||||
|
data: {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'merged': {
|
||||||
|
assert(user?.refId);
|
||||||
|
const [user2] = await context.select('user', {
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
userState: 1,
|
||||||
|
refId: 1,
|
||||||
|
wechatUser$user: {
|
||||||
|
$entity: 'wechatUser',
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
userSystem$user: {
|
||||||
|
$entity: 'userSystem',
|
||||||
|
data: {
|
||||||
|
id: 1,
|
||||||
|
systemId: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: user.refId,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
dontCollect: true,
|
||||||
|
})
|
||||||
|
return await dealWithUserState(user2, context, tokenData);
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
assert(user.userState === 'normal');
|
||||||
|
return {
|
||||||
|
userId: user.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function setupMobile<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(mobile: string, env: WebEnv | WechatMpEnv, context: Cxt) {
|
async function setupMobile<ED extends EntityDict, Cxt extends BackendRuntimeContext<ED>>(mobile: string, env: WebEnv | WechatMpEnv, context: Cxt) {
|
||||||
const currentToken = context.getToken(true);
|
const currentToken = context.getToken(true);
|
||||||
const applicationId = context.getApplicationId();
|
const applicationId = context.getApplicationId();
|
||||||
|
|
@ -97,6 +150,7 @@ async function setupMobile<ED extends EntityDict, Cxt extends BackendRuntimeCont
|
||||||
user: {
|
user: {
|
||||||
id: 1,
|
id: 1,
|
||||||
userState: 1,
|
userState: 1,
|
||||||
|
refId: 1,
|
||||||
wechatUser$user: {
|
wechatUser$user: {
|
||||||
$entity: 'wechatUser',
|
$entity: 'wechatUser',
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -141,7 +195,7 @@ async function setupMobile<ED extends EntityDict, Cxt extends BackendRuntimeCont
|
||||||
default: {
|
default: {
|
||||||
/* assert(userState === 'normal');
|
/* assert(userState === 'normal');
|
||||||
throw await makeDistinguishException<ED, Cxt>(userId as string, context, '该手机号已被一个有效用户占用,请联系管理员处理'); */
|
throw await makeDistinguishException<ED, Cxt>(userId as string, context, '该手机号已被一个有效用户占用,请联系管理员处理'); */
|
||||||
|
|
||||||
// 直接合并
|
// 直接合并
|
||||||
await mergeUser<ED, Cxt>({ from: userId!, to: currentToken.userId! }, context, true);
|
await mergeUser<ED, Cxt>({ from: userId!, to: currentToken.userId! }, context, true);
|
||||||
return currentToken.id!;
|
return currentToken.id!;
|
||||||
|
|
@ -161,29 +215,9 @@ async function setupMobile<ED extends EntityDict, Cxt extends BackendRuntimeCont
|
||||||
};
|
};
|
||||||
const { user } = mobileRow;
|
const { user } = mobileRow;
|
||||||
const { userState } = user!;
|
const { userState } = user!;
|
||||||
switch (userState) {
|
|
||||||
case 'disabled': {
|
|
||||||
throw new OakUserDisabledException();
|
|
||||||
}
|
|
||||||
case 'shadow': {
|
|
||||||
Object.assign(tokenData, {
|
|
||||||
userId: mobileRow.userId,
|
|
||||||
user: {
|
|
||||||
id: await generateNewIdAsync(),
|
|
||||||
action: 'activate',
|
|
||||||
data: {},
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
assert(userState === 'normal');
|
|
||||||
Object.assign(tokenData, {
|
|
||||||
userId: mobileRow.userId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 可能出现多次merge的情况
|
||||||
|
Object.assign(tokenData, await dealWithUserState(user as Partial<EntityDict['user']['Schema']>, context as BackendRuntimeContext<EntityDict>, tokenData));
|
||||||
await context.operate('token', {
|
await context.operate('token', {
|
||||||
id: await generateNewIdAsync(),
|
id: await generateNewIdAsync(),
|
||||||
data: tokenData,
|
data: tokenData,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue