perf: 自动生成jwtkey,无需手动配置

This commit is contained in:
xiaojunnuo
2024-07-15 01:29:19 +08:00
parent 485e603b51
commit 390e4853a5
8 changed files with 65 additions and 30 deletions
+1
View File
@@ -8,3 +8,4 @@ VITE_APP_COPYRIGHT_NAME=handsfree.work
VITE_APP_COPYRIGHT_URL=https://certd.handsfree.work
VITE_APP_LOGO_PATH=./images/logo/logo.svg
VITE_APP_PROJECT_PATH=https://github.com/certd/certd
VITE_APP_ICP_NO=
@@ -21,6 +21,7 @@
import * as api from "./api";
import { Ref, ref } from "vue";
import { CrudOptions, useColumns, useFormWrapper } from "@fast-crud/fast-crud";
import { notification } from "ant-design-vue";
const userInfo: Ref = ref({});
@@ -54,10 +55,14 @@ const passwordFormOptions: CrudOptions = {
span: 24
},
wrapper: {
title: "修改密码",
width: "500px"
},
async doSubmit({ form }) {
await api.changePassword(form);
},
async afterSubmit() {
notification.success({ message: "修改成功" });
}
},
columns: {
@@ -97,7 +102,6 @@ async function changePassword() {
const formOptions = buildFormOptions(passwordFormOptions);
formOptions.newInstance = true; //新实例打开
passwordFormRef.value = await openDialog(formOptions);
debugger;
console.log(passwordFormRef.value);
}
</script>
+2
View File
@@ -14,3 +14,5 @@ run/
./data
./test/**/*.js
/test/setup.js
/test/setup.ts
@@ -1,9 +1,9 @@
import { MidwayConfig } from '@midwayjs/core';
import { join } from 'path';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
// const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(fileURLToPath(import.meta.url));
// import { join } from 'path';
// import { dirname } from 'node:path';
// import { fileURLToPath } from 'node:url';
// // const __filename = fileURLToPath(import.meta.url);
// const __dirname = dirname(fileURLToPath(import.meta.url));
import { FlywayHistory } from '@certd/midway-flyway-js';
import { UserEntity } from '../modules/authority/entity/user.js';
@@ -11,8 +11,11 @@ import { PipelineEntity } from '../modules/pipeline/entity/pipeline.js';
//import { logger } from '../utils/logger';
// load .env file in process.cwd
import { mergeConfig } from './loader.js';
import { Keys } from './keys.js';
const keys = Keys.load();
const development = {
keys: '111',
keys: keys.cookieKeys,
koa: {
port: 7001,
},
@@ -49,7 +52,7 @@ const development = {
* 单数据库实例
*/
type: 'sqlite',
database: join(__dirname, '../../data/db.sqlite'),
database: './data/db.sqlite',
synchronize: false, // 如果第一次使用,不存在表,有同步的需求可以写 true
logging: true,
@@ -62,17 +65,17 @@ const development = {
* 自动升级数据库脚本
*/
flyway: {
scriptDir: join(__dirname, '../../db/migration'),
scriptDir: './db/migration',
},
auth: {
jwt: {
secret: 'certd666',
secret: keys.jwtKey,
expire: 7 * 24 * 60 * 60, //单位秒
},
},
certd: {
fileRootDir: '/app/data/files',
fileRootDir: './data/files',
},
system: {
resetAdminPasswd: false,
@@ -0,0 +1,24 @@
import fs from 'fs';
import yaml from 'js-yaml';
import * as _ from 'lodash-es';
import { nanoid } from 'nanoid';
const KEYS_FILE = './data/keys.yaml';
export class Keys {
jwtKey: string = nanoid();
cookieKeys: string[] = [nanoid()];
static load(): Keys {
const keys = new Keys();
if (fs.existsSync(KEYS_FILE)) {
const content = fs.readFileSync(KEYS_FILE, 'utf8');
const json = yaml.load(content);
_.merge(keys, json);
}
keys.save();
return keys;
}
save() {
fs.writeFileSync(KEYS_FILE, yaml.dump(this));
}
}