登录: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

View File

@@ -8,7 +8,7 @@ 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_MAX_TIME = 60 * 60; // 游客体验时间
export const GUEST_DAY = 15; // 同一设备15天内不得重复体验游客模式
export const COUNTER = {
@@ -409,4 +409,13 @@ export enum ADDICTION_PREVENTION_CODE {
CURFEW = 2, // 每日22时至次日8时,未成年禁止游戏
HOLIDAY = 3, // 法定节假日每日累计不得超过3小时
WORKDAY = 4, // 非法定节假日每日累计不得超过1.5小时
}
export enum GET_SMS_TYPE {
LOGIN = 1,
BIND = 2
}
export enum DEFAULT_DEVICE_ID {
PC = 'pc'
}

View File

@@ -162,6 +162,7 @@ export class Attribute {
public calCe() {
let { hp, atk, def, mdef } = this.getRealMainAttr();
let { cri, flee, damageIncrease, damageDecrease, damageCri } = this.getRealSubAttr();
let putHit = CE_CONST.PUT_HIT / HERO_SUB_ATTR_RATIO;
let putAntCri = CE_CONST.PUT_ANT_CRI / HERO_SUB_ATTR_RATIO;
@@ -179,6 +180,7 @@ export class Attribute {
let validHp = hp + (def + mdef) * 0.5 / ((1 - fleeRate * CE_CONST.FLEE_VALUE) * (1 - damageDecrease)); // 有效生命
let validAtk = atk * hitRate * ( 1 + criRate * criValue) * ( 1 + damageIncrease); // 有效输出
let ce = Math.floor(validHp * validAtk * HERO_CE_RATIO * HERO_CE_RATIO);
return ce > 0? ce: 1;
}

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() {

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)) {