aboutsummaryrefslogtreecommitdiffhomepage
path: root/ui/form
diff options
context:
space:
mode:
Diffstat (limited to 'ui/form')
-rw-r--r--ui/form/auth.go34
-rw-r--r--ui/form/category.go38
-rw-r--r--ui/form/feed.go64
-rw-r--r--ui/form/integration.go73
-rw-r--r--ui/form/settings.go70
-rw-r--r--ui/form/subscription.go42
-rw-r--r--ui/form/user.go87
7 files changed, 408 insertions, 0 deletions
diff --git a/ui/form/auth.go b/ui/form/auth.go
new file mode 100644
index 0000000..c18a0be
--- /dev/null
+++ b/ui/form/auth.go
@@ -0,0 +1,34 @@
+// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package form
+
+import (
+ "net/http"
+
+ "github.com/miniflux/miniflux/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.NewLocalizedError("All fields are mandatory.")
+ }
+
+ return nil
+}
+
+// NewAuthForm returns a new AuthForm.
+func NewAuthForm(r *http.Request) *AuthForm {
+ return &AuthForm{
+ Username: r.FormValue("username"),
+ Password: r.FormValue("password"),
+ }
+}
diff --git a/ui/form/category.go b/ui/form/category.go
new file mode 100644
index 0000000..31b7196
--- /dev/null
+++ b/ui/form/category.go
@@ -0,0 +1,38 @@
+// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package form
+
+import (
+ "net/http"
+
+ "github.com/miniflux/miniflux/errors"
+ "github.com/miniflux/miniflux/model"
+)
+
+// CategoryForm represents a feed form in the UI
+type CategoryForm struct {
+ Title string
+}
+
+// Validate makes sure the form values are valid.
+func (c CategoryForm) Validate() error {
+ if c.Title == "" {
+ 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/ui/form/feed.go b/ui/form/feed.go
new file mode 100644
index 0000000..896a6d7
--- /dev/null
+++ b/ui/form/feed.go
@@ -0,0 +1,64 @@
+// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package form
+
+import (
+ "net/http"
+ "strconv"
+
+ "github.com/miniflux/miniflux/errors"
+ "github.com/miniflux/miniflux/model"
+)
+
+// FeedForm represents a feed form in the UI
+type FeedForm struct {
+ FeedURL string
+ SiteURL string
+ Title string
+ ScraperRules string
+ RewriteRules string
+ Crawler bool
+ CategoryID int64
+}
+
+// ValidateModification validates FeedForm fields
+func (f FeedForm) ValidateModification() error {
+ if f.FeedURL == "" || f.SiteURL == "" || f.Title == "" || f.CategoryID == 0 {
+ 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
+ feed.SiteURL = f.SiteURL
+ feed.FeedURL = f.FeedURL
+ feed.ScraperRules = f.ScraperRules
+ feed.RewriteRules = f.RewriteRules
+ feed.Crawler = f.Crawler
+ feed.ParsingErrorCount = 0
+ feed.ParsingErrorMsg = ""
+ return feed
+}
+
+// NewFeedForm parses the HTTP request and returns a FeedForm
+func NewFeedForm(r *http.Request) *FeedForm {
+ categoryID, err := strconv.Atoi(r.FormValue("category_id"))
+ if err != nil {
+ categoryID = 0
+ }
+
+ return &FeedForm{
+ FeedURL: r.FormValue("feed_url"),
+ SiteURL: r.FormValue("site_url"),
+ Title: r.FormValue("title"),
+ ScraperRules: r.FormValue("scraper_rules"),
+ RewriteRules: r.FormValue("rewrite_rules"),
+ Crawler: r.FormValue("crawler") == "1",
+ CategoryID: int64(categoryID),
+ }
+}
diff --git a/ui/form/integration.go b/ui/form/integration.go
new file mode 100644
index 0000000..8cc6d35
--- /dev/null
+++ b/ui/form/integration.go
@@ -0,0 +1,73 @@
+// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package form
+
+import (
+ "net/http"
+
+ "github.com/miniflux/miniflux/model"
+)
+
+// IntegrationForm represents user integration settings form.
+type IntegrationForm struct {
+ PinboardEnabled bool
+ PinboardToken string
+ PinboardTags string
+ PinboardMarkAsUnread bool
+ InstapaperEnabled bool
+ InstapaperUsername string
+ InstapaperPassword string
+ FeverEnabled bool
+ FeverUsername string
+ FeverPassword string
+ WallabagEnabled bool
+ WallabagURL string
+ WallabagClientID string
+ WallabagClientSecret string
+ WallabagUsername string
+ WallabagPassword string
+}
+
+// Merge copy form values to the model.
+func (i IntegrationForm) Merge(integration *model.Integration) {
+ integration.PinboardEnabled = i.PinboardEnabled
+ integration.PinboardToken = i.PinboardToken
+ integration.PinboardTags = i.PinboardTags
+ integration.PinboardMarkAsUnread = i.PinboardMarkAsUnread
+ integration.InstapaperEnabled = i.InstapaperEnabled
+ integration.InstapaperUsername = i.InstapaperUsername
+ integration.InstapaperPassword = i.InstapaperPassword
+ integration.FeverEnabled = i.FeverEnabled
+ integration.FeverUsername = i.FeverUsername
+ integration.FeverPassword = i.FeverPassword
+ integration.WallabagEnabled = i.WallabagEnabled
+ integration.WallabagURL = i.WallabagURL
+ integration.WallabagClientID = i.WallabagClientID
+ integration.WallabagClientSecret = i.WallabagClientSecret
+ integration.WallabagUsername = i.WallabagUsername
+ integration.WallabagPassword = i.WallabagPassword
+}
+
+// NewIntegrationForm returns a new AuthForm.
+func NewIntegrationForm(r *http.Request) *IntegrationForm {
+ return &IntegrationForm{
+ PinboardEnabled: r.FormValue("pinboard_enabled") == "1",
+ PinboardToken: r.FormValue("pinboard_token"),
+ PinboardTags: r.FormValue("pinboard_tags"),
+ PinboardMarkAsUnread: r.FormValue("pinboard_mark_as_unread") == "1",
+ InstapaperEnabled: r.FormValue("instapaper_enabled") == "1",
+ InstapaperUsername: r.FormValue("instapaper_username"),
+ InstapaperPassword: r.FormValue("instapaper_password"),
+ FeverEnabled: r.FormValue("fever_enabled") == "1",
+ FeverUsername: r.FormValue("fever_username"),
+ FeverPassword: r.FormValue("fever_password"),
+ WallabagEnabled: r.FormValue("wallabag_enabled") == "1",
+ WallabagURL: r.FormValue("wallabag_url"),
+ WallabagClientID: r.FormValue("wallabag_client_id"),
+ WallabagClientSecret: r.FormValue("wallabag_client_secret"),
+ WallabagUsername: r.FormValue("wallabag_username"),
+ WallabagPassword: r.FormValue("wallabag_password"),
+ }
+}
diff --git a/ui/form/settings.go b/ui/form/settings.go
new file mode 100644
index 0000000..e5f6939
--- /dev/null
+++ b/ui/form/settings.go
@@ -0,0 +1,70 @@
+// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package form
+
+import (
+ "net/http"
+
+ "github.com/miniflux/miniflux/errors"
+ "github.com/miniflux/miniflux/model"
+)
+
+// SettingsForm represents the settings form.
+type SettingsForm struct {
+ Username string
+ Password string
+ Confirmation string
+ Theme string
+ Language string
+ Timezone string
+ EntryDirection 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
+ user.Language = s.Language
+ user.Timezone = s.Timezone
+ user.EntryDirection = s.EntryDirection
+
+ if s.Password != "" {
+ user.Password = s.Password
+ }
+
+ return user
+}
+
+// Validate makes sure the form values are valid.
+func (s *SettingsForm) Validate() error {
+ if s.Username == "" || s.Theme == "" || s.Language == "" || s.Timezone == "" || s.EntryDirection == "" {
+ return errors.NewLocalizedError("The username, theme, language and timezone fields are mandatory.")
+ }
+
+ if s.Password != "" {
+ if s.Password != s.Confirmation {
+ return errors.NewLocalizedError("Passwords are not the same.")
+ }
+
+ if len(s.Password) < 6 {
+ 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"),
+ Password: r.FormValue("password"),
+ Confirmation: r.FormValue("confirmation"),
+ Theme: r.FormValue("theme"),
+ Language: r.FormValue("language"),
+ Timezone: r.FormValue("timezone"),
+ EntryDirection: r.FormValue("entry_direction"),
+ }
+}
diff --git a/ui/form/subscription.go b/ui/form/subscription.go
new file mode 100644
index 0000000..7d2caaf
--- /dev/null
+++ b/ui/form/subscription.go
@@ -0,0 +1,42 @@
+// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package form
+
+import (
+ "net/http"
+ "strconv"
+
+ "github.com/miniflux/miniflux/errors"
+)
+
+// SubscriptionForm represents the subscription form.
+type SubscriptionForm struct {
+ URL string
+ CategoryID int64
+ Crawler bool
+}
+
+// Validate makes sure the form values are valid.
+func (s *SubscriptionForm) Validate() error {
+ if s.URL == "" || s.CategoryID == 0 {
+ 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 {
+ categoryID = 0
+ }
+
+ return &SubscriptionForm{
+ URL: r.FormValue("url"),
+ Crawler: r.FormValue("crawler") == "1",
+ CategoryID: int64(categoryID),
+ }
+}
diff --git a/ui/form/user.go b/ui/form/user.go
new file mode 100644
index 0000000..8b8346e
--- /dev/null
+++ b/ui/form/user.go
@@ -0,0 +1,87 @@
+// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package form
+
+import (
+ "net/http"
+
+ "github.com/miniflux/miniflux/errors"
+ "github.com/miniflux/miniflux/model"
+)
+
+// UserForm represents the user form.
+type UserForm struct {
+ Username string
+ Password string
+ Confirmation string
+ IsAdmin bool
+}
+
+// ValidateCreation validates user creation.
+func (u UserForm) ValidateCreation() error {
+ if u.Username == "" || u.Password == "" || u.Confirmation == "" {
+ return errors.NewLocalizedError("All fields are mandatory.")
+ }
+
+ if u.Password != u.Confirmation {
+ return errors.NewLocalizedError("Passwords are not the same.")
+ }
+
+ if len(u.Password) < 6 {
+ 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.NewLocalizedError("The username is mandatory.")
+ }
+
+ if u.Password != "" {
+ if u.Password != u.Confirmation {
+ return errors.NewLocalizedError("Passwords are not the same.")
+ }
+
+ if len(u.Password) < 6 {
+ 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,
+ Password: u.Password,
+ IsAdmin: u.IsAdmin,
+ }
+}
+
+// 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
+
+ if u.Password != "" {
+ user.Password = u.Password
+ }
+
+ return user
+}
+
+// NewUserForm returns a new UserForm.
+func NewUserForm(r *http.Request) *UserForm {
+ return &UserForm{
+ Username: r.FormValue("username"),
+ Password: r.FormValue("password"),
+ Confirmation: r.FormValue("confirmation"),
+ IsAdmin: r.FormValue("is_admin") == "1",
+ }
+}