ec-nest/src/users/dto.ts
liuyun 606585c3bd feat(security): 登录失败锁定 + 密码长度策略 + refresh token 哈希校验
- 登录连续失败 5 次锁定 15 分钟(Redis 计数)
- 密码字段 @MinLength(6)
- refresh 校验 tokenHash

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-11 16:46:13 +08:00

112 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsArray, IsIn, IsNotEmpty, IsOptional, IsString, MinLength } from 'class-validator';
import { PageQuery } from '../common/page.dto.js';
import { UserStatus } from '../common/enums.js';
export class CreateUserDto {
@ApiProperty({ description: '用户名' })
@IsString()
@IsNotEmpty()
username!: string;
@ApiProperty({ description: '初始密码' })
@IsString()
@IsNotEmpty()
@MinLength(6, { message: '密码长度不能少于 6 位' })
password!: string;
@ApiPropertyOptional({ description: '昵称' })
@IsOptional()
@IsString()
nickname?: string;
@ApiPropertyOptional({ description: '邮箱' })
@IsOptional()
@IsString()
email?: string;
@ApiPropertyOptional({ description: '手机号' })
@IsOptional()
@IsString()
phone?: string;
@ApiPropertyOptional({ description: '头像' })
@IsOptional()
@IsString()
avatar?: string;
@ApiPropertyOptional({ description: '所属部门 code' })
@IsOptional()
@IsString()
orgCode?: string;
}
export class UpdateUserDto {
@ApiPropertyOptional({ description: '昵称' })
@IsOptional()
@IsString()
nickname?: string;
@ApiPropertyOptional({ description: '邮箱' })
@IsOptional()
@IsString()
email?: string;
@ApiPropertyOptional({ description: '手机号' })
@IsOptional()
@IsString()
phone?: string;
@ApiPropertyOptional({ description: '头像' })
@IsOptional()
@IsString()
avatar?: string;
@ApiPropertyOptional({ description: '所属部门 code' })
@IsOptional()
@IsString()
orgCode?: string;
@ApiPropertyOptional({ description: '状态:enabled/disabled/locked' })
@IsOptional()
@IsIn(Object.values(UserStatus))
status?: string;
}
export class ResetPasswordDto {
@ApiProperty({ description: '新密码' })
@IsString()
@IsNotEmpty()
@MinLength(6, { message: '密码长度不能少于 6 位' })
password!: string;
}
export class AssignRolesDto {
@ApiProperty({ description: '角色 code 列表', type: [String] })
@IsArray()
@IsString({ each: true })
roleCodes!: string[];
}
export class ListUserQuery extends PageQuery {
@ApiPropertyOptional({ description: '用户名(模糊)' })
@IsOptional()
@IsString()
username?: string;
@ApiPropertyOptional({ description: '昵称(模糊)' })
@IsOptional()
@IsString()
nickname?: string;
@ApiPropertyOptional({ description: '手机号(模糊)' })
@IsOptional()
@IsString()
phone?: string;
@ApiPropertyOptional({ description: '状态:enabled/disabled/locked' })
@IsOptional()
@IsIn(Object.values(UserStatus))
status?: string;
}