后台:修改白名单

This commit is contained in:
luying
2021-12-08 17:35:23 +08:00
parent fc38485f94
commit 46108f90f2
14 changed files with 56 additions and 43 deletions
+16 -8
View File
@@ -1,22 +1,30 @@
import BaseModel from './BaseModel';
import { prop, DocumentType, getModelForClass } from '@typegoose/typegoose';
import { WHITE_LIST_TYPE } from '../consts';
export default class WhiteList extends BaseModel {
@prop({ required: true, enum: WHITE_LIST_TYPE })
type: WHITE_LIST_TYPE; // 区号
@prop({ required: true })
regionId: number; // 大区区号
@prop({ required: true })
str: string; // ip或手机号
env: string; // 环境变量
public static async checkIp(ip: string) {
const rec: WhiteListModelType = await WhiteListModel.findOne({ type: WHITE_LIST_TYPE.IP, str: ip }).lean();
@prop({ required: true })
ip: string; // ip
@prop({ required: true })
serverId: number; // 小区id
@prop({ required: true })
uid: number; // 玩家uid
public static async checkIp(env: string, ip: string) {
const rec = await WhiteListModel.exists({ env, ip });
return rec;
}
public static async checkTel(tel: string) {
const rec: WhiteListModelType = await WhiteListModel.findOne({ type: WHITE_LIST_TYPE.TEL, str: tel }).lean();
public static async checkUid(env: string, serverId: number, uid: number) {
const rec = await WhiteListModel.exists({ env, serverId, uid });
return rec;
}
}
-1
View File
@@ -3,7 +3,6 @@ import { isArray } from 'underscore';
import GMMail from "../../db/GMMail";
import ServerStategy from "../../db/ServerStategy";
import { RegionType } from "../../db/Region";
import { nowSeconds } from "../../pubUtils/timeUtil";
export class UpdateMailParams {
hasGoods: boolean = false; // 是否有道具
+5 -13
View File
@@ -11,7 +11,6 @@ import { findIndex } from 'underscore';
import { getTimeFunM } from './timeUtil';
import { Floor } from '../domain/activityField/gachaField';
import { WhiteListModel } from '../db/WhiteList';
import { UserModel } from '../db/User';
const randomName = require("chinese-random-name");
const moment = require('moment');
const crypto = require('crypto');
@@ -659,20 +658,13 @@ export function getFloorStatus(gachaId: number, floor: Floor[]) {
});
}
export async function checkWhiteListWithUid(uid: number) {
let user = await UserModel.findUserByUid(uid);
if(!user) return false;
let { tel, ip } = user;
return await checkWhiteList(tel, ip);
}
export async function checkWhiteList(tel: string, ip: string) {
if(tel) {
let result = await WhiteListModel.checkTel(tel);
export async function checkWhiteList(env: string, ip: string, uid: number, serverId: number) {
if(ip) {
let result = await WhiteListModel.checkIp(env, ip);
if(!!result) return true;
}
if(ip) {
let result = await WhiteListModel.checkIp(ip);
if(uid && serverId) {
let result = await WhiteListModel.checkUid(env, serverId, uid);
if(!!result) return true;
}
return false