feat: remove emit cmd
This commit is contained in:
parent
90b9a17fd0
commit
f942bd1355
3
.vscode/tasks.json
vendored
3
.vscode/tasks.json
vendored
|
@ -16,7 +16,8 @@
|
||||||
"dmp-gateway",
|
"dmp-gateway",
|
||||||
"aorta-gateway",
|
"aorta-gateway",
|
||||||
"cert-gateway"
|
"cert-gateway"
|
||||||
]
|
],
|
||||||
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "build:pkg",
|
"label": "build:pkg",
|
||||||
|
|
|
@ -23,27 +23,24 @@ export class AuthController {
|
||||||
const { username, password, phoneNumber } = userLoginDto;
|
const { username, password, phoneNumber } = userLoginDto;
|
||||||
// TODO: isEnabled、phoneNumber,用于后续验证
|
// TODO: isEnabled、phoneNumber,用于后续验证
|
||||||
const { isLegal, data, msg } = await firstValueFrom(
|
const { isLegal, data, msg } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.user.account' }, { username, password }),
|
this.client.send('cert.user.account', { username, password }),
|
||||||
);
|
);
|
||||||
await firstValueFrom(
|
await firstValueFrom(
|
||||||
this.client.send(
|
this.client.send('logger.user.signIn', {
|
||||||
{ cmd: 'logger.user.signIn' },
|
|
||||||
{
|
|
||||||
platform: 'dmp',
|
platform: 'dmp',
|
||||||
username,
|
username,
|
||||||
finger: request.headers['x-finger'] as string,
|
finger: request.headers['x-finger'] as string,
|
||||||
finger2: request.headers['x-finger2'] as string,
|
finger2: request.headers['x-finger2'] as string,
|
||||||
isLegal,
|
isLegal,
|
||||||
},
|
}),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
if (isLegal) {
|
if (isLegal) {
|
||||||
// 签发token
|
// 签发token
|
||||||
const { token } = await firstValueFrom(
|
const { token } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.create' }, { username }),
|
this.client.send('cert.token.create', { username }),
|
||||||
);
|
);
|
||||||
const { tokenKeyInCookie, expires } = await firstValueFrom(
|
const { tokenKeyInCookie, expires } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.config' }, []),
|
this.client.send('cert.token.config', []),
|
||||||
);
|
);
|
||||||
res.cookie(tokenKeyInCookie, token, {
|
res.cookie(tokenKeyInCookie, token, {
|
||||||
maxAge: expires * 1000,
|
maxAge: expires * 1000,
|
||||||
|
|
|
@ -29,14 +29,14 @@ export class AuthGuard implements CanActivate {
|
||||||
|
|
||||||
// 获取token的配置
|
// 获取token的配置
|
||||||
const { tokenKeyInCookie, tokenResignIn, expires } = await firstValueFrom(
|
const { tokenKeyInCookie, tokenResignIn, expires } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.config' }, []),
|
this.client.send('cert.token.config', []),
|
||||||
);
|
);
|
||||||
const tokenCipher = request.cookies[tokenKeyInCookie];
|
const tokenCipher = request.cookies[tokenKeyInCookie];
|
||||||
if (!tokenCipher) throw new ForbiddenException('您没有执行此操作的权限');
|
if (!tokenCipher) throw new ForbiddenException('您没有执行此操作的权限');
|
||||||
|
|
||||||
// 1.验证token是否合法
|
// 1.验证token是否合法
|
||||||
const { tokenValid, payload } = await firstValueFrom(
|
const { tokenValid, payload } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.decode' }, tokenCipher),
|
this.client.send('cert.token.decode', tokenCipher),
|
||||||
);
|
);
|
||||||
if (!tokenValid) throw new ForbiddenException('您没有执行此操作的权限');
|
if (!tokenValid) throw new ForbiddenException('您没有执行此操作的权限');
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ export class AuthGuard implements CanActivate {
|
||||||
if (tokenExpiredSoon) {
|
if (tokenExpiredSoon) {
|
||||||
const { username } = payload;
|
const { username } = payload;
|
||||||
const { token: newToken } = await firstValueFrom(
|
const { token: newToken } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.create' }, { username }),
|
this.client.send('cert.token.create', { username }),
|
||||||
);
|
);
|
||||||
request.res.cookie(tokenKeyInCookie, newToken, {
|
request.res.cookie(tokenKeyInCookie, newToken, {
|
||||||
maxAge: expires * 1000,
|
maxAge: expires * 1000,
|
||||||
|
@ -65,10 +65,10 @@ export class AuthGuard implements CanActivate {
|
||||||
*/
|
*/
|
||||||
async rolePermissionAllow(payload: { username: string }, requestUrl: string) {
|
async rolePermissionAllow(payload: { username: string }, requestUrl: string) {
|
||||||
const { allow } = await firstValueFrom(
|
const { allow } = await firstValueFrom(
|
||||||
this.client.send(
|
this.client.send('cert.role.authorize', {
|
||||||
{ cmd: 'cert.role.authorize' },
|
user: payload,
|
||||||
{ user: payload, url: requestUrl },
|
url: requestUrl,
|
||||||
),
|
}),
|
||||||
);
|
);
|
||||||
return { allow };
|
return { allow };
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { MinioOSS } from '@tavi/oss';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AppController {
|
export class AppController {
|
||||||
@EventPattern({ cmd: 'report-upload-image' })
|
@EventPattern('report-upload-image')
|
||||||
async uploadImageHandler({ buffer, originalName }) {
|
async uploadImageHandler({ buffer, originalName }) {
|
||||||
const objectName = Date.now() + '.' + getFileExt(originalName);
|
const objectName = Date.now() + '.' + getFileExt(originalName);
|
||||||
const { bucketName, ...config } = clientConfig;
|
const { bucketName, ...config } = clientConfig;
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class AppController {
|
||||||
* 给业务系统登录接口进行token签发,注入用户的角色信息
|
* 给业务系统登录接口进行token签发,注入用户的角色信息
|
||||||
* @description redis的EX、cookie的maxAge(ms)、jwt的expiresIn,三者保持一致
|
* @description redis的EX、cookie的maxAge(ms)、jwt的expiresIn,三者保持一致
|
||||||
*/
|
*/
|
||||||
@EventPattern({ cmd: 'cert.token.create' })
|
@EventPattern('cert.token.create')
|
||||||
async createToken(payload) {
|
async createToken(payload) {
|
||||||
const { username } = payload;
|
const { username } = payload;
|
||||||
const token = await this.jwtService.sign(payload);
|
const token = await this.jwtService.sign(payload);
|
||||||
|
@ -28,7 +28,7 @@ export class AppController {
|
||||||
* 检查token有效性 && 解token
|
* 检查token有效性 && 解token
|
||||||
* @description 业务系统的guard对请求token进行拦截,校验每次请求token是否合法&是否在redis中
|
* @description 业务系统的guard对请求token进行拦截,校验每次请求token是否合法&是否在redis中
|
||||||
*/
|
*/
|
||||||
@EventPattern({ cmd: 'cert.token.decode' })
|
@EventPattern('cert.token.decode')
|
||||||
async decodeToken(
|
async decodeToken(
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<{ tokenValid: boolean; payload: unknown; error?: unknown }> {
|
): Promise<{ tokenValid: boolean; payload: unknown; error?: unknown }> {
|
||||||
|
@ -47,7 +47,7 @@ export class AppController {
|
||||||
* 获取token在cookie中存储的key
|
* 获取token在cookie中存储的key
|
||||||
* @description cookie的maxAge单位是毫秒,如果给cookie使用expires需要 x1000
|
* @description cookie的maxAge单位是毫秒,如果给cookie使用expires需要 x1000
|
||||||
*/
|
*/
|
||||||
@EventPattern({ cmd: 'cert.token.config' })
|
@EventPattern('cert.token.config')
|
||||||
async tokenConfig() {
|
async tokenConfig() {
|
||||||
return {
|
return {
|
||||||
tokenResignIn: this.configService.get('TOKEN_RESIGN_IN'),
|
tokenResignIn: this.configService.get('TOKEN_RESIGN_IN'),
|
||||||
|
@ -56,7 +56,7 @@ export class AppController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.token.deprecated' })
|
@EventPattern('cert.token.deprecated')
|
||||||
async removeToken(payload) {
|
async removeToken(payload) {
|
||||||
const { username } = payload;
|
const { username } = payload;
|
||||||
console.log('username', username);
|
console.log('username', username);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Controller } from '@nestjs/common';
|
import { Controller } from '@nestjs/common';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
import { EventPattern, MessagePattern } from '@nestjs/microservices';
|
import { EventPattern } from '@nestjs/microservices';
|
||||||
import { RbacService } from './rbac/rbac.service';
|
import { RbacService } from './rbac/rbac.service';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
|
@ -10,59 +10,59 @@ export class AppController {
|
||||||
private readonly rbacService: RbacService,
|
private readonly rbacService: RbacService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.authorize' })
|
@EventPattern('cert.authorize')
|
||||||
async authorize(payload) {
|
async authorize(payload) {
|
||||||
console.log('获取user的token,进行payload权限的验证', payload);
|
console.log('获取user的token,进行payload权限的验证', payload);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.init.role.admin' })
|
@EventPattern('cert.init.role.admin')
|
||||||
async initRole() {
|
async initRole() {
|
||||||
await this.rbacService.initSuperAdminRole();
|
await this.rbacService.initSuperAdminRole();
|
||||||
await this.rbacService.initSuperAdminAccount();
|
await this.rbacService.initSuperAdminAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.create.role' })
|
@EventPattern('cert.create.role')
|
||||||
async createRole(payload) {
|
async createRole(payload) {
|
||||||
return await this.rbacService.createRole(payload);
|
return await this.rbacService.createRole(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.remove.role' })
|
@EventPattern('cert.remove.role')
|
||||||
async removeRole(payload) {
|
async removeRole(payload) {
|
||||||
return await this.rbacService.removeRole(payload);
|
return await this.rbacService.removeRole(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.find.role.all' })
|
@EventPattern('cert.find.role.all')
|
||||||
async findAllRole() {
|
async findAllRole() {
|
||||||
return await this.rbacService.findAllRole();
|
return await this.rbacService.findAllRole();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.init.permission.resource' })
|
@EventPattern('cert.init.permission.resource')
|
||||||
async initPermission(payload) {
|
async initPermission(payload) {
|
||||||
await this.rbacService.initPermission(payload);
|
await this.rbacService.initPermission(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.find.role.permission' })
|
@EventPattern('cert.find.role.permission')
|
||||||
async findRolePermission(payload) {
|
async findRolePermission(payload) {
|
||||||
return await this.rbacService.findRolePermission(payload);
|
return await this.rbacService.findRolePermission(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.update.role.permissions' })
|
@EventPattern('cert.update.role.permissions')
|
||||||
async updateRolePermissions(payload) {
|
async updateRolePermissions(payload) {
|
||||||
return await this.rbacService.updateRolePermissions(payload);
|
return await this.rbacService.updateRolePermissions(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.update.role' })
|
@EventPattern('cert.update.role')
|
||||||
async updateRole(payload) {
|
async updateRole(payload) {
|
||||||
return await this.rbacService.updateRole(payload);
|
return await this.rbacService.updateRole(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.find.all.user' })
|
@EventPattern('cert.find.all.user')
|
||||||
async findAllUser() {
|
async findAllUser() {
|
||||||
return await this.rbacService.findAllUser();
|
return await this.rbacService.findAllUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.role.authorize' })
|
@EventPattern('cert.role.authorize')
|
||||||
async roleAuthorize({ user, url }) {
|
async roleAuthorize({ user, url }) {
|
||||||
const allow = await this.rbacService.roleAuthorize(user, url);
|
const allow = await this.rbacService.roleAuthorize(user, url);
|
||||||
return { allow };
|
return { allow };
|
||||||
|
|
|
@ -12,7 +12,7 @@ export class UserController {
|
||||||
/**
|
/**
|
||||||
* 用户账号、密码、是否可用
|
* 用户账号、密码、是否可用
|
||||||
*/
|
*/
|
||||||
@EventPattern({ cmd: 'cert.user.account' })
|
@EventPattern('cert.user.account')
|
||||||
async findUser(
|
async findUser(
|
||||||
payload,
|
payload,
|
||||||
): Promise<{ isLegal: boolean; msg?: string; data?: any }> {
|
): Promise<{ isLegal: boolean; msg?: string; data?: any }> {
|
||||||
|
@ -28,22 +28,22 @@ export class UserController {
|
||||||
return { isLegal: true, data: user };
|
return { isLegal: true, data: user };
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.user.encrypt' })
|
@EventPattern('cert.user.encrypt')
|
||||||
async encrypt(plainText: string) {
|
async encrypt(plainText: string) {
|
||||||
return await this.bcryptService.hashPassword(plainText);
|
return await this.bcryptService.hashPassword(plainText);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.encrypt.compare' })
|
@EventPattern('cert.encrypt.compare')
|
||||||
async compare(plainText: string, hash: string) {
|
async compare(plainText: string, hash: string) {
|
||||||
return await this.bcryptService.comparePassword(plainText, hash);
|
return await this.bcryptService.comparePassword(plainText, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.user.create' })
|
@EventPattern('cert.user.create')
|
||||||
async createUser(payload) {
|
async createUser(payload) {
|
||||||
return await this.userService.create(payload);
|
return await this.userService.create(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.user.update' })
|
@EventPattern('cert.user.update')
|
||||||
async updateUser(payload) {
|
async updateUser(payload) {
|
||||||
const { password, ...rest } = payload;
|
const { password, ...rest } = payload;
|
||||||
const updateFields = password
|
const updateFields = password
|
||||||
|
@ -52,12 +52,12 @@ export class UserController {
|
||||||
return await this.userService.update(updateFields);
|
return await this.userService.update(updateFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.user.delete' })
|
@EventPattern('cert.user.delete')
|
||||||
async deleteUser(userIds: number[]) {
|
async deleteUser(userIds: number[]) {
|
||||||
return await this.userService.delete(userIds);
|
return await this.userService.delete(userIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'cert.user.find.annotator' })
|
@EventPattern('cert.user.find.annotator')
|
||||||
async findAnnotators() {
|
async findAnnotators() {
|
||||||
const annotators = await this.userService.findAnnotators();
|
const annotators = await this.userService.findAnnotators();
|
||||||
return { data: annotators };
|
return { data: annotators };
|
||||||
|
|
|
@ -25,7 +25,7 @@ export class AdminController {
|
||||||
@Post('role/create')
|
@Post('role/create')
|
||||||
async createRole(@Body() createRoleDto: CreateRoleDto) {
|
async createRole(@Body() createRoleDto: CreateRoleDto) {
|
||||||
const { success, result, message } = await firstValueFrom(
|
const { success, result, message } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.create.role' }, createRoleDto),
|
this.client.send('cert.create.role', createRoleDto),
|
||||||
);
|
);
|
||||||
return success
|
return success
|
||||||
? { code: 0, data: result, msg: message }
|
? { code: 0, data: result, msg: message }
|
||||||
|
@ -34,14 +34,14 @@ export class AdminController {
|
||||||
|
|
||||||
@Post('role/remove')
|
@Post('role/remove')
|
||||||
async removeRole(@Body() role: RoleDto) {
|
async removeRole(@Body() role: RoleDto) {
|
||||||
const pattern = { cmd: 'cert.remove.role' };
|
const pattern = 'cert.remove.role';
|
||||||
const result = await firstValueFrom(this.client.send(pattern, role));
|
const result = await firstValueFrom(this.client.send(pattern, role));
|
||||||
return { code: 'ok', data: result };
|
return { code: 'ok', data: result };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('role/update')
|
@Post('role/update')
|
||||||
async updateRole(@Body() forbidRoleDto: ForbidRoleDto) {
|
async updateRole(@Body() forbidRoleDto: ForbidRoleDto) {
|
||||||
const pattern = { cmd: 'cert.update.role' };
|
const pattern = 'cert.update.role';
|
||||||
const payload = forbidRoleDto;
|
const payload = forbidRoleDto;
|
||||||
const result = await firstValueFrom(this.client.send(pattern, payload));
|
const result = await firstValueFrom(this.client.send(pattern, payload));
|
||||||
return { code: 'ok', data: result };
|
return { code: 'ok', data: result };
|
||||||
|
@ -49,14 +49,14 @@ export class AdminController {
|
||||||
|
|
||||||
@Get('find/role/all')
|
@Get('find/role/all')
|
||||||
async findAllRolePermissions() {
|
async findAllRolePermissions() {
|
||||||
const pattern = { cmd: 'cert.find.role.all' };
|
const pattern = 'cert.find.role.all';
|
||||||
const result = await firstValueFrom(this.client.send(pattern, []));
|
const result = await firstValueFrom(this.client.send(pattern, []));
|
||||||
return { code: 'ok', data: result };
|
return { code: 'ok', data: result };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('role/permissions/find')
|
@Post('role/permissions/find')
|
||||||
async findRolePermission(@Body() findRoleDto: FindRoleDto): Promise<any> {
|
async findRolePermission(@Body() findRoleDto: FindRoleDto): Promise<any> {
|
||||||
const pattern = { cmd: 'cert.find.role.permission' };
|
const pattern = 'cert.find.role.permission';
|
||||||
const payload = findRoleDto.id;
|
const payload = findRoleDto.id;
|
||||||
// 角色在role-permission关联表中已存在的权限
|
// 角色在role-permission关联表中已存在的权限
|
||||||
const { permissions } = await firstValueFrom(
|
const { permissions } = await firstValueFrom(
|
||||||
|
@ -79,7 +79,7 @@ export class AdminController {
|
||||||
async updateRolePermissions(
|
async updateRolePermissions(
|
||||||
@Body() updateRolePermissionsDto: UpdateRolePermissionsDto,
|
@Body() updateRolePermissionsDto: UpdateRolePermissionsDto,
|
||||||
) {
|
) {
|
||||||
const pattern = { cmd: 'cert.update.role.permissions' };
|
const pattern = 'cert.update.role.permissions';
|
||||||
const { roleId, permissionIds } = updateRolePermissionsDto;
|
const { roleId, permissionIds } = updateRolePermissionsDto;
|
||||||
const payload = { roleId, permissionIds };
|
const payload = { roleId, permissionIds };
|
||||||
const result = await firstValueFrom(this.client.send(pattern, payload));
|
const result = await firstValueFrom(this.client.send(pattern, payload));
|
||||||
|
@ -89,7 +89,7 @@ export class AdminController {
|
||||||
@Post('user/create')
|
@Post('user/create')
|
||||||
async createUser(@Body() createUserDto: CreateUserDto) {
|
async createUser(@Body() createUserDto: CreateUserDto) {
|
||||||
const { success, msg, data } = await firstValueFrom(
|
const { success, msg, data } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.user.create' }, createUserDto),
|
this.client.send('cert.user.create', createUserDto),
|
||||||
);
|
);
|
||||||
return success ? { code: 0, data, msg } : { code: 1, msg };
|
return success ? { code: 0, data, msg } : { code: 1, msg };
|
||||||
}
|
}
|
||||||
|
@ -97,26 +97,24 @@ export class AdminController {
|
||||||
@Get('user/find/all')
|
@Get('user/find/all')
|
||||||
async userSelect() {
|
async userSelect() {
|
||||||
const result = await firstValueFrom(
|
const result = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.find.all.user' }, []),
|
this.client.send('cert.find.all.user', []),
|
||||||
);
|
);
|
||||||
return { code: 'ok', data: result };
|
return { code: 'ok', data: result };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('user/update')
|
@Post('user/update')
|
||||||
async userUpdate(@Body() user: UpdateUserDto) {
|
async userUpdate(@Body() user: UpdateUserDto) {
|
||||||
const pattern = { cmd: 'cert.user.update' };
|
const pattern = 'cert.user.update';
|
||||||
const payload = user;
|
const payload = user;
|
||||||
const result = await firstValueFrom(this.client.send(pattern, payload));
|
const result = await firstValueFrom(this.client.send(pattern, payload));
|
||||||
// 删除token
|
// 删除token
|
||||||
await firstValueFrom(
|
await firstValueFrom(this.client.send('cert.token.deprecated', payload));
|
||||||
this.client.send({ cmd: 'cert.token.deprecated' }, payload),
|
|
||||||
);
|
|
||||||
return { code: 'ok', data: result };
|
return { code: 'ok', data: result };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('user/delete')
|
@Post('user/delete')
|
||||||
async userDelete(@Body() userIds: number[]) {
|
async userDelete(@Body() userIds: number[]) {
|
||||||
const pattern = { cmd: 'cert.user.delete' };
|
const pattern = 'cert.user.delete';
|
||||||
const payload = userIds;
|
const payload = userIds;
|
||||||
const result = await firstValueFrom(this.client.send(pattern, payload));
|
const result = await firstValueFrom(this.client.send(pattern, payload));
|
||||||
return { code: 'ok', data: result };
|
return { code: 'ok', data: result };
|
||||||
|
|
|
@ -17,12 +17,12 @@ export class AppController {
|
||||||
@Get('/auth/user')
|
@Get('/auth/user')
|
||||||
async auth(@Req() request: Request) {
|
async auth(@Req() request: Request) {
|
||||||
const { tokenKeyInCookie } = await firstValueFrom(
|
const { tokenKeyInCookie } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.config' }, []),
|
this.client.send('cert.token.config', []),
|
||||||
);
|
);
|
||||||
const tokenCipher = request.cookies[tokenKeyInCookie];
|
const tokenCipher = request.cookies[tokenKeyInCookie];
|
||||||
if (!tokenCipher) return { code: 1, msg: '登录状态失效,请重新登录' };
|
if (!tokenCipher) return { code: 1, msg: '登录状态失效,请重新登录' };
|
||||||
const result = await firstValueFrom(
|
const result = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.decode' }, tokenCipher),
|
this.client.send('cert.token.decode', tokenCipher),
|
||||||
);
|
);
|
||||||
return { code: 0, data: result };
|
return { code: 0, data: result };
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ export class AppService {
|
||||||
*/
|
*/
|
||||||
async permissionResourceInitialization() {
|
async permissionResourceInitialization() {
|
||||||
console.log('初始化资源权限');
|
console.log('初始化资源权限');
|
||||||
const pattern = { cmd: 'cert.init.permission.resource' };
|
const pattern = 'cert.init.permission.resource';
|
||||||
const payload = rbacConfiguration.map((i) => i.permissions).flat();
|
const payload = rbacConfiguration.map((i) => i.permissions).flat();
|
||||||
const result = await firstValueFrom(this.client.emit(pattern, payload));
|
const result = await firstValueFrom(this.client.emit(pattern, payload));
|
||||||
return { code: 'ok', data: result };
|
return { code: 'ok', data: result };
|
||||||
|
@ -22,7 +22,7 @@ export class AppService {
|
||||||
* 初始化角色资源&超级管理员账号
|
* 初始化角色资源&超级管理员账号
|
||||||
*/
|
*/
|
||||||
async roleInitialization() {
|
async roleInitialization() {
|
||||||
const pattern = { cmd: 'cert.init.role.admin' };
|
const pattern = 'cert.init.role.admin';
|
||||||
const payload = [];
|
const payload = [];
|
||||||
const result = await firstValueFrom(this.client.emit(pattern, payload));
|
const result = await firstValueFrom(this.client.emit(pattern, payload));
|
||||||
return { code: 'ok', data: result };
|
return { code: 'ok', data: result };
|
||||||
|
|
|
@ -118,7 +118,7 @@ export class AppController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'dicom.archive.url' })
|
@EventPattern('dicom.archive.url')
|
||||||
async archiveUrl({ ID, Type }: { ID: string; Type: string }) {
|
async archiveUrl({ ID, Type }: { ID: string; Type: string }) {
|
||||||
const pacsUrl = this.configService.get('PACS_URL');
|
const pacsUrl = this.configService.get('PACS_URL');
|
||||||
const mapping = {
|
const mapping = {
|
||||||
|
|
|
@ -6,12 +6,12 @@ import { EventPattern } from '@nestjs/microservices';
|
||||||
export class AppController {
|
export class AppController {
|
||||||
constructor(private readonly appService: AppService) {}
|
constructor(private readonly appService: AppService) {}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'archive.task.create' })
|
@EventPattern('archive.task.create')
|
||||||
async createArchiveTask(payload) {
|
async createArchiveTask(payload) {
|
||||||
return await this.appService.createArchiveTask(payload);
|
return await this.appService.createArchiveTask(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'archive.task.find' })
|
@EventPattern('archive.task.find')
|
||||||
async findArchiveTask(payload) {
|
async findArchiveTask(payload) {
|
||||||
return await this.appService.findArchiveTask(payload);
|
return await this.appService.findArchiveTask(payload);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ export class AdminController {
|
||||||
@Get('find/annotator')
|
@Get('find/annotator')
|
||||||
async findAnnotator() {
|
async findAnnotator() {
|
||||||
const { data } = await firstValueFrom(
|
const { data } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.user.find.annotator' }, {}),
|
this.client.send('cert.user.find.annotator', {}),
|
||||||
);
|
);
|
||||||
return { data, code: 0 };
|
return { data, code: 0 };
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ export class AdminController {
|
||||||
const { user, study } = body;
|
const { user, study } = body;
|
||||||
const { username } = user;
|
const { username } = user;
|
||||||
const { success, data, error } = await firstValueFrom(
|
const { success, data, error } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'archive.task.create' }, { username, study }),
|
this.client.send('archive.task.create', { username, study }),
|
||||||
);
|
);
|
||||||
return success ? { code: 0, data } : { code: 1, msg: error.code };
|
return success ? { code: 0, data } : { code: 1, msg: error.code };
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,15 @@ export class AnnotatorController {
|
||||||
@Get('find/archiveTask')
|
@Get('find/archiveTask')
|
||||||
async findArchiveTask(@Req() request: Request) {
|
async findArchiveTask(@Req() request: Request) {
|
||||||
const { tokenKeyInCookie } = await firstValueFrom(
|
const { tokenKeyInCookie } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.config' }, []),
|
this.client.send('cert.token.config', []),
|
||||||
);
|
);
|
||||||
const tokenCipher = request.cookies[tokenKeyInCookie];
|
const tokenCipher = request.cookies[tokenKeyInCookie];
|
||||||
const { payload } = await firstValueFrom(
|
const { payload } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.decode' }, tokenCipher),
|
this.client.send('cert.token.decode', tokenCipher),
|
||||||
);
|
);
|
||||||
const { username } = payload;
|
const { username } = payload;
|
||||||
const data = await firstValueFrom(
|
const data = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'archive.task.find' }, { username }),
|
this.client.send('archive.task.find', { username }),
|
||||||
);
|
);
|
||||||
return { code: 0, data };
|
return { code: 0, data };
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,29 +16,26 @@ export class AuthController {
|
||||||
) {
|
) {
|
||||||
const { username, password } = userLoginDto;
|
const { username, password } = userLoginDto;
|
||||||
const { isLegal, data, msg } = await firstValueFrom(
|
const { isLegal, data, msg } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.user.account' }, { username, password }),
|
this.client.send('cert.user.account', { username, password }),
|
||||||
);
|
);
|
||||||
// 日志
|
// 日志
|
||||||
await firstValueFrom(
|
await firstValueFrom(
|
||||||
this.client.send(
|
this.client.send('logger.user.signIn', {
|
||||||
{ cmd: 'logger.user.signIn' },
|
|
||||||
{
|
|
||||||
platform: 'dmp',
|
platform: 'dmp',
|
||||||
username,
|
username,
|
||||||
finger: request.headers['x-finger'] as string,
|
finger: request.headers['x-finger'] as string,
|
||||||
finger2: request.headers['x-finger2'] as string,
|
finger2: request.headers['x-finger2'] as string,
|
||||||
isLegal,
|
isLegal,
|
||||||
},
|
}),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
if (isLegal) {
|
if (isLegal) {
|
||||||
// 签发token,签用户的角色,前端UI路由鉴权
|
// 签发token,签用户的角色,前端UI路由鉴权
|
||||||
const { roles } = data;
|
const { roles } = data;
|
||||||
const { token } = await firstValueFrom(
|
const { token } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.create' }, { username, roles }),
|
this.client.send('cert.token.create', { username, roles }),
|
||||||
);
|
);
|
||||||
const { tokenKeyInCookie, expires } = await firstValueFrom(
|
const { tokenKeyInCookie, expires } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.config' }, []),
|
this.client.send('cert.token.config', []),
|
||||||
);
|
);
|
||||||
res.cookie(tokenKeyInCookie, token, {
|
res.cookie(tokenKeyInCookie, token, {
|
||||||
maxAge: expires * 1000,
|
maxAge: expires * 1000,
|
||||||
|
|
|
@ -12,7 +12,7 @@ export class DicomController {
|
||||||
async downloadDicom(@Body() body, @Res() res: Response) {
|
async downloadDicom(@Body() body, @Res() res: Response) {
|
||||||
const { ID, Type } = body;
|
const { ID, Type } = body;
|
||||||
const url = await firstValueFrom(
|
const url = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'dicom.archive.url' }, { ID, Type }),
|
this.client.send('dicom.archive.url', { ID, Type }),
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
const { data: dataStream } = await axios.get(url, {
|
const { data: dataStream } = await axios.get(url, {
|
||||||
|
|
|
@ -29,14 +29,14 @@ export class AuthGuard implements CanActivate {
|
||||||
|
|
||||||
// 获取token的配置
|
// 获取token的配置
|
||||||
const { tokenKeyInCookie, tokenResignIn, expires } = await firstValueFrom(
|
const { tokenKeyInCookie, tokenResignIn, expires } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.config' }, []),
|
this.client.send('cert.token.config', []),
|
||||||
);
|
);
|
||||||
const tokenCipher = request.cookies[tokenKeyInCookie];
|
const tokenCipher = request.cookies[tokenKeyInCookie];
|
||||||
if (!tokenCipher) throw new ForbiddenException('您没有执行此操作的权限');
|
if (!tokenCipher) throw new ForbiddenException('您没有执行此操作的权限');
|
||||||
|
|
||||||
// 1.验证token是否合法
|
// 1.验证token是否合法
|
||||||
const { tokenValid, payload } = await firstValueFrom(
|
const { tokenValid, payload } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.decode' }, tokenCipher),
|
this.client.send('cert.token.decode', tokenCipher),
|
||||||
);
|
);
|
||||||
if (!tokenValid) throw new ForbiddenException('您没有执行此操作的权限');
|
if (!tokenValid) throw new ForbiddenException('您没有执行此操作的权限');
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ export class AuthGuard implements CanActivate {
|
||||||
if (tokenExpiredSoon) {
|
if (tokenExpiredSoon) {
|
||||||
const { username } = payload;
|
const { username } = payload;
|
||||||
const { token: newToken } = await firstValueFrom(
|
const { token: newToken } = await firstValueFrom(
|
||||||
this.client.send({ cmd: 'cert.token.create' }, { username }),
|
this.client.send('cert.token.create', { username }),
|
||||||
);
|
);
|
||||||
request.res.cookie(tokenKeyInCookie, newToken, {
|
request.res.cookie(tokenKeyInCookie, newToken, {
|
||||||
maxAge: expires * 1000,
|
maxAge: expires * 1000,
|
||||||
|
@ -65,10 +65,10 @@ export class AuthGuard implements CanActivate {
|
||||||
*/
|
*/
|
||||||
async rolePermissionAllow(payload: { username: string }, requestUrl: string) {
|
async rolePermissionAllow(payload: { username: string }, requestUrl: string) {
|
||||||
const { allow } = await firstValueFrom(
|
const { allow } = await firstValueFrom(
|
||||||
this.client.send(
|
this.client.send('cert.role.authorize', {
|
||||||
{ cmd: 'cert.role.authorize' },
|
user: payload,
|
||||||
{ user: payload, url: requestUrl },
|
url: requestUrl,
|
||||||
),
|
}),
|
||||||
);
|
);
|
||||||
return { allow };
|
return { allow };
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ interface UserSignLoggerDto {
|
||||||
export class AppController {
|
export class AppController {
|
||||||
constructor(private readonly appService: AppService) {}
|
constructor(private readonly appService: AppService) {}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'logger.user.signIn' })
|
@EventPattern('logger.user.signIn')
|
||||||
async userSignIn(payload: UserSignLoggerDto) {
|
async userSignIn(payload: UserSignLoggerDto) {
|
||||||
const dateTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
const dateTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
||||||
const { finger2, ...rest } = payload;
|
const { finger2, ...rest } = payload;
|
||||||
|
@ -25,7 +25,7 @@ export class AppController {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventPattern({ cmd: 'logger.save' })
|
@EventPattern('logger.save')
|
||||||
async saveLogger(payload: UserSignLoggerDto) {
|
async saveLogger(payload: UserSignLoggerDto) {
|
||||||
return 'ok';
|
return 'ok';
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
// 网关
|
// 网关
|
||||||
@Get('/hello')
|
@Get('/hello')
|
||||||
async getHello(): Promise<any> {
|
async getHello(): Promise<any> {
|
||||||
const pattern = { cmd: 'sum' };
|
const pattern = 'sum';
|
||||||
const payload = [1, 2];
|
const payload = [1, 2];
|
||||||
// this.client.emit(pattern,payload)没有返回值
|
// this.client.emit(pattern,payload)没有返回值
|
||||||
const it = await this.client.send<number[]>(pattern, payload);
|
const it = await this.client.send<number[]>(pattern, payload);
|
||||||
|
@ -14,7 +14,7 @@ async getHello(): Promise<any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 服务
|
// 服务
|
||||||
@EventPattern({ cmd: 'sum' })
|
@EventPattern('sum')
|
||||||
sum(data: number[]): number {
|
sum(data: number[]): number {
|
||||||
return (data || []).reduce((a, b) => a + b);
|
return (data || []).reduce((a, b) => a + b);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user