登录:fix 浏览器同设备号不继承游客时间

This commit is contained in:
luying
2021-03-08 16:45:23 +08:00
parent a846258a6a
commit 9773b8d69e
4 changed files with 37 additions and 9 deletions
+2 -2
View File
@@ -10,8 +10,8 @@ export default class AccountController extends Controller {
public async getSms() {
const { ctx } = this;
const { tel } = ctx.request.body;
ctx.body = await ctx.service.auth.getSms(tel);
const { type, tel } = ctx.request.body;
ctx.body = await ctx.service.auth.getSms(type, tel);
}
public async smsLogin() {
+23 -6
View File
@@ -3,7 +3,7 @@ import { DEFAULT_HEROES } from '@consts';
import { HeroModel } from '@db/Hero';
import { RoleModel } from '@db/Role';
import { UserModel, UserType } from '@db/User';
import { STATUS } from '@consts';
import { STATUS, GET_SMS_TYPE, DEFAULT_DEVICE_ID } from '@consts';
import { smsModel } from '@db/Sms';
import { Service } from 'egg';
import Counter from '@db/Counter';
@@ -35,10 +35,18 @@ export default class Auth extends Service {
if(isGuest) {
const tel = ctx.service.utils.genCode(10);
const token = ctx.service.utils.generateStr(256);
let lastGuest = await UserModel.getLastDeviceGuest(deviceId);
let { guestTime, createdAt } = lastGuest;
if(shouldRefresh(createdAt, new Date(), 0, GUEST_DAY)) {
guestTime = 0;
let lastGuest = null;
let guestTime = 0;
if(deviceId != DEFAULT_DEVICE_ID.PC) {
lastGuest = await UserModel.getLastDeviceGuest(deviceId);
if(lastGuest) {
guestTime = lastGuest.guestTime;
let { createdAt } = lastGuest;
if(shouldRefresh(createdAt, new Date(), 0, GUEST_DAY)) {
guestTime = 0;
}
}
}
if(guestTime > GUEST_MAX_TIME) {
loginType = 3;
@@ -135,12 +143,21 @@ export default class Auth extends Service {
* @param telNo - 用户手机号
*/
public async getSms(tel: string) {
public async getSms(type: number, tel: string) {
const ctx = this.ctx;
const telVerify = this.checkTelNo(tel);
if (telVerify.status !== 0) {
return telVerify.resResult;
}
if(type == GET_SMS_TYPE.BIND) {
let telUser = await UserModel.findUserByTel(tel);
if(telUser && telUser.uid != ctx.uid) {
return ctx.service.utils.resResult(STATUS.TEL_HAS_USED);
}
}
const sms = await smsModel.findByTel(tel, false);
if (sms) {
if (await sms.timeLimit(10000)) {