Browse Source

fix: 数据库名称校验调整

pull/81/head
ssongliu 2 years ago committed by ssongliu
parent
commit
e13bb924d6
  1. 4
      backend/app/service/database_mysql.go
  2. 42
      frontend/src/global/form-rules.ts
  3. 4
      frontend/src/lang/modules/en.ts
  4. 4
      frontend/src/lang/modules/zh.ts
  5. 2
      frontend/src/views/app-store/detail/install/index.vue
  6. 2
      frontend/src/views/database/mysql/create/index.vue
  7. 6
      frontend/src/views/database/mysql/index.vue
  8. 6
      frontend/src/views/database/redis/index.vue

4
backend/app/service/database_mysql.go

@ -169,14 +169,14 @@ func (u *MysqlService) Create(mysqlDto dto.MysqlDBCreate) error {
return errors.WithMessage(constant.ErrStructTransform, err.Error())
}
if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("create database if not exists %s character set=%s", mysqlDto.Name, mysqlDto.Format)); err != nil {
if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("create database if not exists `%s` character set=%s", mysqlDto.Name, mysqlDto.Format)); err != nil {
return err
}
tmpPermission := mysqlDto.Permission
if err := excuteSql(app.ContainerName, app.Password, fmt.Sprintf("create user if not exists '%s'@'%s' identified by '%s';", mysqlDto.Username, tmpPermission, mysqlDto.Password)); err != nil {
return err
}
grantStr := fmt.Sprintf("grant all privileges on %s.* to '%s'@'%s'", mysqlDto.Name, mysqlDto.Username, tmpPermission)
grantStr := fmt.Sprintf("grant all privileges on `%s`.* to '%s'@'%s'", mysqlDto.Name, mysqlDto.Username, tmpPermission)
if app.Version == "5.7.39" {
grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, mysqlDto.Password)
}

42
frontend/src/global/form-rules.ts

@ -32,7 +32,7 @@ const checkName = (rule: any, value: any, callback: any) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback(new Error(i18n.global.t('commons.rule.commonName')));
} else {
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9_]{0,30}$/;
const reg = /^[a-zA-Z0-9\u4e00-\u9fa5]{1}[a-zA-Z0-9_.\u4e00-\u9fa5-]{0,30}$/;
if (!reg.test(value) && value !== '') {
callback(new Error(i18n.global.t('commons.rule.commonName')));
} else {
@ -41,9 +41,35 @@ const checkName = (rule: any, value: any, callback: any) => {
}
};
const checkSimpleName = (rule: any, value: any, callback: any) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback(new Error(i18n.global.t('commons.rule.simpleName')));
} else {
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9_]{0,30}$/;
if (!reg.test(value) && value !== '') {
callback(new Error(i18n.global.t('commons.rule.simpleName')));
} else {
callback();
}
}
};
const checkDBName = (rule: any, value: any, callback: any) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback(new Error(i18n.global.t('commons.rule.dbName')));
} else {
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9_.-]{0,30}$/;
if (!reg.test(value) && value !== '') {
callback(new Error(i18n.global.t('commons.rule.dbName')));
} else {
callback();
}
}
};
const checkImageName = (rule: any, value: any, callback: any) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback(new Error(i18n.global.t('commons.rule.commonName')));
callback(new Error(i18n.global.t('commons.rule.imageName')));
} else {
const reg = /^[a-zA-Z0-9\u4e00-\u9fa5]{1}[a-z:A-Z0-9_.\u4e00-\u9fa5-]{0,30}$/;
if (!reg.test(value) && value !== '') {
@ -98,6 +124,8 @@ interface CommonRule {
requiredSelect: FormItemRule;
requiredSelectBusiness: FormItemRule;
name: FormItemRule;
simpleName: FormItemRule;
dbName: FormItemRule;
imageName: FormItemRule;
linuxName: FormItemRule;
password: FormItemRule;
@ -128,6 +156,16 @@ export const Rules: CommonRule = {
message: i18n.global.t('commons.rule.requiredSelect'),
trigger: 'change',
},
simpleName: {
required: true,
validator: checkSimpleName,
trigger: 'blur',
},
dbName: {
required: true,
validator: checkDBName,
trigger: 'blur',
},
imageName: {
required: true,
validator: checkImageName,

4
frontend/src/lang/modules/en.ts

@ -102,7 +102,9 @@ export default {
rePassword: 'The passwords are inconsistent. Please check and re-enter the password',
requiredInput: 'Please enter the required fields',
requiredSelect: 'Please select the required fields',
commonName: 'Support English, numbers, _, length 1-30',
commonName: 'Support English, Chinese, numbers, .-, and _ length 1-30',
simpleName: 'Support English, numbers and _ length 1-30',
dbName: 'Support English, numbers, .-, and _ length 1-30',
imageName: 'Support English, Chinese, numbers, :.-_, length 1-30',
complexityPassword:
'Please enter a password with more than 8 characters and must contain letters, digits, and special symbols',

4
frontend/src/lang/modules/zh.ts

@ -102,7 +102,9 @@ export default {
rePassword: '密码不一致请检查后重新输入',
requiredInput: '请填写必填项',
requiredSelect: '请选择必选项',
commonName: '支持英文数字_,长度1-30',
commonName: '支持英文中文数字.-和_,长度1-30',
simpleName: '支持英文数字_,长度1-30',
dbName: '支持英文数字:.-_,长度1-30',
imageName: '支持英文中文数字:.-_,长度1-30',
complexityPassword: '请输入 8 位以上必须含有字母数字特殊符号的密码',
commonPassword: '请输入 6 位以上长度密码',

2
frontend/src/views/app-store/detail/install/index.vue

@ -46,7 +46,7 @@ const installData = ref<InstallRrops>({
let open = ref(false);
let form = ref<{ [key: string]: any }>({});
let rules = ref<FormRules>({
NAME: [Rules.requiredInput],
NAME: [Rules.simpleName],
});
let loading = false;
const paramForm = ref<FormInstance>();

2
frontend/src/views/database/mysql/create/index.vue

@ -69,7 +69,7 @@ const form = reactive({
description: '',
});
const rules = reactive({
name: [Rules.requiredInput, Rules.name],
name: [Rules.requiredInput, Rules.dbName],
username: [Rules.requiredInput, Rules.name],
password: [Rules.requiredInput],
permission: [Rules.requiredSelect],

6
frontend/src/views/database/mysql/index.vue

@ -10,7 +10,11 @@
/>
<Setting ref="settingRef" style="margin-top: 20px" />
<el-card width="30%" v-if="mysqlStatus != 'Running' && !isOnSetting && mysqlIsExist" class="mask-prompt">
<el-card
width="30%"
v-if="mysqlStatus != 'Running' && !isOnSetting && mysqlIsExist && !loading"
class="mask-prompt"
>
<span style="font-size: 14px">{{ $t('commons.service.serviceNotStarted', ['Mysql']) }}</span>
</el-card>
<div v-if="mysqlIsExist" :class="{ mask: mysqlStatus != 'Running' }">

6
frontend/src/views/database/redis/index.vue

@ -10,7 +10,11 @@
@is-exist="checkExist"
v-model:loading="loading"
></AppStatus>
<el-card width="30%" v-if="redisStatus != 'Running' && !isOnSetting && redisIsExist" class="mask-prompt">
<el-card
width="30%"
v-if="redisStatus != 'Running' && !isOnSetting && redisIsExist && !loading"
class="mask-prompt"
>
<span style="font-size: 14px">{{ $t('commons.service.serviceNotStarted', ['Redis']) }}</span>
</el-card>

Loading…
Cancel
Save