mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 02:45:49 +02:00
enhance: show the form error details of CertificateEditor
This commit is contained in:
parent
8581bdd3c6
commit
b0a3989ef4
4 changed files with 166 additions and 128 deletions
|
@ -76,9 +76,9 @@ func GetCert(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type certJson struct {
|
type certJson struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name" binding:"required"`
|
||||||
SSLCertificatePath string `json:"ssl_certificate_path" binding:"publickey_path"`
|
SSLCertificatePath string `json:"ssl_certificate_path" binding:"required,publickey_path"`
|
||||||
SSLCertificateKeyPath string `json:"ssl_certificate_key_path" binding:"privatekey_path"`
|
SSLCertificateKeyPath string `json:"ssl_certificate_key_path" binding:"required,privatekey_path"`
|
||||||
SSLCertificate string `json:"ssl_certificate" binding:"omitempty,publickey"`
|
SSLCertificate string `json:"ssl_certificate" binding:"omitempty,publickey"`
|
||||||
SSLCertificateKey string `json:"ssl_certificate_key" binding:"omitempty,privatekey"`
|
SSLCertificateKey string `json:"ssl_certificate_key" binding:"omitempty,privatekey"`
|
||||||
ChallengeMethod string `json:"challenge_method"`
|
ChallengeMethod string `json:"challenge_method"`
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nginx-ui-app-next",
|
"name": "nginx-ui-app-next",
|
||||||
"version": "2.0.0-beta.11",
|
"version": "2.0.0-beta.12",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|
|
@ -41,12 +41,15 @@ onMounted(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const errors = ref({}) as Ref<Record<string, string>>
|
||||||
function save() {
|
function save() {
|
||||||
cert.save(data.value.id, data.value).then(r => {
|
cert.save(data.value.id, data.value).then(r => {
|
||||||
data.value = r
|
data.value = r
|
||||||
message.success($gettext('Save successfully'))
|
message.success($gettext('Save successfully'))
|
||||||
router.push(`/certificates/${r.id}`)
|
router.push(`/certificates/${r.id}`)
|
||||||
|
errors.value = {}
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
|
errors.value = e.errors
|
||||||
message.error($gettext(e?.message ?? 'Server error'))
|
message.error($gettext(e?.message ?? 'Server error'))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -142,7 +145,13 @@ const isManaged = computed(() => {
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
style="max-width: 600px"
|
style="max-width: 600px"
|
||||||
>
|
>
|
||||||
<AFormItem :label="$gettext('Name')">
|
<AFormItem
|
||||||
|
:label="$gettext('Name')"
|
||||||
|
:validate-status="errors.name ? 'error' : ''"
|
||||||
|
:help="errors.name === 'required'
|
||||||
|
? $gettext('This field is required')
|
||||||
|
: ''"
|
||||||
|
>
|
||||||
<p v-if="isManaged">
|
<p v-if="isManaged">
|
||||||
{{ data.name }}
|
{{ data.name }}
|
||||||
</p>
|
</p>
|
||||||
|
@ -151,7 +160,13 @@ const isManaged = computed(() => {
|
||||||
v-model:value="data.name"
|
v-model:value="data.name"
|
||||||
/>
|
/>
|
||||||
</AFormItem>
|
</AFormItem>
|
||||||
<AFormItem :label="$gettext('SSL Certificate Path')">
|
<AFormItem
|
||||||
|
:label="$gettext('SSL Certificate Path')"
|
||||||
|
:validate-status="errors.ssl_certificate_path ? 'error' : ''"
|
||||||
|
:help="errors.ssl_certificate_path === 'required' ? $gettext('This field is required')
|
||||||
|
: errors.ssl_certificate_path === 'publickey_path'
|
||||||
|
? $gettext('The path exists, but the file is not a public key') : ''"
|
||||||
|
>
|
||||||
<p v-if="isManaged">
|
<p v-if="isManaged">
|
||||||
{{ data.ssl_certificate_path }}
|
{{ data.ssl_certificate_path }}
|
||||||
</p>
|
</p>
|
||||||
|
@ -160,7 +175,13 @@ const isManaged = computed(() => {
|
||||||
v-model:value="data.ssl_certificate_path"
|
v-model:value="data.ssl_certificate_path"
|
||||||
/>
|
/>
|
||||||
</AFormItem>
|
</AFormItem>
|
||||||
<AFormItem :label="$gettext('SSL Certificate Key Path')">
|
<AFormItem
|
||||||
|
:label="$gettext('SSL Certificate Key Path')"
|
||||||
|
:validate-status="errors.ssl_certificate_key_path ? 'error' : ''"
|
||||||
|
:help="errors.ssl_certificate_key_path === 'required' ? $gettext('This field is required')
|
||||||
|
: errors.ssl_certificate_key_path === 'privatekey_path'
|
||||||
|
? $gettext('The path exists, but the file is not a private key') : ''"
|
||||||
|
>
|
||||||
<p v-if="isManaged">
|
<p v-if="isManaged">
|
||||||
{{ data.ssl_certificate_key_path }}
|
{{ data.ssl_certificate_key_path }}
|
||||||
</p>
|
</p>
|
||||||
|
@ -169,7 +190,12 @@ const isManaged = computed(() => {
|
||||||
v-model:value="data.ssl_certificate_key_path"
|
v-model:value="data.ssl_certificate_key_path"
|
||||||
/>
|
/>
|
||||||
</AFormItem>
|
</AFormItem>
|
||||||
<AFormItem :label="$gettext('SSL Certificate Content')">
|
<AFormItem
|
||||||
|
:label="$gettext('SSL Certificate Content')"
|
||||||
|
:validate-status="errors.ssl_certificate ? 'error' : ''"
|
||||||
|
:help="errors.ssl_certificate === 'publickey'
|
||||||
|
? $gettext('The input is not a SSL Certificate') : ''"
|
||||||
|
>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
v-model:content="data.ssl_certificate"
|
v-model:content="data.ssl_certificate"
|
||||||
default-height="300px"
|
default-height="300px"
|
||||||
|
@ -177,7 +203,12 @@ const isManaged = computed(() => {
|
||||||
:placeholder="$gettext('Leave blank will not change anything')"
|
:placeholder="$gettext('Leave blank will not change anything')"
|
||||||
/>
|
/>
|
||||||
</AFormItem>
|
</AFormItem>
|
||||||
<AFormItem :label="$gettext('SSL Certificate Key Content')">
|
<AFormItem
|
||||||
|
:label="$gettext('SSL Certificate Key Content')"
|
||||||
|
:validate-status="errors.ssl_certificate_key ? 'error' : ''"
|
||||||
|
:help="errors.ssl_certificate_key === 'privatekey'
|
||||||
|
? $gettext('The input is not a SSL Certificate Key') : ''"
|
||||||
|
>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
v-model:content="data.ssl_certificate_key"
|
v-model:content="data.ssl_certificate_key"
|
||||||
default-height="300px"
|
default-height="300px"
|
||||||
|
|
|
@ -33,6 +33,9 @@ func IsPrivateKey(pemStr string) bool {
|
||||||
|
|
||||||
// IsPublicKeyPath checks if the file at the given path is a public key or not exists.
|
// IsPublicKeyPath checks if the file at the given path is a public key or not exists.
|
||||||
func IsPublicKeyPath(path string) bool {
|
func IsPublicKeyPath(path string) bool {
|
||||||
|
if path == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -52,6 +55,10 @@ func IsPublicKeyPath(path string) bool {
|
||||||
|
|
||||||
// IsPrivateKeyPath checks if the file at the given path is a private key or not exists.
|
// IsPrivateKeyPath checks if the file at the given path is a private key or not exists.
|
||||||
func IsPrivateKeyPath(path string) bool {
|
func IsPrivateKeyPath(path string) bool {
|
||||||
|
if path == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue