diff --git a/src/modules/user/dtos/account.dto.ts b/src/modules/user/dtos/account.dto.ts index f43c730..518720a 100644 --- a/src/modules/user/dtos/account.dto.ts +++ b/src/modules/user/dtos/account.dto.ts @@ -1,15 +1,17 @@ import { PickType } from '@nestjs/swagger'; -import { Length } from 'class-validator'; +import { IsDefined, IsUUID, Length } from 'class-validator'; import { IsPassword } from '@/modules/core/constraints/password.constraint'; import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator'; import { UserCommonDto } from '@/modules/user/dtos/user.common.dto'; +import { UserValidateGroup } from '../constants'; + /** * 更新用户信息 */ -@DtoValidation({ whitelist: false, groups: [UserValidateGroup.ACCOUNT_UPDATE] }) +@DtoValidation({ groups: [UserValidateGroup.ACCOUNT_UPDATE] }) export class UpdateAccountDto extends PickType(UserCommonDto, ['username', 'nickname']) { /** * 待更新的用户ID diff --git a/src/modules/user/dtos/user.common.dto.ts b/src/modules/user/dtos/user.common.dto.ts index 51c94a9..cea08ac 100644 --- a/src/modules/user/dtos/user.common.dto.ts +++ b/src/modules/user/dtos/user.common.dto.ts @@ -61,7 +61,7 @@ export class UserCommonDto { ) @IsMatchPhone( undefined, - { strictMode: trus }, + { strictMode: true }, { message: '手机格式错误,示例: +86.15005255555', always: true }, ) @IsOptional({ diff --git a/src/modules/user/dtos/user.dto.ts b/src/modules/user/dtos/user.dto.ts index b23a3d0..09f5ae8 100644 --- a/src/modules/user/dtos/user.dto.ts +++ b/src/modules/user/dtos/user.dto.ts @@ -4,7 +4,7 @@ import { IsDefined, IsEnum, IsUUID } from 'class-validator'; import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator'; import { PaginateWithTrashedDto } from '@/modules/restful/dtos/paginate-width-trashed.dto'; -import { UserOrderType } from '@/modules/user/constants'; +import { UserOrderType, UserValidateGroup } from '@/modules/user/constants'; import { UserCommonDto } from '@/modules/user/dtos/user.common.dto'; /** diff --git a/src/modules/user/services/token.service.ts b/src/modules/user/services/token.service.ts index ab09da3..0a06cd0 100644 --- a/src/modules/user/services/token.service.ts +++ b/src/modules/user/services/token.service.ts @@ -1,8 +1,12 @@ +/* eslint-disable import/no-extraneous-dependencies */ import { Injectable } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import dayjs from 'dayjs'; +import { FastifyReply as Response } from 'fastify'; +import jwt from 'jsonwebtoken'; +import { v4 as uuid } from 'uuid'; import { Configure } from '@/modules/config/configure'; import { getTime } from '@/modules/core/helpers/time'; @@ -11,7 +15,6 @@ import { UserEntity } from '@/modules/user/entities/UserEntity'; import { AccessTokenEntity } from '@/modules/user/entities/access.token.entity'; import { RefreshTokenEntity } from '@/modules/user/entities/refresh.token.entity'; import { JwtConfig, JwtPayload } from '@/modules/user/types'; - /** * 令牌服务 */ @@ -79,7 +82,7 @@ export class TokenService { const config = await getUserConfig(this.configure, 'jwt'); const refreshTokenPayload = { uuid: uuid() }; const refreshToken = new RefreshTokenEntity(); - refreshToken.value = this.jwtService.sign( + refreshToken.value = jwt.sign( refreshTokenPayload, this.configure.env.get('USER_REFRESH_TOKEN_EXPIRED', 'my-refresh-secret'), ); @@ -130,7 +133,7 @@ export class TokenService { * @param token */ async verifyAccessToken(token: AccessTokenEntity) { - const result = this.jwtService.verify( + const result = jwt.verify( token.value, this.configure.env.get('USER_TOKEN_SECRET', 'my-access-secret'), );