fix: Redis 数据库连接信息移除密码限制 (#5239)

pull/5241/head
ssongliu 6 months ago committed by GitHub
parent 8c929004e9
commit 400dd79b9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -166,7 +166,7 @@ type MysqlVariablesUpdateHelper struct {
// redis
type ChangeRedisPass struct {
Database string `json:"database" validate:"required"`
Value string `json:"value" validate:"required"`
Value string `json:"value"`
}
type RedisConfUpdate struct {

@ -154,9 +154,15 @@ func (u *CommandService) ListRedisCommand() ([]dto.RedisCommand, error) {
return dtoCommands, err
}
func (u *CommandService) SaveRedisCommand(commandDto dto.RedisCommand) error {
func (u *CommandService) SaveRedisCommand(req dto.RedisCommand) error {
if req.ID == 0 {
command, _ := commandRepo.GetRedis(commonRepo.WithByName(req.Name))
if command.ID != 0 {
return constant.ErrRecordExist
}
}
var command model.RedisCommand
if err := copier.Copy(&command, &commandDto); err != nil {
if err := copier.Copy(&command, &req); err != nil {
return errors.WithMessage(constant.ErrStructTransform, err.Error())
}
if err := commandRepo.SaveRedis(&command); err != nil {

@ -19,13 +19,13 @@
</el-button>
<el-table :data="data" class="mt-5" @selection-change="handleSelectionChange">
<el-table-column type="selection" fix />
<el-table-column :label="$t('commons.table.name')" min-width="50">
<el-table-column :label="$t('commons.table.name')" min-width="50" show-overflow-tooltip>
<template #default="{ row }">
<el-input v-if="row.lineStatus === 'create' || row.lineStatus === 'edit'" v-model="row.name" />
<span v-else>{{ row.name }}</span>
</template>
</el-table-column>
<el-table-column :label="$t('terminal.quickCommand')" min-width="120">
<el-table-column :label="$t('terminal.quickCommand')" min-width="120" show-overflow-tooltip>
<template #default="{ row }">
<el-input
v-if="row.lineStatus === 'create' || row.lineStatus === 'edit'"

@ -9,7 +9,7 @@
<template #header>
<DrawerHeader :header="$t('database.databaseConnInfo')" :back="handleClose" />
</template>
<el-form @submit.prevent v-loading="loading" ref="formRef" :model="form" label-position="top">
<el-form @submit.prevent v-loading="loading" ref="formRef" :model="form" label-position="top" :rules="rules">
<el-row type="flex" justify="center">
<el-col :span="22">
<el-form-item :label="$t('database.containerConn')" v-if="form.from === 'local'">
@ -66,12 +66,7 @@
</el-form-item>
<el-divider border-style="dashed" />
<el-form-item
:label="$t('commons.login.password')"
v-if="form.from === 'local'"
:rules="Rules.paramComplexity"
prop="password"
>
<el-form-item :label="$t('commons.login.password')" v-if="form.from === 'local'" prop="password">
<el-input type="password" show-password clearable v-model="form.password">
<template #append>
<CopyButton :content="form.password" />
@ -109,7 +104,6 @@
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { Rules } from '@/global/form-rules';
import i18n from '@/lang';
import { ElForm } from 'element-plus';
import { changeRedisPassword, getDatabase } from '@/api/modules/database';
@ -135,6 +129,21 @@ const form = reactive({
database: '',
remoteIP: '',
});
const rules = reactive({
password: [{ validator: checkPassword, trigger: 'blur' }],
});
function checkPassword(rule: any, value: any, callback: any) {
if (form.password !== '') {
const reg = /^[a-zA-Z0-9]{1}[a-zA-Z0-9.%@!~_-]{4,126}[a-zA-Z0-9]{1}$/;
if (!reg.test(value) && value !== '') {
callback(new Error(i18n.global.t('commons.rule.paramComplexity', ['.%@!~_-'])));
} else {
callback();
}
}
callback();
}
const confirmDialogRef = ref();

Loading…
Cancel
Save