登录:同一设备不可重复使用游客模式
This commit is contained in:
@@ -8,6 +8,8 @@ export const ENCRYPT_KEY = 'fiqaxijabbantusmprc234fj';
|
||||
export const AUTH_SMS_CNT_PER_DAY = 8;
|
||||
|
||||
export const ADULT_AGE = 18;
|
||||
export const GUEST_MAX_TIME = 60 * 60 * 100; // 游客体验时间
|
||||
export const GUEST_DAY = 15; // 同一设备15天内不得重复体验游客模式
|
||||
|
||||
export const COUNTER = {
|
||||
UID: { name: 'uid', def: 1 },
|
||||
|
||||
@@ -98,19 +98,23 @@ export default class User extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
auth: number;
|
||||
|
||||
public static async createUser(isGuest: boolean, tel: string, token: string, platform: string, pkgName: string, serverType: string, deviceId: string, lean = true) {
|
||||
public static async createUser(isGuest: boolean, tel: string, token: string, platform: string, pkgName: string, serverType: string, deviceId: string, guestTime?: number) {
|
||||
const curTime: Date = new Date();
|
||||
|
||||
const uid = await CounterModel.getNewCounter(COUNTER.UID);
|
||||
const userCode = genCode(8);
|
||||
const doc = new UserModel();
|
||||
let update = {};
|
||||
update = Object.assign(update, doc.toJSON(), { platform, pkgName, serverType, createTime: curTime, uid, userCode, username: `用户${uid}`, isGuest });
|
||||
update = Object.assign(update, doc.toJSON(), { platform, pkgName, serverType, createTime: curTime, uid, userCode, username: `用户${uid}`, isGuest, token, lastLoginTime: curTime, guestTime });
|
||||
if(isGuest) update["guestId"] = tel;
|
||||
update = Object.assign(update, { token, lastLoginTime: curTime });
|
||||
delete update["device"];
|
||||
|
||||
const user = await UserModel.findOneAndUpdate({ tel }, { $set: update, $addToSet: {device: deviceId}}, { upsert: true, new: true }).lean(lean);
|
||||
const user: UserType = await UserModel.findOneAndUpdate({ tel }, { $set: update, $addToSet: {device: deviceId}}, { upsert: true, new: true }).lean();
|
||||
return user;
|
||||
}
|
||||
|
||||
public static async getLastDeviceGuest(deviceId: string) {
|
||||
const user: UserType = await UserModel.findOne({ device: { $elemMatch: { $eq: deviceId } }, isGuest: true }).sort({createTime: -1}).lean();
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user