aboutsummaryrefslogtreecommitdiff
path: root/internal/validator/user.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <f@miniflux.net> 2023-10-21 19:50:29 -0700
committerGravatar Frédéric Guillot <f@miniflux.net> 2023-10-22 13:09:30 -0700
commit14e25ab9fe09b9951b38e56af2bdff7a0737b280 (patch)
tree1e466305ccf868d0253b09895af29f811a3e3393 /internal/validator/user.go
parent120aabfbcef4ef453d70861aece3b107b603a911 (diff)
downloadv2-14e25ab9fe09b9951b38e56af2bdff7a0737b280.tar.gz
v2-14e25ab9fe09b9951b38e56af2bdff7a0737b280.tar.zst
v2-14e25ab9fe09b9951b38e56af2bdff7a0737b280.zip
Refactor HTTP Client and LocalizedError packages
Diffstat (limited to 'internal/validator/user.go')
-rw-r--r--internal/validator/user.go54
1 files changed, 27 insertions, 27 deletions
diff --git a/internal/validator/user.go b/internal/validator/user.go
index edaa3fe1..8c6cc9d2 100644
--- a/internal/validator/user.go
+++ b/internal/validator/user.go
@@ -10,13 +10,13 @@ import (
)
// ValidateUserCreationWithPassword validates user creation with a password.
-func ValidateUserCreationWithPassword(store *storage.Storage, request *model.UserCreationRequest) *ValidationError {
+func ValidateUserCreationWithPassword(store *storage.Storage, request *model.UserCreationRequest) *locale.LocalizedError {
if request.Username == "" {
- return NewValidationError("error.user_mandatory_fields")
+ return locale.NewLocalizedError("error.user_mandatory_fields")
}
if store.UserExists(request.Username) {
- return NewValidationError("error.user_already_exists")
+ return locale.NewLocalizedError("error.user_already_exists")
}
if err := validatePassword(request.Password); err != nil {
@@ -27,12 +27,12 @@ func ValidateUserCreationWithPassword(store *storage.Storage, request *model.Use
}
// ValidateUserModification validates user modifications.
-func ValidateUserModification(store *storage.Storage, userID int64, changes *model.UserModificationRequest) *ValidationError {
+func ValidateUserModification(store *storage.Storage, userID int64, changes *model.UserModificationRequest) *locale.LocalizedError {
if changes.Username != nil {
if *changes.Username == "" {
- return NewValidationError("error.user_mandatory_fields")
+ return locale.NewLocalizedError("error.user_mandatory_fields")
} else if store.AnotherUserExists(userID, *changes.Username) {
- return NewValidationError("error.user_already_exists")
+ return locale.NewLocalizedError("error.user_already_exists")
}
}
@@ -105,80 +105,80 @@ func ValidateUserModification(store *storage.Storage, userID int64, changes *mod
return nil
}
-func validateReadingSpeed(readingSpeed int) *ValidationError {
+func validateReadingSpeed(readingSpeed int) *locale.LocalizedError {
if readingSpeed <= 0 {
- return NewValidationError("error.settings_reading_speed_is_positive")
+ return locale.NewLocalizedError("error.settings_reading_speed_is_positive")
}
return nil
}
-func validatePassword(password string) *ValidationError {
+func validatePassword(password string) *locale.LocalizedError {
if len(password) < 6 {
- return NewValidationError("error.password_min_length")
+ return locale.NewLocalizedError("error.password_min_length")
}
return nil
}
-func validateTheme(theme string) *ValidationError {
+func validateTheme(theme string) *locale.LocalizedError {
themes := model.Themes()
if _, found := themes[theme]; !found {
- return NewValidationError("error.invalid_theme")
+ return locale.NewLocalizedError("error.invalid_theme")
}
return nil
}
-func validateLanguage(language string) *ValidationError {
+func validateLanguage(language string) *locale.LocalizedError {
languages := locale.AvailableLanguages()
if _, found := languages[language]; !found {
- return NewValidationError("error.invalid_language")
+ return locale.NewLocalizedError("error.invalid_language")
}
return nil
}
-func validateTimezone(store *storage.Storage, timezone string) *ValidationError {
+func validateTimezone(store *storage.Storage, timezone string) *locale.LocalizedError {
timezones, err := store.Timezones()
if err != nil {
- return NewValidationError(err.Error())
+ return locale.NewLocalizedError(err.Error())
}
if _, found := timezones[timezone]; !found {
- return NewValidationError("error.invalid_timezone")
+ return locale.NewLocalizedError("error.invalid_timezone")
}
return nil
}
-func validateEntryDirection(direction string) *ValidationError {
+func validateEntryDirection(direction string) *locale.LocalizedError {
if direction != "asc" && direction != "desc" {
- return NewValidationError("error.invalid_entry_direction")
+ return locale.NewLocalizedError("error.invalid_entry_direction")
}
return nil
}
-func validateEntriesPerPage(entriesPerPage int) *ValidationError {
+func validateEntriesPerPage(entriesPerPage int) *locale.LocalizedError {
if entriesPerPage < 1 {
- return NewValidationError("error.entries_per_page_invalid")
+ return locale.NewLocalizedError("error.entries_per_page_invalid")
}
return nil
}
-func validateDisplayMode(displayMode string) *ValidationError {
+func validateDisplayMode(displayMode string) *locale.LocalizedError {
if displayMode != "fullscreen" && displayMode != "standalone" && displayMode != "minimal-ui" && displayMode != "browser" {
- return NewValidationError("error.invalid_display_mode")
+ return locale.NewLocalizedError("error.invalid_display_mode")
}
return nil
}
-func validateGestureNav(gestureNav string) *ValidationError {
+func validateGestureNav(gestureNav string) *locale.LocalizedError {
if gestureNav != "none" && gestureNav != "tap" && gestureNav != "swipe" {
- return NewValidationError("error.invalid_gesture_nav")
+ return locale.NewLocalizedError("error.invalid_gesture_nav")
}
return nil
}
-func validateDefaultHomePage(defaultHomePage string) *ValidationError {
+func validateDefaultHomePage(defaultHomePage string) *locale.LocalizedError {
defaultHomePages := model.HomePages()
if _, found := defaultHomePages[defaultHomePage]; !found {
- return NewValidationError("error.invalid_default_home_page")
+ return locale.NewLocalizedError("error.invalid_default_home_page")
}
return nil
}