mirror of
https://github.com/SunnyQjm/sunny-blog-server.git
synced 2026-10-04 19:52:21 +08:00
add: 添加获取用户信息接口
This commit is contained in:
1 parent
2caed93d46
commit
005a91131e
4 files changed
+12
-4
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { CreatePostDto } from './dto/create-post.dto';
|
||||
import { Post as PostModel } from '../entity/post.entity';
|
||||
@@ -19,6 +19,12 @@ export class AdminController {
|
||||
|
||||
}
|
||||
|
||||
@Get('getUserInfo')
|
||||
async getUserInfo(@Req() req) {
|
||||
const user = await this.userService.findOne(req.user.username);
|
||||
return ResponseUtil.success(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建标签
|
||||
* @param createTagDto
|
||||
|
||||
@@ -3,6 +3,7 @@ import { AppService } from './app.service';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { AuthService } from './auth/auth.service';
|
||||
import { CreateUserDto } from './auth/dto/create-user.dto';
|
||||
import { ResponseUtil } from './model/response-util';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
@@ -15,7 +16,8 @@ export class AppController {
|
||||
@UseGuards(AuthGuard('local'))
|
||||
@Post('login')
|
||||
async login(@Req() req) {
|
||||
return this.authService.login(req.user);
|
||||
const data = await this.authService.login(req.user);
|
||||
return ResponseUtil.success(data);
|
||||
}
|
||||
|
||||
@Post('register')
|
||||
|
||||
@@ -20,7 +20,7 @@ export class LocalStrategy extends PassportStrategy(Strategy) {
|
||||
// 验证用户名和密码是否有效,有效则local验证通过
|
||||
const user = await this.authService.validateUser(username, password);
|
||||
if (!user) {
|
||||
throw new UnauthorizedException('验证未通过');
|
||||
throw new UnauthorizedException('用户名或密码错误');
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
||||
const request = ctx.getRequest<Request>();
|
||||
const status = exception.getStatus();
|
||||
// @ts-ignore
|
||||
response.status(status)
|
||||
response.status(200)
|
||||
.json({
|
||||
...exception.message,
|
||||
path: request.url,
|
||||
|
||||
Reference in new issue
Block a user