fix: 增加数据库密码回显

pull/81/head
ssongliu 2022-12-20 20:30:14 +08:00 committed by ssongliu
parent 8bbc286f43
commit 0e6846a266
6 changed files with 54 additions and 7 deletions

View File

@ -2,9 +2,10 @@ package v1
import ( import (
"errors" "errors"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"reflect" "reflect"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/constant"
@ -68,6 +69,20 @@ func (b *BaseApi) LoadPort(c *gin.Context) {
helper.SuccessWithData(c, port) helper.SuccessWithData(c, port)
} }
func (b *BaseApi) LoadPassword(c *gin.Context) {
key, ok := c.Params.Get("key")
if !ok {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error key in path"))
return
}
password, err := appInstallService.LoadPassword(key)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, password)
}
func (b *BaseApi) DeleteCheck(c *gin.Context) { func (b *BaseApi) DeleteCheck(c *gin.Context) {
appInstallId, err := helper.GetIntParamByKey(c, "appInstallId") appInstallId, err := helper.GetIntParamByKey(c, "appInstallId")
if err != nil { if err != nil {

View File

@ -4,8 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
@ -13,6 +11,9 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
"github.com/1Panel-dev/1Panel/backend/app/repo" "github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
@ -88,6 +89,14 @@ func (a AppInstallService) LoadPort(key string) (int64, error) {
return app.Port, nil return app.Port, nil
} }
func (a AppInstallService) LoadPassword(key string) (string, error) {
app, err := appInstallRepo.LoadBaseInfoByKey(key)
if err != nil {
return "", nil
}
return app.Password, nil
}
func (a AppInstallService) Search(req request.AppInstalledSearch) ([]response.AppInstalledDTO, error) { func (a AppInstallService) Search(req request.AppInstalledSearch) ([]response.AppInstalledDTO, error) {
var installs []model.AppInstall var installs []model.AppInstall
var err error var err error

View File

@ -23,6 +23,7 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) {
appRouter.GET("/installed/:appInstallId/versions", baseApi.GetUpdateVersions) appRouter.GET("/installed/:appInstallId/versions", baseApi.GetUpdateVersions)
appRouter.GET("/installed/check/:key", baseApi.CheckAppInstalled) appRouter.GET("/installed/check/:key", baseApi.CheckAppInstalled)
appRouter.GET("/installed/loadport/:key", baseApi.LoadPort) appRouter.GET("/installed/loadport/:key", baseApi.LoadPort)
appRouter.GET("/installed/loadpassword/:key", baseApi.LoadPassword)
appRouter.GET("/installed/delete/check/:appInstallId", baseApi.DeleteCheck) appRouter.GET("/installed/delete/check/:appInstallId", baseApi.DeleteCheck)
appRouter.POST("/installed", baseApi.SearchAppInstalled) appRouter.POST("/installed", baseApi.SearchAppInstalled)
appRouter.POST("/installed/op", baseApi.OperateInstalled) appRouter.POST("/installed/op", baseApi.OperateInstalled)

View File

@ -34,6 +34,10 @@ export const GetAppPort = (key: string) => {
return http.get<number>(`apps/installed/loadport/${key}`); return http.get<number>(`apps/installed/loadport/${key}`);
}; };
export const GetAppPassword = (key: string) => {
return http.get<string>(`apps/installed/loadpassword/${key}`);
};
export const CheckAppInstalled = (key: string) => { export const CheckAppInstalled = (key: string) => {
return http.get<App.CheckInstalled>(`apps/installed/check/${key}`); return http.get<App.CheckInstalled>(`apps/installed/check/${key}`);
}; };

View File

@ -15,8 +15,10 @@
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="dialogVisiable = false">{{ $t('commons.button.cancel') }}</el-button> <el-button :disabled="loading" @click="dialogVisiable = false">
<el-button type="primary" @click="onSave(formRef)"> {{ $t('commons.button.cancel') }}
</el-button>
<el-button :disabled="loading" type="primary" @click="onSave(formRef)">
{{ $t('commons.button.confirm') }} {{ $t('commons.button.confirm') }}
</el-button> </el-button>
</span> </span>
@ -31,6 +33,7 @@ import i18n from '@/lang';
import { ElForm, ElMessage } from 'element-plus'; import { ElForm, ElMessage } from 'element-plus';
import { updateMysqlPassword } from '@/api/modules/database'; import { updateMysqlPassword } from '@/api/modules/database';
import ConfirmDialog from '@/components/confirm-dialog/index.vue'; import ConfirmDialog from '@/components/confirm-dialog/index.vue';
import { GetAppPassword } from '@/api/modules/app';
const loading = ref(false); const loading = ref(false);
@ -46,9 +49,15 @@ const formRef = ref<FormInstance>();
const acceptParams = (): void => { const acceptParams = (): void => {
form.password = ''; form.password = '';
loadPassword();
dialogVisiable.value = true; dialogVisiable.value = true;
}; };
const loadPassword = async () => {
const res = await GetAppPassword('mysql');
form.password = res.data;
};
const onSubmit = async () => { const onSubmit = async () => {
let param = { let param = {
id: 0, id: 0,

View File

@ -15,8 +15,10 @@
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="dialogVisiable = false">{{ $t('commons.button.cancel') }}</el-button> <el-button :disabled="loading" @click="dialogVisiable = false">
<el-button type="primary" @click="onSave(formRef)"> {{ $t('commons.button.cancel') }}
</el-button>
<el-button :disabled="loading" type="primary" @click="onSave(formRef)">
{{ $t('commons.button.confirm') }} {{ $t('commons.button.confirm') }}
</el-button> </el-button>
</span> </span>
@ -31,6 +33,7 @@ import i18n from '@/lang';
import { ElForm, ElMessage } from 'element-plus'; import { ElForm, ElMessage } from 'element-plus';
import { changeRedisPassword } from '@/api/modules/database'; import { changeRedisPassword } from '@/api/modules/database';
import ConfirmDialog from '@/components/confirm-dialog/index.vue'; import ConfirmDialog from '@/components/confirm-dialog/index.vue';
import { GetAppPassword } from '@/api/modules/app';
const loading = ref(false); const loading = ref(false);
@ -48,9 +51,15 @@ const formRef = ref<FormInstance>();
const acceptParams = (): void => { const acceptParams = (): void => {
form.password = ''; form.password = '';
loadPassword();
dialogVisiable.value = true; dialogVisiable.value = true;
}; };
const loadPassword = async () => {
const res = await GetAppPassword('redis');
form.password = res.data;
};
const onSubmit = async () => { const onSubmit = async () => {
let param = { let param = {
id: 0, id: 0,