Browse Source

token解析

zs 2 năm trước cách đây
mục cha
commit
c92cf62b28

+ 1 - 0
src/controller/system/role.controller.ts

@@ -43,6 +43,7 @@ import get = require('lodash/get');
 export class RoleController extends BaseController {
 export class RoleController extends BaseController {
   @Inject()
   @Inject()
   service: RoleService;
   service: RoleService;
+
   @Inject()
   @Inject()
   moduleService: ModuleService;
   moduleService: ModuleService;
 
 

+ 24 - 0
src/controller/token/token.controller.ts

@@ -0,0 +1,24 @@
+import { Controller, Get, Inject } from '@midwayjs/decorator';
+import { Context } from '@midwayjs/koa';
+import { ApiResponse, ApiTags } from '@midwayjs/swagger';
+const assert = require('assert');
+import { JwtService } from '@midwayjs/jwt';
+import get = require('lodash/get');
+@ApiTags(['解析token'])
+@Controller('/token')
+export class TokenController {
+  @Inject()
+  jwtService: JwtService;
+
+  @Inject()
+  ctx: Context;
+
+  @Get('/tokenView')
+  @ApiResponse({})
+  async tokenView() {
+    const token = get(this.ctx, 'request.header.token');
+    assert(token, '缺少token信息');
+    const result: any = await this.jwtService.decode(token);
+    return result;
+  }
+}

+ 3 - 0
src/controller/user/admin.controller.ts

@@ -48,13 +48,16 @@ export class AdminController extends BaseController {
 
 
   @Inject()
   @Inject()
   jwtService: JwtService;
   jwtService: JwtService;
+
   @Config('jwt.secret')
   @Config('jwt.secret')
   jwtSecret;
   jwtSecret;
+
   @Config('jwt.expiresIn')
   @Config('jwt.expiresIn')
   jwtExpiresIn;
   jwtExpiresIn;
 
 
   @Inject()
   @Inject()
   userUtil: UserUtilService;
   userUtil: UserUtilService;
+
   @Inject()
   @Inject()
   util: UtilService;
   util: UtilService;
 
 

+ 2 - 0
src/controller/user/company.controller.ts

@@ -44,8 +44,10 @@ export class CompanyController extends BaseController {
 
 
   @Inject()
   @Inject()
   jwtService: JwtService;
   jwtService: JwtService;
+
   @Config('jwt.secret')
   @Config('jwt.secret')
   jwtSecret;
   jwtSecret;
+
   @Config('jwt.expiresIn')
   @Config('jwt.expiresIn')
   jwtExpiresIn;
   jwtExpiresIn;
 
 

+ 2 - 0
src/controller/user/expert.controller.ts

@@ -49,8 +49,10 @@ export class ExpertController extends BaseController {
 
 
   @Inject()
   @Inject()
   jwtService: JwtService;
   jwtService: JwtService;
+
   @Config('jwt.secret')
   @Config('jwt.secret')
   jwtSecret;
   jwtSecret;
+
   @Config('jwt.expiresIn')
   @Config('jwt.expiresIn')
   jwtExpiresIn;
   jwtExpiresIn;
 
 

+ 2 - 0
src/controller/user/personal.controller.ts

@@ -48,8 +48,10 @@ export class PersonalController extends BaseController {
 
 
   @Inject()
   @Inject()
   jwtService: JwtService;
   jwtService: JwtService;
+
   @Config('jwt.secret')
   @Config('jwt.secret')
   jwtSecret;
   jwtSecret;
+
   @Config('jwt.expiresIn')
   @Config('jwt.expiresIn')
   jwtExpiresIn;
   jwtExpiresIn;
 
 

+ 14 - 9
src/interface/user/admin.interface.ts

@@ -124,7 +124,8 @@ export class UVAO_admin extends FVO_admin {
     dealVO(this, data);
     dealVO(this, data);
   }
   }
 }
 }
-export class FetchVO_admin {
+
+export class LoginVO {
   constructor(data: object) {
   constructor(data: object) {
     for (const key of Object.keys(this)) {
     for (const key of Object.keys(this)) {
       this[key] = get(data, key);
       this[key] = get(data, key);
@@ -132,22 +133,26 @@ export class FetchVO_admin {
   }
   }
   @ApiProperty({ description: '数据id' })
   @ApiProperty({ description: '数据id' })
   _id: string = undefined;
   _id: string = undefined;
+  @ApiProperty({ description: '所属上级' })
+  'pid': string = undefined;
+  @ApiProperty({ description: '用户类型' })
+  'type': string = undefined;
+  @ApiProperty({ description: '邀请码' })
+  'code': string = undefined;
   @ApiProperty({ description: '账号' })
   @ApiProperty({ description: '账号' })
   'account': string = undefined;
   'account': string = undefined;
+  @ApiProperty({ description: '密码' })
+  'password': string = undefined;
   @ApiProperty({ description: '名称' })
   @ApiProperty({ description: '名称' })
   'name': string = undefined;
   'name': string = undefined;
+  @ApiProperty({ description: '手机号' })
+  'phone': string = undefined;
+  @ApiProperty({ description: '机构名称' })
+  'dept_name': string = undefined;
   @ApiProperty({ description: '角色' })
   @ApiProperty({ description: '角色' })
   'role': Array<any> = undefined;
   'role': Array<any> = undefined;
 }
 }
 
 
-export class LoginVO extends FetchVO_admin {
-  constructor(data: object) {
-    super(data);
-  }
-  @ApiProperty({ description: '用户类型' })
-  'type': string = undefined;
-}
-
 export class LoginDTO {
 export class LoginDTO {
   @ApiProperty({ description: '账号', example: 'test' })
   @ApiProperty({ description: '账号', example: 'test' })
   @Rule(RuleType['string']().empty(''))
   @Rule(RuleType['string']().empty(''))