mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
Merge branch 'server_sync' into v2
# Conflicts: # packages/ui/certd-server/.eslintrc.json # packages/ui/certd-server/.gitignore # packages/ui/certd-server/LICENSE # packages/ui/certd-server/README.md # packages/ui/certd-server/bootstrap.js # packages/ui/certd-server/package.json # packages/ui/certd-server/src/basic/base-service.ts # packages/ui/certd-server/src/basic/crud-controller.ts # packages/ui/certd-server/src/config/config.default.ts # packages/ui/certd-server/src/configuration.ts # packages/ui/certd-server/src/middleware/authority.ts # packages/ui/certd-server/src/middleware/global-exception.ts # packages/ui/certd-server/src/middleware/preview.ts # packages/ui/certd-server/src/middleware/report.ts # packages/ui/certd-server/src/modules/authority/controller/permission-controller.ts # packages/ui/certd-server/src/modules/authority/controller/role-controller.ts # packages/ui/certd-server/src/modules/authority/controller/user-controller.ts # packages/ui/certd-server/src/modules/authority/service/permission-service.ts # packages/ui/certd-server/src/modules/authority/service/role-permission-service.ts # packages/ui/certd-server/src/modules/authority/service/role-service.ts # packages/ui/certd-server/src/modules/authority/service/user-role-service.ts # packages/ui/certd-server/src/modules/authority/service/user-service.ts # packages/ui/certd-server/src/modules/basic/controller/basic-controller.ts # packages/ui/certd-server/src/modules/login/controller/login-controller.ts # packages/ui/certd-server/tsconfig.json
This commit is contained in:
@@ -23,8 +23,9 @@ export abstract class BaseService<T> {
|
||||
if (!id) {
|
||||
throw new ValidateException('id不能为空');
|
||||
}
|
||||
// @ts-ignore
|
||||
const info = await this.getRepository().findOne({ where: { id } });
|
||||
const info = await this.getRepository().findOne({
|
||||
where:{ id }
|
||||
});
|
||||
if (info && infoIgnoreProperty) {
|
||||
for (const property of infoIgnoreProperty) {
|
||||
delete info[property];
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { ALL, Body, Post, Query } from '@midwayjs/decorator';
|
||||
import { BaseService } from './base-service';
|
||||
import { BaseController } from './base-controller';
|
||||
|
||||
export abstract class CrudController extends BaseController {
|
||||
export abstract class CrudController<
|
||||
T extends BaseService
|
||||
> extends BaseController {
|
||||
abstract getService();
|
||||
|
||||
@Post('/page')
|
||||
@@ -62,3 +65,4 @@ export abstract class CrudController extends BaseController {
|
||||
return this.ok(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,17 +4,21 @@ import * as previewConfig from './config/config.preview';
|
||||
import * as defaultConfig from './config/config.default';
|
||||
import { Configuration, App } from '@midwayjs/decorator';
|
||||
import * as koa from '@midwayjs/koa';
|
||||
import * as bodyParser from 'koa-bodyparser';
|
||||
import * as orm from '@midwayjs/typeorm';
|
||||
import * as cache from '@midwayjs/cache';
|
||||
import cors from '@koa/cors';
|
||||
import * as cors from '@koa/cors';
|
||||
import { join } from 'path';
|
||||
import * as flyway from 'midway-flyway-js';
|
||||
import { ReportMiddleware } from './middleware/report';
|
||||
import { GlobalExceptionMiddleware } from './middleware/global-exception';
|
||||
import { PreviewMiddleware } from './middleware/preview';
|
||||
import { AuthorityMiddleware } from './middleware/authority';
|
||||
import {ReportMiddleware} from "./middleware/report";
|
||||
import {GlobalExceptionMiddleware} from "./middleware/global-exception";
|
||||
import {PreviewMiddleware} from "./middleware/preview";
|
||||
import {AuthorityMiddleware} from "./middleware/authority";
|
||||
|
||||
|
||||
import * as pipeline from './plugins/pipeline';
|
||||
import * as cron from './plugins/cron';
|
||||
|
||||
@Configuration({
|
||||
imports: [koa, orm, cache, flyway, validateComp,pipeline, cron],
|
||||
importConfigs: [
|
||||
@@ -54,7 +58,5 @@ export class ContainerLifeCycle {
|
||||
//授权处理
|
||||
AuthorityMiddleware,
|
||||
]);
|
||||
|
||||
//加载插件
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Config, Provide } from '@midwayjs/decorator';
|
||||
import {
|
||||
IWebMiddleware,
|
||||
IMidwayKoaContext,
|
||||
IMidwayKoaNext,
|
||||
NextFunction
|
||||
} from '@midwayjs/koa';
|
||||
import * as _ from 'lodash';
|
||||
import * as jwt from 'jsonwebtoken';
|
||||
@@ -19,7 +19,7 @@ export class AuthorityMiddleware implements IWebMiddleware {
|
||||
private ignoreUrls: string[];
|
||||
|
||||
resolve() {
|
||||
return async (ctx: IMidwayKoaContext, next: IMidwayKoaNext) => {
|
||||
return async (ctx: IMidwayKoaContext, next: NextFunction) => {
|
||||
const { url } = ctx;
|
||||
const token = ctx.get('Authorization');
|
||||
// 路由地址为 admin前缀的 需要权限校验
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Provide } from '@midwayjs/decorator';
|
||||
import {
|
||||
IWebMiddleware,
|
||||
IMidwayKoaContext,
|
||||
IMidwayKoaNext,
|
||||
NextFunction,
|
||||
} from '@midwayjs/koa';
|
||||
import { logger } from '../utils/logger';
|
||||
import { Result } from '../basic/result';
|
||||
@@ -10,7 +10,7 @@ import { Result } from '../basic/result';
|
||||
@Provide()
|
||||
export class GlobalExceptionMiddleware implements IWebMiddleware {
|
||||
resolve() {
|
||||
return async (ctx: IMidwayKoaContext, next: IMidwayKoaNext) => {
|
||||
return async (ctx: IMidwayKoaContext, next: NextFunction) => {
|
||||
const { url } = ctx;
|
||||
const startTime = Date.now();
|
||||
logger.info('请求开始:', url);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Config, Provide } from '@midwayjs/decorator';
|
||||
import {
|
||||
IMidwayKoaContext,
|
||||
IMidwayKoaNext,
|
||||
NextFunction,
|
||||
IWebMiddleware,
|
||||
} from '@midwayjs/koa';
|
||||
import { PreviewException } from '../basic/exception/preview-exception';
|
||||
@@ -15,7 +15,7 @@ export class PreviewMiddleware implements IWebMiddleware {
|
||||
private preview: boolean;
|
||||
|
||||
resolve() {
|
||||
return async (ctx: IMidwayKoaContext, next: IMidwayKoaNext) => {
|
||||
return async (ctx: IMidwayKoaContext, next: NextFunction) => {
|
||||
if (!this.preview) {
|
||||
await next();
|
||||
return;
|
||||
|
||||
@@ -2,14 +2,14 @@ import { Provide } from '@midwayjs/decorator';
|
||||
import {
|
||||
IWebMiddleware,
|
||||
IMidwayKoaContext,
|
||||
IMidwayKoaNext,
|
||||
NextFunction,
|
||||
} from '@midwayjs/koa';
|
||||
import { logger } from '../utils/logger';
|
||||
|
||||
@Provide()
|
||||
export class ReportMiddleware implements IWebMiddleware {
|
||||
resolve() {
|
||||
return async (ctx: IMidwayKoaContext, next: IMidwayKoaNext) => {
|
||||
return async (ctx: IMidwayKoaContext, next: NextFunction) => {
|
||||
const { url } = ctx;
|
||||
logger.info('请求开始:', url);
|
||||
const startTime = Date.now();
|
||||
|
||||
@@ -15,7 +15,7 @@ import { PermissionService } from '../service/permission-service';
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/sys/authority/permission')
|
||||
export class PermissionController extends CrudController {
|
||||
export class PermissionController extends CrudController<PermissionService> {
|
||||
@Inject()
|
||||
service: PermissionService;
|
||||
|
||||
@@ -60,3 +60,4 @@ export class PermissionController extends CrudController {
|
||||
return this.ok(tree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import { RoleService } from '../service/role-service';
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/sys/authority/role')
|
||||
export class RoleController extends CrudController {
|
||||
export class RoleController extends CrudController<RoleService> {
|
||||
@Inject()
|
||||
service: RoleService;
|
||||
|
||||
@@ -93,3 +93,4 @@ export class RoleController extends CrudController {
|
||||
return this.ok(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import { PermissionService } from '../service/permission-service';
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/sys/authority/user')
|
||||
export class UserController extends CrudController {
|
||||
export class UserController extends CrudController<UserService> {
|
||||
@Inject()
|
||||
service: UserService;
|
||||
|
||||
@@ -40,7 +40,7 @@ export class UserController extends CrudController {
|
||||
const users = ret.data.records;
|
||||
|
||||
//获取roles
|
||||
const userIds = users.map(item => item.id);
|
||||
const userIds = users.map((item) => item.id);
|
||||
const userRoles = await this.roleService.getByUserIds(userIds);
|
||||
const userRolesMap = new Map();
|
||||
for (const ur of userRoles) {
|
||||
@@ -116,3 +116,4 @@ export class UserController extends CrudController {
|
||||
return this.ok(tree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ import { Inject, Provide } from '@midwayjs/decorator';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { UserEntity } from '../entity/user';
|
||||
import _ from 'lodash';
|
||||
import md5 from 'md5';
|
||||
import * as _ from 'lodash';
|
||||
import * as md5 from 'md5';
|
||||
import { CommonException } from '../../../basic/exception/common-exception';
|
||||
import { BaseService } from '../../../basic/base-service';
|
||||
import { logger } from '../../../utils/logger';
|
||||
@@ -36,7 +36,7 @@ export class UserService extends BaseService<UserEntity> {
|
||||
const info = await this.repository.findOne({
|
||||
where: {
|
||||
id: this.ctx.user.id,
|
||||
},
|
||||
}
|
||||
});
|
||||
delete info.password;
|
||||
return info;
|
||||
@@ -48,9 +48,9 @@ export class UserService extends BaseService<UserEntity> {
|
||||
*/
|
||||
async add(param) {
|
||||
const exists = await this.repository.findOne({
|
||||
where: {
|
||||
where:{
|
||||
username: param.username,
|
||||
},
|
||||
}
|
||||
});
|
||||
if (!_.isEmpty(exists)) {
|
||||
throw new CommonException('用户名已经存在');
|
||||
@@ -74,7 +74,7 @@ export class UserService extends BaseService<UserEntity> {
|
||||
throw new CommonException('id不能为空');
|
||||
}
|
||||
const userInfo = await this.repository.findOne({
|
||||
where: { id: param.id },
|
||||
where:{ id: param.id }
|
||||
});
|
||||
if (!userInfo) {
|
||||
throw new CommonException('用户不存在');
|
||||
@@ -92,7 +92,7 @@ export class UserService extends BaseService<UserEntity> {
|
||||
|
||||
async findOne(param) {
|
||||
return this.repository.findOne({
|
||||
where: param,
|
||||
where:param
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Rule, RuleType } from '@midwayjs/validate';
|
||||
import { Rule,RuleType } from '@midwayjs/validate';
|
||||
import { ALL, Inject } from '@midwayjs/decorator';
|
||||
import { Body } from '@midwayjs/decorator';
|
||||
import { Controller, Post, Provide } from '@midwayjs/decorator';
|
||||
@@ -53,3 +53,4 @@ export class BasicController extends BaseController {
|
||||
return this.ok(captcha.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,3 +28,4 @@ export class LoginController extends BaseController {
|
||||
@Post('/logout')
|
||||
public logout() {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user