const loginLog = async (res = {}) => {
if (res.code != 0) {
return false
}
const now = Date.now()
const uniIdLogCollection = db.collection('uni-id-log')
let logData = {
deviceId: params.deviceId || ctx.context.DEVICEID,
ip: params.ip || ctx.context.CLIENTIP,
type: res.type,
ua: ctx.context.CLIENTUA,
create_date: now
};
Object.assign(logData,
res.code === 0 ? {
user_id: res.uid,
state: 1
} : {
state: 0
})
return await uniIdLogCollection.add(logData)
}
let res;
switch (loginType) {
case 'loginByUniverify':
res = await ctx.uniID.loginByUniverify(params);
await loginLog(res);
break;
case 'loginByApple':
res = await ctx.uniID.loginByApple(params);
await loginLog(res);
break;
case 'loginByWeixin':
res = await ctx.uniID.loginByWeixin(params);
if (res.type == 'register') {
let newusername = "微信用户" + randomString("1", 6)
await ctx.uniID.updateUser({
uid: res.uid,
username: newusername
});
res.userInfo.username = newusername
}
await loginLog(res);
break;
}
console.log("=======登录-res: ==========", res);
if (res.code != 0) {
return res
}
Jack6 (作者)
发在评论了,麻烦看看呢
2022-01-04 11:32