网安:修改手机存储

This commit is contained in:
luying
2021-04-09 10:43:53 +08:00
parent ad2b62d426
commit a02ee04a5b
11 changed files with 4504 additions and 213 deletions
+17 -10
View File
@@ -1,6 +1,8 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { generateNum } from '../pubUtils/util';
import { generateNum, aesEncryptcfb, aesDecryptcfb } from '../pubUtils/util';
import { ENCRYPT_KEY, ENCRYPT_IV } from './../consts';
const moment = require('moment');
/**
@@ -9,7 +11,7 @@ const moment = require('moment');
@index({ tel: 1 })
export default class Sms extends BaseModel {
@prop({ required: true })
@prop({ required: true, set: (val: string) => aesEncryptcfb(val, ENCRYPT_KEY, ENCRYPT_IV), get: (val: string) => aesDecryptcfb(val, ENCRYPT_KEY, ENCRYPT_IV) })
tel: string;
@prop({ required: true })
@@ -31,17 +33,20 @@ export default class Sms extends BaseModel {
isFixed: boolean;
public static async findByTel(tel: string, lean = true) {
const sms: SmsType = await smsModel.findOne({ tel }).lean(lean);
let _tel = aesEncryptcfb(tel, ENCRYPT_KEY, ENCRYPT_IV);
const sms: SmsType = await smsModel.findOne({ tel: _tel }).lean(lean);
return sms;
}
public static async updateByTel(tel: string, code: string, used: boolean, updateTime: Date, countToday: number, lean = true) {
const sms: SmsType = await smsModel.findOneAndUpdate({ tel }, { code, used, updateTime, countToday }, { upsert: true }).lean(lean);
public static async updateByTel(tel: string, code: string, used: boolean, updateTime: Date, countToday: number) {
const sms: SmsType = await smsModel.findOneAndUpdate({ tel }, { tel, code, used, updateTime, countToday }, { upsert: true }).lean({ getters: true });
return sms;
}
public static async validateSms(tel: string, code: string, lean = true) {
const record: SmsType = await smsModel.findOneAndUpdate({ tel, code, used: false }, { used: true }).lean(lean);
public static async validateSms(tel: string, code: string) {
const record: SmsType = await smsModel.findOneAndUpdate({ tel, code, used: false }, { used: true }).lean({ getters: true });
return !!record;
}
@@ -66,14 +71,16 @@ export default class Sms extends BaseModel {
return moment(this.updateTime).format('YYYY-MM-DD') === moment(Date.now()).format('YYYY-MM-DD');
}
public static async fixSms(tel: string, lean = true) {
const sms: SmsType = await smsModel.findOneAndUpdate({ tel }, { $setOnInsert: {
public static async fixSms(tel: string) {
let _tel = aesEncryptcfb(tel, ENCRYPT_KEY, ENCRYPT_IV);
const sms: SmsType = await smsModel.findOneAndUpdate({ tel: _tel }, { $setOnInsert: {
tel,
code: generateNum(6),
used: false,
updateTime: new Date(),
countToday: 1
}, $set: { isFixed: true } }, {new: true, upsert: true}).lean(lean);
}, $set: { isFixed: true } }, {new: true, upsert: true}).lean({ getters: true });
return sms;
}
}