add: 添加获取用户信息接口

This commit is contained in:
SunnyQjm committed 2019-10-30 19:38:38 +08:00
1 parent 2caed93d46
commit 005a91131e
4 files changed
+12 -4

No files matched your search

+7 -1
View File
@@ -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 -1
View File
@@ -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')
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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,