fix: 数据库名称校验调整

This commit is contained in:
ssongliu 2022-12-21 13:03:49 +08:00 committed by ssongliu
parent 4b15815dbf
commit e13bb924d6
8 changed files with 60 additions and 10 deletions

View File

@ -169,14 +169,14 @@ func (u *MysqlService) Create(mysqlDto dto.MysqlDBCreate) error {
return errors.WithMessage(constant.ErrStructTransform, err.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 return err
} }
tmpPermission := mysqlDto.Permission 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 { 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 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" { if app.Version == "5.7.39" {
grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, mysqlDto.Password) grantStr = fmt.Sprintf("%s identified by '%s' with grant option;", grantStr, mysqlDto.Password)
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,7 +10,11 @@
@is-exist="checkExist" @is-exist="checkExist"
v-model:loading="loading" v-model:loading="loading"
></AppStatus> ></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> <span style="font-size: 14px">{{ $t('commons.service.serviceNotStarted', ['Redis']) }}</span>
</el-card> </el-card>