From d3ab2b94b72a83d71e081f3aad521c09a565bf94 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Thu, 23 Oct 2025 22:46:31 +0800 Subject: [PATCH] verify the username, email and nickname are valid when registering via OAuth 2.0 --- cmd/webserver.go | 1 + pkg/api/forget_passwords.go | 2 +- pkg/api/oauth2_authentications.go | 12 + pkg/errs/user.go | 4 +- pkg/models/user.go | 4 +- pkg/utils/{regexps.go => validators.go} | 9 +- .../{regexps_test.go => validators_test.go} | 221 +++++++----------- pkg/validators/nickname.go | 18 ++ pkg/validators/nickname_test.go | 28 +++ src/locales/de.json | 2 + src/locales/en.json | 2 + src/locales/es.json | 2 + src/locales/fr.json | 2 + src/locales/it.json | 2 + src/locales/ja.json | 2 + src/locales/ko.json | 2 + src/locales/nl.json | 2 + src/locales/pt_BR.json | 2 + src/locales/ru.json | 2 + src/locales/th.json | 2 + src/locales/uk.json | 2 + src/locales/vi.json | 2 + src/locales/zh_Hans.json | 2 + src/locales/zh_Hant.json | 2 + 24 files changed, 189 insertions(+), 140 deletions(-) rename pkg/utils/{regexps.go => validators.go} (92%) rename pkg/utils/{regexps_test.go => validators_test.go} (59%) create mode 100644 pkg/validators/nickname.go create mode 100644 pkg/validators/nickname_test.go diff --git a/cmd/webserver.go b/cmd/webserver.go index c50e3962..a6394fbe 100644 --- a/cmd/webserver.go +++ b/cmd/webserver.go @@ -112,6 +112,7 @@ func startWebServer(c *core.CliContext) error { _ = v.RegisterValidation("notBlank", validators.NotBlank) _ = v.RegisterValidation("validUsername", validators.ValidUsername) _ = v.RegisterValidation("validEmail", validators.ValidEmail) + _ = v.RegisterValidation("validNickname", validators.ValidNickname) _ = v.RegisterValidation("validCurrency", validators.ValidCurrency) _ = v.RegisterValidation("validHexRGBColor", validators.ValidHexRGBColor) _ = v.RegisterValidation("validAmountFilter", validators.ValidAmountFilter) diff --git a/pkg/api/forget_passwords.go b/pkg/api/forget_passwords.go index 8b1f94cf..d9a648f1 100644 --- a/pkg/api/forget_passwords.go +++ b/pkg/api/forget_passwords.go @@ -146,7 +146,7 @@ func (a *ForgetPasswordsApi) UserResetPasswordHandler(c *core.WebContext) (any, if user.Email != request.Email { log.Warnf(c, "[forget_passwords.UserResetPasswordHandler] request email not equals the user email") - return nil, errs.ErrEmptyIsInvalid + return nil, errs.ErrEmailIsInvalid } if a.users.IsPasswordEqualsUserPassword(request.Password, user) { diff --git a/pkg/api/oauth2_authentications.go b/pkg/api/oauth2_authentications.go index 5ade4a73..c4f10a0e 100644 --- a/pkg/api/oauth2_authentications.go +++ b/pkg/api/oauth2_authentications.go @@ -234,6 +234,18 @@ func (a *OAuth2AuthenticationApi) CallbackHandler(c *core.WebContext) (string, * nickName = userName } + if !utils.IsValidUsername(userName) { + return a.redirectToFailedCallbackPage(c, errs.ErrUserNameIsInvalid) + } + + if !utils.IsValidEmail(email) { + return a.redirectToFailedCallbackPage(c, errs.ErrEmailIsInvalid) + } + + if !utils.IsValidNickName(nickName) { + return a.redirectToFailedCallbackPage(c, errs.ErrNickNameIsInvalid) + } + if _, exists := locales.AllLanguages[oauth2UserInfo.LanguageCode]; exists { languageCode = oauth2UserInfo.LanguageCode } diff --git a/pkg/errs/user.go b/pkg/errs/user.go index 98a111e9..b460da9a 100644 --- a/pkg/errs/user.go +++ b/pkg/errs/user.go @@ -23,7 +23,7 @@ var ( ErrUserRegistrationNotAllowed = NewNormalError(NormalSubcategoryUser, 14, http.StatusBadRequest, "user registration not allowed") ErrUserDefaultAccountIsInvalid = NewNormalError(NormalSubcategoryUser, 15, http.StatusBadRequest, "user default account is invalid") ErrUserIsDisabled = NewNormalError(NormalSubcategoryUser, 16, http.StatusBadRequest, "user is disabled") - ErrEmptyIsInvalid = NewNormalError(NormalSubcategoryUser, 17, http.StatusBadRequest, "email is invalid") + ErrEmailIsInvalid = NewNormalError(NormalSubcategoryUser, 17, http.StatusBadRequest, "email is invalid") ErrEmailIsEmptyOrInvalid = NewNormalError(NormalSubcategoryUser, 18, http.StatusBadRequest, "email is empty or invalid") ErrNewPasswordEqualsOldInvalid = NewNormalError(NormalSubcategoryUser, 19, http.StatusBadRequest, "new password equals old password") ErrEmailIsNotVerified = NewNormalError(NormalSubcategoryUser, 20, http.StatusBadRequest, "email is not verified") @@ -39,4 +39,6 @@ var ( ErrExceedMaxUserAvatarFileSize = NewNormalError(NormalSubcategoryUser, 30, http.StatusBadRequest, "exceed the maximum size of user avatar file") ErrNotPermittedToPerformThisAction = NewNormalError(NormalSubcategoryUser, 31, http.StatusBadRequest, "not permitted to perform this action") ErrCannotLoginByPassword = NewNormalError(NormalSubcategoryUser, 32, http.StatusBadRequest, "cannot login by password") + ErrUserNameIsInvalid = NewNormalError(NormalSubcategoryUser, 33, http.StatusBadRequest, "user name is invalid") + ErrNickNameIsInvalid = NewNormalError(NormalSubcategoryUser, 34, http.StatusBadRequest, "nick name is invalid") ) diff --git a/pkg/models/user.go b/pkg/models/user.go index 54362e07..2816aa25 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -161,7 +161,7 @@ type UserLoginRequest struct { type UserRegisterRequest struct { Username string `json:"username" binding:"required,notBlank,max=32,validUsername"` Email string `json:"email" binding:"required,notBlank,max=100,validEmail"` - Nickname string `json:"nickname" binding:"required,notBlank,max=64"` + Nickname string `json:"nickname" binding:"required,notBlank,max=64,validNickname"` Password string `json:"password" binding:"required,min=6,max=128"` Language string `json:"language" binding:"required,min=2,max=16"` DefaultCurrency string `json:"defaultCurrency" binding:"required,len=3,validCurrency"` @@ -190,7 +190,7 @@ type UserResendVerifyEmailRequest struct { // UserProfileUpdateRequest represents all parameters of user updating profile request type UserProfileUpdateRequest struct { Email string `json:"email" binding:"omitempty,notBlank,max=100,validEmail"` - Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64"` + Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64,validNickname"` Password string `json:"password" binding:"omitempty,min=6,max=128"` OldPassword string `json:"oldPassword" binding:"omitempty,min=6,max=128"` DefaultAccountId int64 `json:"defaultAccountId,string" binding:"omitempty,min=1"` diff --git a/pkg/utils/regexps.go b/pkg/utils/validators.go similarity index 92% rename from pkg/utils/regexps.go rename to pkg/utils/validators.go index c9b5c087..cbb9b329 100644 --- a/pkg/utils/regexps.go +++ b/pkg/utils/validators.go @@ -16,12 +16,17 @@ var ( // IsValidUsername reports whether username is valid func IsValidUsername(username string) bool { - return usernamePattern.MatchString(username) + return len(username) <= 32 && usernamePattern.MatchString(username) } // IsValidEmail reports whether email is valid func IsValidEmail(email string) bool { - return emailPattern.MatchString(email) + return len(email) <= 100 && emailPattern.MatchString(email) +} + +// IsValidNickName reports whether user nick name is valid +func IsValidNickName(nickname string) bool { + return len(nickname) <= 64 } // IsValidHexRGBColor reports whether color is valid diff --git a/pkg/utils/regexps_test.go b/pkg/utils/validators_test.go similarity index 59% rename from pkg/utils/regexps_test.go rename to pkg/utils/validators_test.go index 8c81bc48..5b90049a 100644 --- a/pkg/utils/regexps_test.go +++ b/pkg/utils/validators_test.go @@ -8,365 +8,318 @@ import ( func TestIsValidUsername_ValidUserName(t *testing.T) { username := "foobar" - expectedValue := true actualValue := IsValidUsername(username) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) username = "--foo_bar--" - expectedValue = true actualValue = IsValidUsername(username) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) } func TestIsValidUsername_InvalidUserName(t *testing.T) { username := "foo~bar~" - expectedValue := false actualValue := IsValidUsername(username) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) + + username = "012345678901234567890123456789012" + actualValue = IsValidUsername(username) + assert.False(t, actualValue) } func TestIsValidEmail_ValidEmail(t *testing.T) { email := "foo@bar.com" - expectedValue := true actualValue := IsValidEmail(email) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) email = "foo@1.2.3.4" - expectedValue = true actualValue = IsValidEmail(email) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) email = "foo_bar@foo.bar" - expectedValue = true actualValue = IsValidEmail(email) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) } func TestIsValidEmail_InvalidEmail(t *testing.T) { email := "foo" - expectedValue := false actualValue := IsValidEmail(email) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) email = "@bar" - expectedValue = false actualValue = IsValidEmail(email) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) email = "foo@bar" - expectedValue = false actualValue = IsValidEmail(email) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) email = "foo@bar." - expectedValue = false actualValue = IsValidEmail(email) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) + + email = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@foobar.com" + actualValue = IsValidEmail(email) + assert.False(t, actualValue) +} + +func TestIsValidNickName_ValidNickName(t *testing.T) { + nickname := "0123456789012345678901234567890123456789012345678901234567890123" + actualValue := IsValidNickName(nickname) + assert.True(t, actualValue) +} + +func TestIsValidNickName_InvalidNickName(t *testing.T) { + username := "01234567890123456789012345678901234567890123456789012345678901234" + actualValue := IsValidNickName(username) + assert.False(t, actualValue) } func TestIsValidHexRGBColor_ValidHexRGBColor(t *testing.T) { color := "000000" - expectedValue := true actualValue := IsValidHexRGBColor(color) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) color = "000" - expectedValue = true actualValue = IsValidHexRGBColor(color) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) color = "e0e0e0" - expectedValue = true actualValue = IsValidHexRGBColor(color) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) color = "ffffff" - expectedValue = true actualValue = IsValidHexRGBColor(color) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) color = "FFFFFF" - expectedValue = true actualValue = IsValidHexRGBColor(color) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) } func TestIsValidHexRGBColor_InvalidHexRGBColor(t *testing.T) { color := "f" - expectedValue := false actualValue := IsValidHexRGBColor(color) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) color = "fffffff" - expectedValue = false actualValue = IsValidHexRGBColor(color) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) color = "gggggg" - expectedValue = false actualValue = IsValidHexRGBColor(color) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) color = "#ffffff" - expectedValue = false actualValue = IsValidHexRGBColor(color) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) } func TestIsValidLongDateTimeFormat_ValidLongDateTimeFormat(t *testing.T) { datetime := "2024-09-01 12:34:56" - expectedValue := true actualValue := IsValidLongDateTimeFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "2024-10-01 00:00:00" - expectedValue = true actualValue = IsValidLongDateTimeFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "9999-12-31 23:59:59" - expectedValue = true actualValue = IsValidLongDateTimeFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) } func TestIsValidLongDateTimeFormat_InvalidLongDateTimeFormat(t *testing.T) { datetime := "2024-09-01" - expectedValue := false actualValue := IsValidLongDateTimeFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) datetime = "2024-09-01 12" - expectedValue = false actualValue = IsValidLongDateTimeFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) datetime = "2024-09-01 12:34" - expectedValue = false actualValue = IsValidLongDateTimeFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) } func TestIsValidLongDateTimeWithoutSecondFormat_ValidLongDateTimeWithoutSecondFormat(t *testing.T) { datetime := "2024-09-01 12:34" - expectedValue := true actualValue := IsValidLongDateTimeWithoutSecondFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "2024-10-01 00:00" - expectedValue = true actualValue = IsValidLongDateTimeWithoutSecondFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "9999-12-31 23:59" - expectedValue = true actualValue = IsValidLongDateTimeWithoutSecondFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) } func TestIsValidLongDateTimeWithoutSecondFormat_InvalidLongDateTimeWithoutSecondFormat(t *testing.T) { datetime := "2024-09-01" - expectedValue := false actualValue := IsValidLongDateTimeWithoutSecondFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) datetime = "2024-09-01 12" - expectedValue = false actualValue = IsValidLongDateTimeWithoutSecondFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) datetime = "2024-09-01 12:34:56" - expectedValue = false actualValue = IsValidLongDateTimeWithoutSecondFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) } func TestIsValidLongDateFormat_ValidLongDateFormat(t *testing.T) { datetime := "2024-09-01" - expectedValue := true actualValue := IsValidLongDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "9999-12-31" - expectedValue = true actualValue = IsValidLongDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) } func TestIsValidLongDateFormat_InvalidLongDateFormat(t *testing.T) { datetime := "24-09-01" - expectedValue := false actualValue := IsValidLongDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) datetime = "2024-9-1" - expectedValue = false actualValue = IsValidLongDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) datetime = "2024-09-1" - expectedValue = false actualValue = IsValidLongDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) datetime = "2024-9-01" - expectedValue = false actualValue = IsValidLongDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) datetime = "2024-09-01 12" - expectedValue = false actualValue = IsValidLongDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) datetime = "2024-09-01 12:34" - expectedValue = false actualValue = IsValidLongDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) datetime = "2024-09-01 12:34:56" - expectedValue = false actualValue = IsValidLongDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.False(t, actualValue) } func TestIsValidYearMonthDayLongOrShortDateFormat_ValidFormat(t *testing.T) { datetime := "2024-09-01" - expectedValue := true actualValue := IsValidYearMonthDayLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "24-09-01" - expectedValue = true actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "2024-09-1" - expectedValue = true actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "2024-9-01" - expectedValue = true actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "2024-9-1" - expectedValue = true actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "9999-12-31" - expectedValue = true actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "2024/09/01" - expectedValue = true actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "2024.09.01" - expectedValue = true actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "2024'09.01" - expectedValue = true actualValue = IsValidYearMonthDayLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) } func TestIsValidMonthDayYearLongOrShortDateFormat_ValidFormat(t *testing.T) { datetime := "09-01-2024" - expectedValue := true actualValue := IsValidMonthDayYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "09-01-24" - expectedValue = true actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "09-1-2024" - expectedValue = true actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "9-01-2024" - expectedValue = true actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "9-1-2024" - expectedValue = true actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "12-31-9999" - expectedValue = true actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "09/01/2024" - expectedValue = true actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "09.01.2024" - expectedValue = true actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "09/01'2024" - expectedValue = true actualValue = IsValidMonthDayYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) } func TestIsValidDayMonthYearLongDateFormat_ValidLongDateFormat(t *testing.T) { datetime := "01-09-2024" - expectedValue := true actualValue := IsValidDayMonthYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "01-09-24" - expectedValue = true actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "1-09-2024" - expectedValue = true actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "01-9-2024" - expectedValue = true actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "1-9-2024" - expectedValue = true actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "31-12-9999" - expectedValue = true actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "01/09/2024" - expectedValue = true actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "01.09.2024" - expectedValue = true actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) datetime = "01/09'2024" - expectedValue = true actualValue = IsValidDayMonthYearLongOrShortDateFormat(datetime) - assert.Equal(t, expectedValue, actualValue) + assert.True(t, actualValue) } diff --git a/pkg/validators/nickname.go b/pkg/validators/nickname.go new file mode 100644 index 00000000..2684e78b --- /dev/null +++ b/pkg/validators/nickname.go @@ -0,0 +1,18 @@ +package validators + +import ( + "github.com/go-playground/validator/v10" + + "github.com/mayswind/ezbookkeeping/pkg/utils" +) + +// ValidNickname returns whether the given nick name is valid +func ValidNickname(fl validator.FieldLevel) bool { + if value, ok := fl.Field().Interface().(string); ok { + if utils.IsValidNickName(value) { + return true + } + } + + return false +} diff --git a/pkg/validators/nickname_test.go b/pkg/validators/nickname_test.go new file mode 100644 index 00000000..8cb28410 --- /dev/null +++ b/pkg/validators/nickname_test.go @@ -0,0 +1,28 @@ +package validators + +import ( + "testing" + + "github.com/go-playground/validator/v10" + "github.com/stretchr/testify/assert" +) + +func TestValidNickname(t *testing.T) { + validate := validator.New() + err := validate.RegisterValidation("validNickname", ValidNickname) + assert.Nil(t, err) + + nickname := "0123456789012345678901234567890123456789012345678901234567890123" + err = validate.Var(nickname, "validNickname") + assert.Nil(t, err) +} + +func TestInvalidNickname(t *testing.T) { + validate := validator.New() + err := validate.RegisterValidation("validNickname", ValidNickname) + assert.Nil(t, err) + + nickname := "01234567890123456789012345678901234567890123456789012345678901234" + err = validate.Var(nickname, "validNickname") + assert.NotNil(t, err) +} diff --git a/src/locales/de.json b/src/locales/de.json index c74504f4..a56bae71 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "Hochgeladener Benutzeravatar überschreitet die maximal zulässige Dateigröße", "not permitted to perform this action": "Sie sind nicht berechtigt, diese Aktion auszuführen", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "Unbefugter Zugriff", "current token is invalid": "Aktuelles Token ist ungültig", "current token is expired": "Aktuelles Token ist abgelaufen", diff --git a/src/locales/en.json b/src/locales/en.json index 29a59a0c..b3e6f089 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "The uploaded user avatar exceeds the maximum allowed file size", "not permitted to perform this action": "You are not permitted to perform this action", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "Unauthorized access", "current token is invalid": "Current token is invalid", "current token is expired": "Current token is expired", diff --git a/src/locales/es.json b/src/locales/es.json index 923bbfe0..9ac88f8b 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "El avatar de usuario subido supera el tamaño de archivo máximo permitido", "not permitted to perform this action": "No tienes permiso para realizar esta acción.", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "Acceso no autorizado", "current token is invalid": "El token actual no es válido", "current token is expired": "El token actual ha caducado", diff --git a/src/locales/fr.json b/src/locales/fr.json index 35994625..4f090853 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "L'avatar utilisateur téléchargé dépasse la taille de fichier maximale autorisée", "not permitted to perform this action": "Vous n'êtes pas autorisé à effectuer cette action", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "Accès non autorisé", "current token is invalid": "Le token actuel est invalide", "current token is expired": "Le token actuel a expiré", diff --git a/src/locales/it.json b/src/locales/it.json index e381c0c6..1cb47b64 100644 --- a/src/locales/it.json +++ b/src/locales/it.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "L'avatar utente caricato supera la dimensione massima consentita del file", "not permitted to perform this action": "Non sei autorizzato a eseguire questa azione", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "Accesso non autorizzato", "current token is invalid": "Token corrente non valido", "current token is expired": "Token corrente scaduto", diff --git a/src/locales/ja.json b/src/locales/ja.json index 9ab75fc3..5aa6c76b 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "アップロードされたユーザーアバターは最大ファイルサイズを超えています", "not permitted to perform this action": "このアクションを実行は許可されていません", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "不正アクセス", "current token is invalid": "現在のトークンは無効です", "current token is expired": "現在のトークンの有効期限が切れています", diff --git a/src/locales/ko.json b/src/locales/ko.json index 9d5146c4..2e2be30d 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "업로드된 사용자 아바타가 허용된 최대 파일 크기를 초과합니다", "not permitted to perform this action": "이 작업을 수행할 수 있는 권한이 없습니다", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "권한이 없는 접근입니다", "current token is invalid": "현재 토큰이 유효하지 않습니다", "current token is expired": "현재 토큰이 만료되었습니다", diff --git a/src/locales/nl.json b/src/locales/nl.json index 11104e52..8eae769f 100644 --- a/src/locales/nl.json +++ b/src/locales/nl.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "Geüploade avatar overschrijdt de maximaal toegestane bestandsgrootte", "not permitted to perform this action": "Je hebt geen toestemming om deze actie uit te voeren", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "Ongeautoriseerde toegang", "current token is invalid": "Huidige token is ongeldig", "current token is expired": "Huidige token is verlopen", diff --git a/src/locales/pt_BR.json b/src/locales/pt_BR.json index 686c0ffc..802b6fd3 100644 --- a/src/locales/pt_BR.json +++ b/src/locales/pt_BR.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "O avatar de usuário enviado excede o tamanho máximo permitido de arquivo", "not permitted to perform this action": "Você não tem permissão para realizar esta ação", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "Acesso não autorizado", "current token is invalid": "Token atual é inválido", "current token is expired": "Token atual está expirado", diff --git a/src/locales/ru.json b/src/locales/ru.json index 538a69f0..dacf29ed 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "Загруженный аватар пользователя превышает максимально допустимый размер файла", "not permitted to perform this action": "Вам не разрешено выполнять это действие", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "Несанкционированный доступ", "current token is invalid": "Текущий токен недействителен", "current token is expired": "Текущий токен истек", diff --git a/src/locales/th.json b/src/locales/th.json index a1c8822b..bf79a8cc 100644 --- a/src/locales/th.json +++ b/src/locales/th.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "ขนาดไฟล์รูปประจำตัวผู้ใช้เกินขนาดสูงสุดที่อนุญาต", "not permitted to perform this action": "คุณไม่ได้รับอนุญาตให้ดำเนินการนี้", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "การเข้าถึงไม่ได้รับอนุญาต", "current token is invalid": "โทเค็นปัจจุบันไม่ถูกต้อง", "current token is expired": "โทเค็นปัจจุบันหมดอายุ", diff --git a/src/locales/uk.json b/src/locales/uk.json index fd892681..b6900759 100644 --- a/src/locales/uk.json +++ b/src/locales/uk.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "Завантажений аватар перевищує максимально допустимий розмір", "not permitted to perform this action": "Вам не дозволено виконувати цю дію", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "Несанкціонований доступ", "current token is invalid": "Поточний токен недійсний", "current token is expired": "Поточний токен прострочений", diff --git a/src/locales/vi.json b/src/locales/vi.json index 70ac4ea8..9242bc11 100644 --- a/src/locales/vi.json +++ b/src/locales/vi.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "Avatar người dùng đã tải lên vượt quá kích thước tệp tối đa cho phép", "not permitted to perform this action": "Bạn không được phép thực hiện hành động này", "cannot login by password": "You cannot login by password", + "user name is invalid": "User name is invalid", + "nick name is invalid": "User nickname is invalid", "unauthorized access": "Truy cập trái phép", "current token is invalid": "Mã thông báo hiện tại không hợp lệ", "current token is expired": "Mã thông báo hiện tại đã hết hạn", diff --git a/src/locales/zh_Hans.json b/src/locales/zh_Hans.json index 439d9be0..3a18053b 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "上传的用户头像超出了允许的最大文件大小", "not permitted to perform this action": "您不能执行该操作", "cannot login by password": "您不能使用密码登录", + "user name is invalid": "用户名无效", + "nick name is invalid": "用户昵称无效", "unauthorized access": "未授权的登录", "current token is invalid": "当前认证令牌无效", "current token is expired": "当前认证令牌已过期", diff --git a/src/locales/zh_Hant.json b/src/locales/zh_Hant.json index 7f08338a..751c1e58 100644 --- a/src/locales/zh_Hant.json +++ b/src/locales/zh_Hant.json @@ -1089,6 +1089,8 @@ "exceed the maximum size of user avatar file": "上傳的使用者頭像超過允許的最大檔案大小", "not permitted to perform this action": "您不能執行該操作", "cannot login by password": "您不能使用密碼登入", + "user name is invalid": "使用者名稱無效", + "nick name is invalid": "使用者暱稱無效", "unauthorized access": "未授權的登入", "current token is invalid": "目前認證令牌無效", "current token is expired": "目前認證令牌已過期",