add user and jwt module
This commit is contained in:
parent
46253b3a4f
commit
6fa6e1f076
@ -1,15 +1,17 @@
|
|||||||
import { PickType } from '@nestjs/swagger';
|
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 { IsPassword } from '@/modules/core/constraints/password.constraint';
|
||||||
import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator';
|
import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator';
|
||||||
import { UserCommonDto } from '@/modules/user/dtos/user.common.dto';
|
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']) {
|
export class UpdateAccountDto extends PickType(UserCommonDto, ['username', 'nickname']) {
|
||||||
/**
|
/**
|
||||||
* 待更新的用户ID
|
* 待更新的用户ID
|
||||||
|
@ -61,7 +61,7 @@ export class UserCommonDto {
|
|||||||
)
|
)
|
||||||
@IsMatchPhone(
|
@IsMatchPhone(
|
||||||
undefined,
|
undefined,
|
||||||
{ strictMode: trus },
|
{ strictMode: true },
|
||||||
{ message: '手机格式错误,示例: +86.15005255555', always: true },
|
{ message: '手机格式错误,示例: +86.15005255555', always: true },
|
||||||
)
|
)
|
||||||
@IsOptional({
|
@IsOptional({
|
||||||
|
@ -4,7 +4,7 @@ import { IsDefined, IsEnum, IsUUID } from 'class-validator';
|
|||||||
|
|
||||||
import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator';
|
import { DtoValidation } from '@/modules/core/decorator/dto.validation.decorator';
|
||||||
import { PaginateWithTrashedDto } from '@/modules/restful/dtos/paginate-width-trashed.dto';
|
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';
|
import { UserCommonDto } from '@/modules/user/dtos/user.common.dto';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
|
|
||||||
import dayjs from 'dayjs';
|
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 { Configure } from '@/modules/config/configure';
|
||||||
import { getTime } from '@/modules/core/helpers/time';
|
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 { AccessTokenEntity } from '@/modules/user/entities/access.token.entity';
|
||||||
import { RefreshTokenEntity } from '@/modules/user/entities/refresh.token.entity';
|
import { RefreshTokenEntity } from '@/modules/user/entities/refresh.token.entity';
|
||||||
import { JwtConfig, JwtPayload } from '@/modules/user/types';
|
import { JwtConfig, JwtPayload } from '@/modules/user/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 令牌服务
|
* 令牌服务
|
||||||
*/
|
*/
|
||||||
@ -79,7 +82,7 @@ export class TokenService {
|
|||||||
const config = await getUserConfig<JwtConfig>(this.configure, 'jwt');
|
const config = await getUserConfig<JwtConfig>(this.configure, 'jwt');
|
||||||
const refreshTokenPayload = { uuid: uuid() };
|
const refreshTokenPayload = { uuid: uuid() };
|
||||||
const refreshToken = new RefreshTokenEntity();
|
const refreshToken = new RefreshTokenEntity();
|
||||||
refreshToken.value = this.jwtService.sign(
|
refreshToken.value = jwt.sign(
|
||||||
refreshTokenPayload,
|
refreshTokenPayload,
|
||||||
this.configure.env.get('USER_REFRESH_TOKEN_EXPIRED', 'my-refresh-secret'),
|
this.configure.env.get('USER_REFRESH_TOKEN_EXPIRED', 'my-refresh-secret'),
|
||||||
);
|
);
|
||||||
@ -130,7 +133,7 @@ export class TokenService {
|
|||||||
* @param token
|
* @param token
|
||||||
*/
|
*/
|
||||||
async verifyAccessToken(token: AccessTokenEntity) {
|
async verifyAccessToken(token: AccessTokenEntity) {
|
||||||
const result = this.jwtService.verify(
|
const result = jwt.verify(
|
||||||
token.value,
|
token.value,
|
||||||
this.configure.env.get('USER_TOKEN_SECRET', 'my-access-secret'),
|
this.configure.env.get('USER_TOKEN_SECRET', 'my-access-secret'),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user