实现修改密码,但引入了修改密码后无法点击窗口的bug
This commit is contained in:
10
tone-page-server/src/user/dto/update-user-password.dto.ts
Normal file
10
tone-page-server/src/user/dto/update-user-password.dto.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { IsString, Length, Matches } from "class-validator";
|
||||
|
||||
export class UpdateUserPasswordDto {
|
||||
@IsString({ message: '密码不得为空' })
|
||||
@Length(6, 32, { message: '密码长度只能为6~32' })
|
||||
@Matches(/^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};:'",.<>/?]{6,32}$/,
|
||||
{ message: '密码必须包含字母和数字,且长度在6~32之间' }
|
||||
)
|
||||
password: string;
|
||||
}
|
||||
@@ -1,21 +1,30 @@
|
||||
import { Controller, Get, Injectable, Request, UnauthorizedException, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Put, Request, UseGuards } from '@nestjs/common';
|
||||
import { UserService } from './user.service';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { UpdateUserPasswordDto } from './dto/update-user-password.dto';
|
||||
import { AuthService } from 'src/auth/auth.service';
|
||||
|
||||
@Controller('user')
|
||||
export class UserController {
|
||||
|
||||
constructor(
|
||||
private readonly userService: UserService
|
||||
private readonly userService: UserService,
|
||||
private readonly authService: AuthService,
|
||||
) { }
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Get('me')
|
||||
async getMe(@Request() req) {
|
||||
const { user } = req;
|
||||
if (!user || !user.userId) {
|
||||
throw new UnauthorizedException('Unauthorized');
|
||||
}
|
||||
return this.userService.findOne({ userId: user.userId });
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@Put('password')
|
||||
async update(
|
||||
@Request() req,
|
||||
@Body() dto: UpdateUserPasswordDto,
|
||||
) {
|
||||
return this.userService.setPassword(req.user.userId, dto.password);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user