mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 01:57:19 +08:00
feat: 优化验证规则
This commit is contained in:
@@ -35,7 +35,7 @@ func (r monitorRepo) GetSetting() (*request.MonitorSetting, error) {
|
||||
|
||||
setting := new(request.MonitorSetting)
|
||||
setting.Enabled = cast.ToBool(monitor)
|
||||
setting.Days = cast.ToInt(monitorDays)
|
||||
setting.Days = cast.ToUint(monitorDays)
|
||||
|
||||
return setting, nil
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package request
|
||||
|
||||
type App struct {
|
||||
Slug string `json:"slug" form:"slug" validate:"required|not_exists:apps,slug"`
|
||||
Slug string `json:"slug" form:"slug" validate:"required|notExists:apps,slug"`
|
||||
Channel string `json:"channel" form:"channel" validate:"required"`
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,6 @@ type CertUpdate struct {
|
||||
}
|
||||
|
||||
type CertDeploy struct {
|
||||
ID uint `form:"id" json:"id" validate:"required,exists:certs,id"`
|
||||
WebsiteID uint `form:"website_id" json:"website_id" validate:"required"`
|
||||
ID uint `form:"id" json:"id" validate:"required|exists:certs,id"`
|
||||
WebsiteID uint `form:"website_id" json:"website_id" validate:"required|exists:websites,id"`
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import "github.com/TheTNB/panel/pkg/acme"
|
||||
type CertDNSCreate struct {
|
||||
Type string `form:"type" json:"type" validate:"required"`
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
Data acme.DNSParam `form:"data" json:"data"`
|
||||
Data acme.DNSParam `form:"data" json:"data" validate:"required"`
|
||||
}
|
||||
|
||||
type CertDNSUpdate struct {
|
||||
ID uint `form:"id" json:"id" validate:"required|exists:cert_dns,id"`
|
||||
Type string `form:"type" json:"type" validate:"required"`
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
Data acme.DNSParam `form:"data" json:"data"`
|
||||
Data acme.DNSParam `form:"data" json:"data" validate:"required"`
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package request
|
||||
|
||||
type ID struct {
|
||||
ID uint `json:"id" form:"id" query:"id" validate:"required|number"`
|
||||
ID uint `json:"id" form:"id" query:"id" validate:"required|min:1"`
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ type ContainerImageID struct {
|
||||
type ContainerImagePull struct {
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
Auth bool `form:"auth" json:"auth"`
|
||||
Username string `form:"username" json:"username"`
|
||||
Password string `form:"password" json:"password"`
|
||||
Username string `form:"username" json:"username" validate:"requiredIf=Auth,true"`
|
||||
Password string `form:"password" json:"password" validate:"requiredIf=Auth,true"`
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ type ContainerNetworkID struct {
|
||||
|
||||
type ContainerNetworkCreate struct {
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
Driver string `form:"driver" json:"driver"`
|
||||
Driver string `form:"driver" json:"driver" validate:"required|in:bridge,host,overlay,macvlan,ipvlan,none"`
|
||||
Ipv4 types.ContainerContainerNetwork `form:"ipv4" json:"ipv4"`
|
||||
Ipv6 types.ContainerContainerNetwork `form:"ipv6" json:"ipv6"`
|
||||
Labels []types.KV `form:"labels" json:"labels"`
|
||||
|
||||
@@ -8,7 +8,7 @@ type ContainerVolumeID struct {
|
||||
|
||||
type ContainerVolumeCreate struct {
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
Driver string `form:"driver" json:"driver"`
|
||||
Driver string `form:"driver" json:"driver" validate:"required|in:local"`
|
||||
Labels []types.KV `form:"labels" json:"labels"`
|
||||
Options []types.KV `form:"options" json:"options"`
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package request
|
||||
|
||||
type CronCreate struct {
|
||||
Name string `form:"name" json:"name" validate:"required|not_exists:crons,name"`
|
||||
Name string `form:"name" json:"name" validate:"required|notExists:crons,name"`
|
||||
Type string `form:"type" json:"type" validate:"required"`
|
||||
Time string `form:"time" json:"time" validate:"required|cron"`
|
||||
Script string `form:"script" json:"script"`
|
||||
BackupType string `form:"backup_type" json:"backup_type" validate:"required"`
|
||||
BackupType string `form:"backup_type" json:"backup_type" validate:"requiredIf=Type,backup"`
|
||||
BackupPath string `form:"backup_path" json:"backup_path"`
|
||||
Target string `form:"target" json:"target" validate:"required"`
|
||||
Save int `form:"save" json:"save" validate:"required"`
|
||||
|
||||
@@ -4,8 +4,8 @@ type DatabaseCreate struct {
|
||||
ServerID uint `form:"server_id" json:"server_id" validate:"required|exists:database_servers,id"`
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
CreateUser bool `form:"create_user" json:"create_user"`
|
||||
Username string `form:"username" json:"username" validate:"required_if:CreateUser,true"`
|
||||
Password string `form:"password" json:"password" validate:"required_if:CreateUser,true"`
|
||||
Username string `form:"username" json:"username" validate:"requiredIf:CreateUser,true"`
|
||||
Password string `form:"password" json:"password" validate:"requiredIf:CreateUser,true"`
|
||||
Host string `form:"host" json:"host"`
|
||||
Comment string `form:"comment" json:"comment"`
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package request
|
||||
|
||||
type DatabaseServerCreate struct {
|
||||
Name string `form:"name" json:"name" validate:"required|not_exists:database_servers,name"`
|
||||
Name string `form:"name" json:"name" validate:"required|notExists:database_servers,name"`
|
||||
Type string `form:"type" json:"type" validate:"required|in:mysql,postgresql,redis"`
|
||||
Host string `form:"host" json:"host" validate:"required"`
|
||||
Port uint `form:"port" json:"port" validate:"required|number|min:1|max:65535"`
|
||||
Port uint `form:"port" json:"port" validate:"required|min:1|max:65535"`
|
||||
Username string `form:"username" json:"username"`
|
||||
Password string `form:"password" json:"password"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
@@ -14,7 +14,7 @@ type DatabaseServerUpdate struct {
|
||||
ID uint `form:"id" json:"id" validate:"required|exists:database_servers,id"`
|
||||
Name string `form:"name" json:"name" validate:"required"`
|
||||
Host string `form:"host" json:"host" validate:"required"`
|
||||
Port uint `form:"port" json:"port" validate:"required|number|min:1|max:65535"`
|
||||
Port uint `form:"port" json:"port" validate:"required|min:1|max:65535"`
|
||||
Username string `form:"username" json:"username"`
|
||||
Password string `form:"password" json:"password"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
|
||||
@@ -7,55 +7,55 @@ import (
|
||||
)
|
||||
|
||||
type FileList struct {
|
||||
Path string `json:"path" form:"path" validate:"required"`
|
||||
Path string `json:"path" form:"path" validate:"required|isUnixPath"`
|
||||
Sort string `json:"sort" form:"sort"`
|
||||
}
|
||||
|
||||
type FilePath struct {
|
||||
Path string `json:"path" form:"path" validate:"required"`
|
||||
Path string `json:"path" form:"path" validate:"required|isUnixPath"`
|
||||
}
|
||||
|
||||
type FileCreate struct {
|
||||
Dir bool `json:"dir" form:"dir"`
|
||||
Path string `json:"path" form:"path" validate:"required"`
|
||||
Path string `json:"path" form:"path" validate:"required|isUnixPath"`
|
||||
}
|
||||
|
||||
type FileSave struct {
|
||||
Path string `form:"path" json:"path" validate:"required"`
|
||||
Path string `form:"path" json:"path" validate:"required|isUnixPath"`
|
||||
Content string `form:"content" json:"content"`
|
||||
}
|
||||
|
||||
type FileControl struct {
|
||||
Source string `form:"source" json:"source" validate:"required"`
|
||||
Target string `form:"target" json:"target" validate:"required"`
|
||||
Source string `form:"source" json:"source" validate:"required|isUnixPath"`
|
||||
Target string `form:"target" json:"target" validate:"required|isUnixPath"`
|
||||
Force bool `form:"force" json:"force"`
|
||||
}
|
||||
|
||||
type FileRemoteDownload struct {
|
||||
Path string `form:"path" json:"path" validate:"required"`
|
||||
URL string `form:"url" json:"url" validate:"required"`
|
||||
Path string `form:"path" json:"path" validate:"required|isUnixPath"`
|
||||
URL string `form:"url" json:"url" validate:"required|isFullURL"`
|
||||
}
|
||||
|
||||
type FilePermission struct {
|
||||
Path string `form:"path" json:"path" validate:"required"`
|
||||
Path string `form:"path" json:"path" validate:"required|isUnixPath"`
|
||||
Mode string `form:"mode" json:"mode" validate:"required"`
|
||||
Owner string `form:"owner" json:"owner" validate:"required"`
|
||||
Group string `form:"group" json:"group" validate:"required"`
|
||||
}
|
||||
|
||||
type FileCompress struct {
|
||||
Dir string `form:"dir" json:"dir" validate:"required"`
|
||||
Dir string `form:"dir" json:"dir" validate:"required|isUnixPath"`
|
||||
Paths []string `form:"paths" json:"paths" validate:"required"`
|
||||
File string `form:"file" json:"file" validate:"required"`
|
||||
File string `form:"file" json:"file" validate:"required|isUnixPath"`
|
||||
}
|
||||
|
||||
type FileUnCompress struct {
|
||||
File string `form:"file" json:"file" validate:"required"`
|
||||
Path string `form:"path" json:"path" validate:"required"`
|
||||
File string `form:"file" json:"file" validate:"required|isUnixPath"`
|
||||
Path string `form:"path" json:"path" validate:"required|isUnixPath"`
|
||||
}
|
||||
|
||||
type FileSearch struct {
|
||||
Path string `form:"path" json:"path" validate:"required"`
|
||||
Path string `form:"path" json:"path" validate:"required|isUnixPath"`
|
||||
Keyword string `form:"keyword" json:"keyword" validate:"required"`
|
||||
Sub bool `form:"sub" json:"sub"`
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ type FirewallRule struct {
|
||||
Protocol string `json:"protocol" validate:"required|in:tcp,udp,tcp/udp"`
|
||||
Address string `json:"address"`
|
||||
Strategy string `json:"strategy" validate:"required|in:accept,drop,reject"`
|
||||
Direction string `json:"direction"`
|
||||
Direction string `json:"direction" validate:"required|in:in,out"`
|
||||
}
|
||||
|
||||
type FirewallIPRule struct {
|
||||
@@ -20,7 +20,7 @@ type FirewallIPRule struct {
|
||||
Protocol string `json:"protocol" validate:"required|in:tcp,udp,tcp/udp"`
|
||||
Address string `json:"address"`
|
||||
Strategy string `json:"strategy" validate:"required|in:accept,drop,reject"`
|
||||
Direction string `json:"direction"`
|
||||
Direction string `json:"direction" validate:"required|in:in,out"`
|
||||
}
|
||||
|
||||
type FirewallForward struct {
|
||||
|
||||
@@ -2,7 +2,7 @@ package request
|
||||
|
||||
type MonitorSetting struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Days int `json:"days"`
|
||||
Days uint `json:"days"`
|
||||
}
|
||||
|
||||
type MonitorList struct {
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
)
|
||||
|
||||
type Paginate struct {
|
||||
Page uint `json:"page" form:"page" query:"page" validate:"required|number|min:1"`
|
||||
Limit uint `json:"limit" form:"limit" query:"limit" validate:"required|number|min:1|max:10000"`
|
||||
Page uint `json:"page" form:"page" query:"page" validate:"required|min:1"`
|
||||
Limit uint `json:"limit" form:"limit" query:"limit" validate:"required|min:1|max:10000"`
|
||||
}
|
||||
|
||||
func (r *Paginate) Messages(_ *http.Request) map[string]string {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package request
|
||||
|
||||
type SafeUpdateSSH struct {
|
||||
Port uint `json:"port" form:"port" validate:"number|min:1|max:65535"`
|
||||
Port uint `json:"port" form:"port" validate:"required|min:1|max:65535"`
|
||||
Status bool `json:"status" form:"status"`
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ type PanelSetting struct {
|
||||
Username string `json:"username" validate:"required"`
|
||||
Password string `json:"password" validate:"password"`
|
||||
Email string `json:"email" validate:"required"`
|
||||
Port uint `json:"port" validate:"number|min:1|max:65535"`
|
||||
Port uint `json:"port" validate:"required|min:1|max:65535"`
|
||||
HTTPS bool `json:"https"`
|
||||
Cert string `json:"cert" validate:"required"`
|
||||
Key string `json:"key" validate:"required"`
|
||||
|
||||
@@ -3,11 +3,11 @@ package request
|
||||
type SSHCreate struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Host string `json:"host" form:"host" validate:"required"`
|
||||
Port uint `json:"port" form:"port" validate:"number|min:1|max:65535"`
|
||||
Port uint `json:"port" form:"port" validate:"required|min:1|max:65535"`
|
||||
AuthMethod string `json:"auth_method" form:"auth_method" validate:"required|in:password,publickey"`
|
||||
User string `json:"user" form:"user" validate:"required_if:AuthMethod,password"`
|
||||
Password string `json:"password" form:"password" validate:"required_if:AuthMethod,password"`
|
||||
Key string `json:"key" form:"key" validate:"required_if:AuthMethod,publickey"`
|
||||
User string `json:"user" form:"user" validate:"requiredIf:AuthMethod,password"`
|
||||
Password string `json:"password" form:"password" validate:"requiredIf:AuthMethod,password"`
|
||||
Key string `json:"key" form:"key" validate:"requiredIf:AuthMethod,publickey"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ type SSHUpdate struct {
|
||||
ID uint `form:"id" json:"id" validate:"required|exists:sshes,id"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Host string `json:"host" form:"host" validate:"required"`
|
||||
Port uint `json:"port" form:"port" validate:"number|min:1|max:65535"`
|
||||
Port uint `json:"port" form:"port" validate:"required|min:1|max:65535"`
|
||||
AuthMethod string `json:"auth_method" form:"auth_method" validate:"required|in:password,publickey"`
|
||||
User string `json:"user" form:"user" validate:"required_if:AuthMethod,password"`
|
||||
Password string `json:"password" form:"password" validate:"required_if:AuthMethod,password"`
|
||||
Key string `json:"key" form:"key" validate:"required_if:AuthMethod,publickey"`
|
||||
User string `json:"user" form:"user" validate:"requiredIf:AuthMethod,password"`
|
||||
Password string `json:"password" form:"password" validate:"requiredIf:AuthMethod,password"`
|
||||
Key string `json:"key" form:"key" validate:"requiredIf:AuthMethod,publickey"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ type WebsiteDefaultConfig struct {
|
||||
}
|
||||
|
||||
type WebsiteCreate struct {
|
||||
Name string `form:"name" json:"name" validate:"required|not_exists:websites,name"`
|
||||
Name string `form:"name" json:"name" validate:"required|notExists:websites,name"`
|
||||
Listens []string `form:"listens" json:"listens" validate:"required"`
|
||||
Domains []string `form:"domains" json:"domains" validate:"required"`
|
||||
Path string `form:"path" json:"path"`
|
||||
PHP int `form:"php" json:"php"`
|
||||
DB bool `form:"db" json:"db"`
|
||||
DBType string `form:"db_type" json:"db_type" validate:"required_if:DB,true"`
|
||||
DBName string `form:"db_name" json:"db_name" validate:"required_if:DB,true"`
|
||||
DBUser string `form:"db_user" json:"db_user" validate:"required_if:DB,true"`
|
||||
DBPassword string `form:"db_password" json:"db_password" validate:"required_if:DB,true"`
|
||||
DBType string `form:"db_type" json:"db_type" validate:"requiredIf:DB,true"`
|
||||
DBName string `form:"db_name" json:"db_name" validate:"requiredIf:DB,true"`
|
||||
DBUser string `form:"db_user" json:"db_user" validate:"requiredIf:DB,true"`
|
||||
DBPassword string `form:"db_password" json:"db_password" validate:"requiredIf:DB,true"`
|
||||
Remark string `form:"remark" json:"remark"`
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ type WebsiteUpdate struct {
|
||||
Raw string `form:"raw" json:"raw"`
|
||||
Rewrite string `form:"rewrite" json:"rewrite"`
|
||||
PHP int `form:"php" json:"php"`
|
||||
SSLCertificate string `form:"ssl_certificate" json:"ssl_certificate" validate:"required_if:HTTPS,true"`
|
||||
SSLCertificateKey string `form:"ssl_certificate_key" json:"ssl_certificate_key" validate:"required_if:HTTPS,true"`
|
||||
SSLCertificate string `form:"ssl_certificate" json:"ssl_certificate" validate:"requiredIf:HTTPS,true"`
|
||||
SSLCertificateKey string `form:"ssl_certificate_key" json:"ssl_certificate_key" validate:"requiredIf:HTTPS,true"`
|
||||
}
|
||||
|
||||
type WebsiteUpdateRemark struct {
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
|
||||
// NotExists 验证一个值在某个表中的字段中不存在,支持同时判断多个字段
|
||||
// NotExists verify a value does not exist in a table field, support judging multiple fields at the same time
|
||||
// 用法:not_exists:表名称,字段名称,字段名称,字段名称
|
||||
// Usage: not_exists:table_name,field_name,field_name,field_name
|
||||
// 例子:not_exists:users,phone,email
|
||||
// Example: not_exists:users,phone,email
|
||||
// 用法:notExists:表名称,字段名称,字段名称,字段名称
|
||||
// Usage: notExists:table_name,field_name,field_name,field_name
|
||||
// 例子:notExists:users,phone,email
|
||||
// Example: notExists:users,phone,email
|
||||
type NotExists struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ import (
|
||||
|
||||
func GlobalRules(db *gorm.DB) {
|
||||
validate.AddValidators(validate.M{
|
||||
"exists": NewExists(db).Passes,
|
||||
"not_exists": NewNotExists(db).Passes,
|
||||
"password": NewPassword().Passes,
|
||||
"cron": NewCron().Passes,
|
||||
"exists": NewExists(db).Passes,
|
||||
"notExists": NewNotExists(db).Passes,
|
||||
"password": NewPassword().Passes,
|
||||
"cron": NewCron().Passes,
|
||||
})
|
||||
validate.AddGlobalMessages(map[string]string{
|
||||
"exists": "{field} 不存在",
|
||||
"not_exists": "{field} 已存在",
|
||||
"password": "密码不满足要求(8-20位,至少包含字母、数字、特殊字符中的两种)",
|
||||
"cron": "Cron 表达式不合法",
|
||||
"exists": "{field} 不存在",
|
||||
"notExists": "{field} 已存在",
|
||||
"password": "密码不满足要求(8-20位,至少包含字母、数字、特殊字符中的两种)",
|
||||
"cron": "Cron 表达式不合法",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -28,7 +28,5 @@
|
||||
"automerge": true
|
||||
}
|
||||
],
|
||||
"ignoreDeps": [
|
||||
"typescript"
|
||||
]
|
||||
"ignoreDeps": []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user