mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-29 18:30:54 +00:00
refactor: form binding validation (#38832)
Make "form-fetch-action" highlight the invalid field as "error"
This commit is contained in:
+26
-26
@@ -77,7 +77,7 @@ type InstallForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *InstallForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// _____ ____ _________________ ___
|
||||
@@ -98,7 +98,7 @@ type RegisterForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *RegisterForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// IsEmailDomainAllowed validates that the email address
|
||||
@@ -120,7 +120,7 @@ type MustChangePasswordForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *MustChangePasswordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// SignInForm form for signing in with user/password
|
||||
@@ -134,7 +134,7 @@ type SignInForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *SignInForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AuthorizationForm form for authorizing oauth2 clients
|
||||
@@ -154,7 +154,7 @@ type AuthorizationForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AuthorizationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// GrantApplicationForm form for authorizing oauth2 clients
|
||||
@@ -170,7 +170,7 @@ type GrantApplicationForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *GrantApplicationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AccessTokenForm for issuing access tokens from authorization codes or refresh tokens
|
||||
@@ -189,7 +189,7 @@ type AccessTokenForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AccessTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// IntrospectTokenForm for introspecting tokens
|
||||
@@ -200,7 +200,7 @@ type IntrospectTokenForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *IntrospectTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// __________________________________________.___ _______ ________ _________
|
||||
@@ -225,7 +225,7 @@ type UpdateProfileForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *UpdateProfileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// UpdateLanguageForm form for updating profile
|
||||
@@ -236,7 +236,7 @@ type UpdateLanguageForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *UpdateLanguageForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// Avatar types
|
||||
@@ -256,7 +256,7 @@ type AvatarForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AvatarForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AddEmailForm form for adding new email
|
||||
@@ -267,7 +267,7 @@ type AddEmailForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AddEmailForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// UpdateThemeForm form for updating a users' theme
|
||||
@@ -278,7 +278,7 @@ type UpdateThemeForm struct {
|
||||
// Validate validates the field
|
||||
func (f *UpdateThemeForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// ChangePasswordForm form for changing password
|
||||
@@ -291,7 +291,7 @@ type ChangePasswordForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *ChangePasswordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AddOpenIDForm is for changing openid uri
|
||||
@@ -302,7 +302,7 @@ type AddOpenIDForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AddOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AddKeyForm form for adding SSH/GPG key
|
||||
@@ -319,7 +319,7 @@ type AddKeyForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AddKeyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// AddSecretForm for adding secrets
|
||||
@@ -332,7 +332,7 @@ type AddSecretForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *AddSecretForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
type EditVariableForm struct {
|
||||
@@ -343,7 +343,7 @@ type EditVariableForm struct {
|
||||
|
||||
func (f *EditVariableForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// NewAccessTokenForm form for creating access token
|
||||
@@ -354,7 +354,7 @@ type NewAccessTokenForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *NewAccessTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// EditOAuth2ApplicationForm form for editing oauth2 applications
|
||||
@@ -381,9 +381,9 @@ func (f *EditOAuth2ApplicationForm) Validate(req *http.Request, errs binding.Err
|
||||
ctx := context.GetValidateContext(req)
|
||||
invalidURI := DetectInvalidOAuth2ApplicationRedirectURI(util.SplitTrimSpace(f.RedirectURIs, "\n"))
|
||||
if invalidURI != "" {
|
||||
errs = middleware.ReportValidationError(errs, ctx.Data, "RedirectURIs", binding.ERR_URL, ctx.Locale.TrString("form.url_error", invalidURI))
|
||||
errs = middleware.AddValidationError(errs, "RedirectURIs", "RedirectURIs: "+ctx.Locale.TrString("form.url_error", `"`+invalidURI+`"`))
|
||||
}
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// TwoFactorAuthForm for logging in with 2FA token.
|
||||
@@ -394,7 +394,7 @@ type TwoFactorAuthForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *TwoFactorAuthForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// TwoFactorScratchAuthForm for logging in with 2FA scratch token.
|
||||
@@ -405,7 +405,7 @@ type TwoFactorScratchAuthForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *TwoFactorScratchAuthForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// WebauthnRegistrationForm for reserving an WebAuthn name
|
||||
@@ -416,7 +416,7 @@ type WebauthnRegistrationForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *WebauthnRegistrationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
// PackageSettingForm form for package settings
|
||||
@@ -428,7 +428,7 @@ type PackageSettingForm struct {
|
||||
// Validate validates the fields
|
||||
func (f *PackageSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
type BlockUserForm struct {
|
||||
@@ -439,5 +439,5 @@ type BlockUserForm struct {
|
||||
|
||||
func (f *BlockUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
|
||||
ctx := context.GetValidateContext(req)
|
||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||
return middleware.Validate(ctx, errs, f)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user