mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 01:34:24 +08:00
modify name
This commit is contained in:
+1
-1
@@ -74,7 +74,7 @@ func startWebServer(c *cli.Context) error {
|
|||||||
_ = v.RegisterValidation("validUsername", validators.ValidUsername)
|
_ = v.RegisterValidation("validUsername", validators.ValidUsername)
|
||||||
_ = v.RegisterValidation("validEmail", validators.ValidEmail)
|
_ = v.RegisterValidation("validEmail", validators.ValidEmail)
|
||||||
_ = v.RegisterValidation("validCurrency", validators.ValidCurrency)
|
_ = v.RegisterValidation("validCurrency", validators.ValidCurrency)
|
||||||
_ = v.RegisterValidation("validRGBColor", validators.ValidRGBColor)
|
_ = v.RegisterValidation("validHexRGBColor", validators.ValidHexRGBColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
router.NoRoute(bindApi(api.Default.ApiNotFound))
|
router.NoRoute(bindApi(api.Default.ApiNotFound))
|
||||||
|
|||||||
@@ -48,3 +48,7 @@ func GetParameterInvalidEmailMessage(field string) string {
|
|||||||
func GetParameterInvalidCurrencyMessage(field string) string {
|
func GetParameterInvalidCurrencyMessage(field string) string {
|
||||||
return fmt.Sprintf("parameter \"%s\" is invalid currency", field)
|
return fmt.Sprintf("parameter \"%s\" is invalid currency", field)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetParameterInvalidHexRGBColorMessage(field string) string {
|
||||||
|
return fmt.Sprintf("parameter \"%s\" is invalid color", field)
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ type AccountCreateRequest struct {
|
|||||||
Category AccountCategory `json:"category" binding:"required"`
|
Category AccountCategory `json:"category" binding:"required"`
|
||||||
Type AccountType `json:"type" binding:"required"`
|
Type AccountType `json:"type" binding:"required"`
|
||||||
Icon int64 `json:"icon,string" binding:"required,min=1"`
|
Icon int64 `json:"icon,string" binding:"required,min=1"`
|
||||||
Color string `json:"color" binding:"required,len=6,validRGBColor"`
|
Color string `json:"color" binding:"required,len=6,validHexRGBColor"`
|
||||||
Currency string `json:"currency" binding:"required,len=3,validCurrency"`
|
Currency string `json:"currency" binding:"required,len=3,validCurrency"`
|
||||||
Comment string `json:"comment" binding:"max=255"`
|
Comment string `json:"comment" binding:"max=255"`
|
||||||
SubAccounts []*AccountCreateRequest `json:"subAccounts" binding:"omitempty"`
|
SubAccounts []*AccountCreateRequest `json:"subAccounts" binding:"omitempty"`
|
||||||
@@ -62,7 +62,7 @@ type AccountModifyRequest struct {
|
|||||||
Name string `json:"name" binding:"required,notBlank,max=32"`
|
Name string `json:"name" binding:"required,notBlank,max=32"`
|
||||||
Category AccountCategory `json:"category" binding:"required"`
|
Category AccountCategory `json:"category" binding:"required"`
|
||||||
Icon int64 `json:"icon,string" binding:"min=1"`
|
Icon int64 `json:"icon,string" binding:"min=1"`
|
||||||
Color string `json:"color" binding:"required,len=6,validRGBColor"`
|
Color string `json:"color" binding:"required,len=6,validHexRGBColor"`
|
||||||
Comment string `json:"comment" binding:"max=255"`
|
Comment string `json:"comment" binding:"max=255"`
|
||||||
Hidden bool `json:"hidden"`
|
Hidden bool `json:"hidden"`
|
||||||
SubAccounts []*AccountModifyRequest `json:"subAccounts" binding:"omitempty"`
|
SubAccounts []*AccountModifyRequest `json:"subAccounts" binding:"omitempty"`
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ func getValidationErrorText(err validator.FieldError) string {
|
|||||||
return errs.GetParameterInvalidEmailMessage(fieldName)
|
return errs.GetParameterInvalidEmailMessage(fieldName)
|
||||||
case "validCurrency":
|
case "validCurrency":
|
||||||
return errs.GetParameterInvalidCurrencyMessage(fieldName)
|
return errs.GetParameterInvalidCurrencyMessage(fieldName)
|
||||||
|
case "validHexRGBColor":
|
||||||
|
return errs.GetParameterInvalidHexRGBColorMessage(fieldName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return errs.GetParameterInvalidMessage(fieldName)
|
return errs.GetParameterInvalidMessage(fieldName)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import "regexp"
|
|||||||
var (
|
var (
|
||||||
UsernamePattern = regexp.MustCompile("^(?i)[a-z0-9_-]+$")
|
UsernamePattern = regexp.MustCompile("^(?i)[a-z0-9_-]+$")
|
||||||
EmailPattern = regexp.MustCompile("^(?i)(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")
|
EmailPattern = regexp.MustCompile("^(?i)(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$")
|
||||||
RGBColorPattern = regexp.MustCompile("^(?i)([0-9a-f]{6}|[0-9a-f]{3})$")
|
HexRGBColorPattern = regexp.MustCompile("^(?i)([0-9a-f]{6}|[0-9a-f]{3})$")
|
||||||
)
|
)
|
||||||
|
|
||||||
func IsValidUsername(username string) bool {
|
func IsValidUsername(username string) bool {
|
||||||
@@ -16,6 +16,6 @@ func IsValidEmail(email string) bool {
|
|||||||
return EmailPattern.MatchString(email)
|
return EmailPattern.MatchString(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsValidRGBColor(color string) bool {
|
func IsValidHexRGBColor(color string) bool {
|
||||||
return RGBColorPattern.MatchString(color)
|
return HexRGBColorPattern.MatchString(color)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"github.com/mayswind/lab/pkg/utils"
|
"github.com/mayswind/lab/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ValidRGBColor(fl validator.FieldLevel) bool {
|
func ValidHexRGBColor(fl validator.FieldLevel) bool {
|
||||||
if value, ok := fl.Field().Interface().(string); ok {
|
if value, ok := fl.Field().Interface().(string); ok {
|
||||||
if utils.IsValidRGBColor(value) {
|
if utils.IsValidHexRGBColor(value) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,14 @@ const parameterizedErrors = [
|
|||||||
field: 'parameter',
|
field: 'parameter',
|
||||||
localized: true
|
localized: true
|
||||||
}]
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
localeKey: 'parameter invalid color',
|
||||||
|
regex: /^parameter "(\w+)" is invalid color$/,
|
||||||
|
parameters: [{
|
||||||
|
field: 'parameter',
|
||||||
|
localized: true
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ export default {
|
|||||||
'parameter invalid username format': '{parameter} is invalid format',
|
'parameter invalid username format': '{parameter} is invalid format',
|
||||||
'parameter invalid email format': '{parameter} is invalid format',
|
'parameter invalid email format': '{parameter} is invalid format',
|
||||||
'parameter invalid currency': '{parameter} is invalid format',
|
'parameter invalid currency': '{parameter} is invalid format',
|
||||||
|
'parameter invalid color': '{parameter} is invalid format',
|
||||||
},
|
},
|
||||||
'OK': 'OK',
|
'OK': 'OK',
|
||||||
'Cancel': 'Cancel',
|
'Cancel': 'Cancel',
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ export default {
|
|||||||
'parameter invalid username format': '{parameter}格式错误',
|
'parameter invalid username format': '{parameter}格式错误',
|
||||||
'parameter invalid email format': '{parameter}格式错误',
|
'parameter invalid email format': '{parameter}格式错误',
|
||||||
'parameter invalid currency': '{parameter}格式错误',
|
'parameter invalid currency': '{parameter}格式错误',
|
||||||
|
'parameter invalid color': '{parameter}格式错误',
|
||||||
},
|
},
|
||||||
'OK': '确定',
|
'OK': '确定',
|
||||||
'Cancel': '取消',
|
'Cancel': '取消',
|
||||||
|
|||||||
Reference in New Issue
Block a user