aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/ui/form
diff options
context:
space:
mode:
Diffstat (limited to 'server/ui/form')
-rw-r--r--server/ui/form/auth.go8
-rw-r--r--server/ui/form/category.go10
-rw-r--r--server/ui/form/feed.go8
-rw-r--r--server/ui/form/settings.go15
-rw-r--r--server/ui/form/subscription.go8
-rw-r--r--server/ui/form/user.go23
6 files changed, 49 insertions, 23 deletions
diff --git a/server/ui/form/auth.go b/server/ui/form/auth.go
index 3cfc217..6849339 100644
--- a/server/ui/form/auth.go
+++ b/server/ui/form/auth.go
@@ -5,23 +5,27 @@
package form
import (
- "errors"
"net/http"
+
+ "github.com/miniflux/miniflux2/errors"
)
+// AuthForm represents the authentication form.
type AuthForm struct {
Username string
Password string
}
+// Validate makes sure the form values are valid.
func (a AuthForm) Validate() error {
if a.Username == "" || a.Password == "" {
- return errors.New("All fields are mandatory.")
+ return errors.NewLocalizedError("All fields are mandatory.")
}
return nil
}
+// NewAuthForm returns a new AuthForm.
func NewAuthForm(r *http.Request) *AuthForm {
return &AuthForm{
Username: r.FormValue("username"),
diff --git a/server/ui/form/category.go b/server/ui/form/category.go
index 510d1b4..f977b7a 100644
--- a/server/ui/form/category.go
+++ b/server/ui/form/category.go
@@ -5,9 +5,10 @@
package form
import (
- "errors"
- "github.com/miniflux/miniflux2/model"
"net/http"
+
+ "github.com/miniflux/miniflux2/errors"
+ "github.com/miniflux/miniflux2/model"
)
// CategoryForm represents a feed form in the UI
@@ -15,18 +16,21 @@ type CategoryForm struct {
Title string
}
+// Validate makes sure the form values are valid.
func (c CategoryForm) Validate() error {
if c.Title == "" {
- return errors.New("The title is mandatory.")
+ return errors.NewLocalizedError("The title is mandatory.")
}
return nil
}
+// Merge update the given category fields.
func (c CategoryForm) Merge(category *model.Category) *model.Category {
category.Title = c.Title
return category
}
+// NewCategoryForm returns a new CategoryForm.
func NewCategoryForm(r *http.Request) *CategoryForm {
return &CategoryForm{
Title: r.FormValue("title"),
diff --git a/server/ui/form/feed.go b/server/ui/form/feed.go
index e21e6ca..8a8cf20 100644
--- a/server/ui/form/feed.go
+++ b/server/ui/form/feed.go
@@ -5,10 +5,11 @@
package form
import (
- "errors"
- "github.com/miniflux/miniflux2/model"
"net/http"
"strconv"
+
+ "github.com/miniflux/miniflux2/errors"
+ "github.com/miniflux/miniflux2/model"
)
// FeedForm represents a feed form in the UI
@@ -22,11 +23,12 @@ type FeedForm struct {
// ValidateModification validates FeedForm fields
func (f FeedForm) ValidateModification() error {
if f.FeedURL == "" || f.SiteURL == "" || f.Title == "" || f.CategoryID == 0 {
- return errors.New("All fields are mandatory.")
+ return errors.NewLocalizedError("All fields are mandatory.")
}
return nil
}
+// Merge updates the fields of the given feed.
func (f FeedForm) Merge(feed *model.Feed) *model.Feed {
feed.Category.ID = f.CategoryID
feed.Title = f.Title
diff --git a/server/ui/form/settings.go b/server/ui/form/settings.go
index 1e40b97..3d37a0f 100644
--- a/server/ui/form/settings.go
+++ b/server/ui/form/settings.go
@@ -5,11 +5,13 @@
package form
import (
- "errors"
- "github.com/miniflux/miniflux2/model"
"net/http"
+
+ "github.com/miniflux/miniflux2/errors"
+ "github.com/miniflux/miniflux2/model"
)
+// SettingsForm represents the settings form.
type SettingsForm struct {
Username string
Password string
@@ -19,6 +21,7 @@ type SettingsForm struct {
Timezone string
}
+// Merge updates the fields of the given user.
func (s *SettingsForm) Merge(user *model.User) *model.User {
user.Username = s.Username
user.Theme = s.Theme
@@ -32,24 +35,26 @@ func (s *SettingsForm) Merge(user *model.User) *model.User {
return user
}
+// Validate makes sure the form values are valid.
func (s *SettingsForm) Validate() error {
if s.Username == "" || s.Theme == "" || s.Language == "" || s.Timezone == "" {
- return errors.New("The username, theme, language and timezone fields are mandatory.")
+ return errors.NewLocalizedError("The username, theme, language and timezone fields are mandatory.")
}
if s.Password != "" {
if s.Password != s.Confirmation {
- return errors.New("Passwords are not the same.")
+ return errors.NewLocalizedError("Passwords are not the same.")
}
if len(s.Password) < 6 {
- return errors.New("You must use at least 6 characters")
+ return errors.NewLocalizedError("You must use at least 6 characters")
}
}
return nil
}
+// NewSettingsForm returns a new SettingsForm.
func NewSettingsForm(r *http.Request) *SettingsForm {
return &SettingsForm{
Username: r.FormValue("username"),
diff --git a/server/ui/form/subscription.go b/server/ui/form/subscription.go
index 6696b22..ca1c605 100644
--- a/server/ui/form/subscription.go
+++ b/server/ui/form/subscription.go
@@ -5,24 +5,28 @@
package form
import (
- "errors"
"net/http"
"strconv"
+
+ "github.com/miniflux/miniflux2/errors"
)
+// SubscriptionForm represents the subscription form.
type SubscriptionForm struct {
URL string
CategoryID int64
}
+// Validate makes sure the form values are valid.
func (s *SubscriptionForm) Validate() error {
if s.URL == "" || s.CategoryID == 0 {
- return errors.New("The URL and the category are mandatory.")
+ return errors.NewLocalizedError("The URL and the category are mandatory.")
}
return nil
}
+// NewSubscriptionForm returns a new SubscriptionForm.
func NewSubscriptionForm(r *http.Request) *SubscriptionForm {
categoryID, err := strconv.Atoi(r.FormValue("category_id"))
if err != nil {
diff --git a/server/ui/form/user.go b/server/ui/form/user.go
index 1197b48..5319cb8 100644
--- a/server/ui/form/user.go
+++ b/server/ui/form/user.go
@@ -5,11 +5,13 @@
package form
import (
- "errors"
- "github.com/miniflux/miniflux2/model"
"net/http"
+
+ "github.com/miniflux/miniflux2/errors"
+ "github.com/miniflux/miniflux2/model"
)
+// UserForm represents the user form.
type UserForm struct {
Username string
Password string
@@ -17,40 +19,43 @@ type UserForm struct {
IsAdmin bool
}
+// ValidateCreation validates user creation.
func (u UserForm) ValidateCreation() error {
if u.Username == "" || u.Password == "" || u.Confirmation == "" {
- return errors.New("All fields are mandatory.")
+ return errors.NewLocalizedError("All fields are mandatory.")
}
if u.Password != u.Confirmation {
- return errors.New("Passwords are not the same.")
+ return errors.NewLocalizedError("Passwords are not the same.")
}
if len(u.Password) < 6 {
- return errors.New("You must use at least 6 characters.")
+ return errors.NewLocalizedError("You must use at least 6 characters.")
}
return nil
}
+// ValidateModification validates user modification.
func (u UserForm) ValidateModification() error {
if u.Username == "" {
- return errors.New("The username is mandatory.")
+ return errors.NewLocalizedError("The username is mandatory.")
}
if u.Password != "" {
if u.Password != u.Confirmation {
- return errors.New("Passwords are not the same.")
+ return errors.NewLocalizedError("Passwords are not the same.")
}
if len(u.Password) < 6 {
- return errors.New("You must use at least 6 characters.")
+ return errors.NewLocalizedError("You must use at least 6 characters.")
}
}
return nil
}
+// ToUser returns a User from the form values.
func (u UserForm) ToUser() *model.User {
return &model.User{
Username: u.Username,
@@ -59,6 +64,7 @@ func (u UserForm) ToUser() *model.User {
}
}
+// Merge updates the fields of the given user.
func (u UserForm) Merge(user *model.User) *model.User {
user.Username = u.Username
user.IsAdmin = u.IsAdmin
@@ -70,6 +76,7 @@ func (u UserForm) Merge(user *model.User) *model.User {
return user
}
+// NewUserForm returns a new UserForm.
func NewUserForm(r *http.Request) *UserForm {
return &UserForm{
Username: r.FormValue("username"),