mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Make sure golint pass on the code base
This commit is contained in:
parent
8781648af9
commit
bb8e61c7c5
59 changed files with 322 additions and 171 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/miniflux/miniflux2/version"
|
||||
)
|
||||
|
||||
// AboutPage shows the about page.
|
||||
func (c *Controller) AboutPage(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
args, err := c.getCommonTemplateArgs(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -22,7 +22,7 @@ func (c *Controller) ShowCategories(ctx *core.Context, request *core.Request, re
|
|||
}
|
||||
|
||||
user := ctx.LoggedUser()
|
||||
categories, err := c.store.GetCategoriesWithFeedCount(user.ID)
|
||||
categories, err := c.store.CategoriesWithFeedCount(user.ID)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return
|
||||
|
@ -57,7 +57,7 @@ func (c *Controller) ShowCategoryEntries(ctx *core.Context, request *core.Reques
|
|||
builder.WithDirection(model.DefaultSortingDirection)
|
||||
builder.WithoutStatus(model.EntryStatusRemoved)
|
||||
builder.WithOffset(offset)
|
||||
builder.WithLimit(NbItemsPerPage)
|
||||
builder.WithLimit(nbItemsPerPage)
|
||||
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
|
@ -110,7 +110,7 @@ func (c *Controller) SaveCategory(ctx *core.Context, request *core.Request, resp
|
|||
return
|
||||
}
|
||||
|
||||
duplicateCategory, err := c.store.GetCategoryByTitle(user.ID, categoryForm.Title)
|
||||
duplicateCategory, err := c.store.CategoryByTitle(user.ID, categoryForm.Title)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return
|
||||
|
@ -223,7 +223,7 @@ func (c *Controller) getCategoryFromURL(ctx *core.Context, request *core.Request
|
|||
}
|
||||
|
||||
user := ctx.LoggedUser()
|
||||
category, err := c.store.GetCategory(user.ID, categoryID)
|
||||
category, err := c.store.Category(user.ID, categoryID)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return nil, err
|
||||
|
|
|
@ -39,7 +39,7 @@ func (c *Controller) ShowFeedsPage(ctx *core.Context, request *core.Request, res
|
|||
return
|
||||
}
|
||||
|
||||
feeds, err := c.store.GetFeeds(user.ID)
|
||||
feeds, err := c.store.Feeds(user.ID)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return
|
||||
|
@ -74,7 +74,7 @@ func (c *Controller) ShowFeedEntries(ctx *core.Context, request *core.Request, r
|
|||
builder.WithOrder(model.DefaultSortingOrder)
|
||||
builder.WithDirection(model.DefaultSortingDirection)
|
||||
builder.WithOffset(offset)
|
||||
builder.WithLimit(NbItemsPerPage)
|
||||
builder.WithLimit(nbItemsPerPage)
|
||||
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
|
@ -190,7 +190,7 @@ func (c *Controller) getFeedFromURL(request *core.Request, response *core.Respon
|
|||
return nil, err
|
||||
}
|
||||
|
||||
feed, err := c.store.GetFeedById(user.ID, feedID)
|
||||
feed, err := c.store.FeedByID(user.ID, feedID)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return nil, err
|
||||
|
@ -210,7 +210,7 @@ func (c *Controller) getFeedFormTemplateArgs(ctx *core.Context, user *model.User
|
|||
return nil, err
|
||||
}
|
||||
|
||||
categories, err := c.store.GetCategories(user.ID)
|
||||
categories, err := c.store.Categories(user.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func (c *Controller) ShowHistoryPage(ctx *core.Context, request *core.Request, r
|
|||
builder.WithOrder(model.DefaultSortingOrder)
|
||||
builder.WithDirection(model.DefaultSortingDirection)
|
||||
builder.WithOffset(offset)
|
||||
builder.WithLimit(NbItemsPerPage)
|
||||
builder.WithLimit(nbItemsPerPage)
|
||||
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
)
|
||||
|
||||
// ShowIcon shows the feed icon.
|
||||
func (c *Controller) ShowIcon(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
iconID, err := request.IntegerParam("iconID")
|
||||
if err != nil {
|
||||
|
@ -16,7 +18,7 @@ func (c *Controller) ShowIcon(ctx *core.Context, request *core.Request, response
|
|||
return
|
||||
}
|
||||
|
||||
icon, err := c.store.GetIconByID(iconID)
|
||||
icon, err := c.store.IconByID(iconID)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return
|
||||
|
|
|
@ -82,7 +82,7 @@ func (c *Controller) OAuth2Callback(ctx *core.Context, request *core.Request, re
|
|||
return
|
||||
}
|
||||
|
||||
user, err := c.store.GetUserByExtraField(profile.Key, profile.ID)
|
||||
user, err := c.store.UserByExtraField(profile.Key, profile.ID)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/miniflux/miniflux2/server/core"
|
||||
)
|
||||
|
||||
// Export generates the OPML file.
|
||||
func (c *Controller) Export(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
opml, err := c.opmlHandler.Export(user.ID)
|
||||
|
@ -21,6 +22,7 @@ func (c *Controller) Export(ctx *core.Context, request *core.Request, response *
|
|||
response.XML().Download("feeds.opml", opml)
|
||||
}
|
||||
|
||||
// Import shows the import form.
|
||||
func (c *Controller) Import(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
args, err := c.getCommonTemplateArgs(ctx)
|
||||
if err != nil {
|
||||
|
@ -33,6 +35,7 @@ func (c *Controller) Import(ctx *core.Context, request *core.Request, response *
|
|||
}))
|
||||
}
|
||||
|
||||
// UploadOPML handles OPML file importation.
|
||||
func (c *Controller) UploadOPML(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
file, fileHeader, err := request.File("file")
|
||||
if err != nil {
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
package controller
|
||||
|
||||
const (
|
||||
NbItemsPerPage = 100
|
||||
nbItemsPerPage = 100
|
||||
)
|
||||
|
||||
type Pagination struct {
|
||||
type pagination struct {
|
||||
Route string
|
||||
Total int
|
||||
Offset int
|
||||
|
@ -19,25 +19,25 @@ type Pagination struct {
|
|||
PrevOffset int
|
||||
}
|
||||
|
||||
func (c *Controller) getPagination(route string, total, offset int) Pagination {
|
||||
func (c *Controller) getPagination(route string, total, offset int) pagination {
|
||||
nextOffset := 0
|
||||
prevOffset := 0
|
||||
showNext := (total - offset) > NbItemsPerPage
|
||||
showNext := (total - offset) > nbItemsPerPage
|
||||
showPrev := offset > 0
|
||||
|
||||
if showNext {
|
||||
nextOffset = offset + NbItemsPerPage
|
||||
nextOffset = offset + nbItemsPerPage
|
||||
}
|
||||
|
||||
if showPrev {
|
||||
prevOffset = offset - NbItemsPerPage
|
||||
prevOffset = offset - nbItemsPerPage
|
||||
}
|
||||
|
||||
return Pagination{
|
||||
return pagination{
|
||||
Route: route,
|
||||
Total: total,
|
||||
Offset: offset,
|
||||
ItemsPerPage: NbItemsPerPage,
|
||||
ItemsPerPage: nbItemsPerPage,
|
||||
ShowNext: showNext,
|
||||
NextOffset: nextOffset,
|
||||
ShowPrev: showPrev,
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
"log"
|
||||
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
)
|
||||
|
||||
// ShowSessions shows the list of active sessions.
|
||||
func (c *Controller) ShowSessions(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
args, err := c.getCommonTemplateArgs(ctx)
|
||||
|
@ -17,7 +19,7 @@ func (c *Controller) ShowSessions(ctx *core.Context, request *core.Request, resp
|
|||
return
|
||||
}
|
||||
|
||||
sessions, err := c.store.GetSessions(user.ID)
|
||||
sessions, err := c.store.Sessions(user.ID)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return
|
||||
|
@ -31,6 +33,7 @@ func (c *Controller) ShowSessions(ctx *core.Context, request *core.Request, resp
|
|||
}))
|
||||
}
|
||||
|
||||
// RemoveSession remove a session.
|
||||
func (c *Controller) RemoveSession(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
|
||||
|
|
|
@ -5,13 +5,15 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/miniflux/miniflux2/locale"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
"github.com/miniflux/miniflux2/server/ui/form"
|
||||
"log"
|
||||
)
|
||||
|
||||
// ShowSettings shows the settings page.
|
||||
func (c *Controller) ShowSettings(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
|
||||
|
@ -24,6 +26,7 @@ func (c *Controller) ShowSettings(ctx *core.Context, request *core.Request, resp
|
|||
response.HTML().Render("settings", args)
|
||||
}
|
||||
|
||||
// UpdateSettings update the settings.
|
||||
func (c *Controller) UpdateSettings(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
|
||||
|
@ -81,9 +84,9 @@ func (c *Controller) getSettingsFormTemplateArgs(ctx *core.Context, user *model.
|
|||
}
|
||||
|
||||
args["menu"] = "settings"
|
||||
args["themes"] = model.GetThemes()
|
||||
args["languages"] = locale.GetAvailableLanguages()
|
||||
args["timezones"], err = c.store.GetTimezones()
|
||||
args["themes"] = model.Themes()
|
||||
args["languages"] = locale.AvailableLanguages()
|
||||
args["timezones"], err = c.store.Timezones()
|
||||
if err != nil {
|
||||
return args, err
|
||||
}
|
||||
|
|
|
@ -6,12 +6,14 @@ package controller
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
"github.com/miniflux/miniflux2/server/static"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
"github.com/miniflux/miniflux2/server/static"
|
||||
)
|
||||
|
||||
// Stylesheet renders the CSS.
|
||||
func (c *Controller) Stylesheet(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
stylesheet := request.StringParam("name", "white")
|
||||
body := static.Stylesheets["common"]
|
||||
|
@ -25,10 +27,12 @@ func (c *Controller) Stylesheet(ctx *core.Context, request *core.Request, respon
|
|||
response.Cache("text/css", etag, []byte(body), 48*time.Hour)
|
||||
}
|
||||
|
||||
// Javascript renders application client side code.
|
||||
func (c *Controller) Javascript(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
response.Cache("text/javascript", static.JavascriptChecksums["app"], []byte(static.Javascript["app"]), 48*time.Hour)
|
||||
}
|
||||
|
||||
// Favicon renders the application favicon.
|
||||
func (c *Controller) Favicon(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
blob, err := base64.StdEncoding.DecodeString(static.Binaries["favicon.ico"])
|
||||
if err != nil {
|
||||
|
|
|
@ -135,7 +135,7 @@ func (c *Controller) getSubscriptionFormTemplateArgs(ctx *core.Context, user *mo
|
|||
return nil, err
|
||||
}
|
||||
|
||||
categories, err := c.store.GetCategories(user.ID)
|
||||
categories, err := c.store.Categories(user.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func (c *Controller) ShowUnreadPage(ctx *core.Context, request *core.Request, re
|
|||
builder.WithOrder(model.DefaultSortingOrder)
|
||||
builder.WithDirection(model.DefaultSortingDirection)
|
||||
builder.WithOffset(offset)
|
||||
builder.WithLimit(NbItemsPerPage)
|
||||
builder.WithLimit(nbItemsPerPage)
|
||||
|
||||
entries, err := builder.GetEntries()
|
||||
if err != nil {
|
||||
|
|
|
@ -6,12 +6,14 @@ package controller
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
"github.com/miniflux/miniflux2/server/ui/form"
|
||||
"log"
|
||||
)
|
||||
|
||||
// ShowUsers shows the list of users.
|
||||
func (c *Controller) ShowUsers(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
|
||||
|
@ -26,7 +28,7 @@ func (c *Controller) ShowUsers(ctx *core.Context, request *core.Request, respons
|
|||
return
|
||||
}
|
||||
|
||||
users, err := c.store.GetUsers()
|
||||
users, err := c.store.Users()
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return
|
||||
|
@ -38,6 +40,7 @@ func (c *Controller) ShowUsers(ctx *core.Context, request *core.Request, respons
|
|||
}))
|
||||
}
|
||||
|
||||
// CreateUser shows the user creation form.
|
||||
func (c *Controller) CreateUser(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
|
||||
|
@ -58,6 +61,7 @@ func (c *Controller) CreateUser(ctx *core.Context, request *core.Request, respon
|
|||
}))
|
||||
}
|
||||
|
||||
// SaveUser validate and save the new user into the database.
|
||||
func (c *Controller) SaveUser(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
|
||||
|
@ -105,6 +109,7 @@ func (c *Controller) SaveUser(ctx *core.Context, request *core.Request, response
|
|||
response.Redirect(ctx.Route("users"))
|
||||
}
|
||||
|
||||
// EditUser shows the form to edit a user.
|
||||
func (c *Controller) EditUser(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
|
||||
|
@ -134,6 +139,7 @@ func (c *Controller) EditUser(ctx *core.Context, request *core.Request, response
|
|||
}))
|
||||
}
|
||||
|
||||
// UpdateUser validate and update a user.
|
||||
func (c *Controller) UpdateUser(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
|
||||
|
@ -189,6 +195,7 @@ func (c *Controller) UpdateUser(ctx *core.Context, request *core.Request, respon
|
|||
response.Redirect(ctx.Route("users"))
|
||||
}
|
||||
|
||||
// RemoveUser deletes a user from the database.
|
||||
func (c *Controller) RemoveUser(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.LoggedUser()
|
||||
if !user.IsAdmin {
|
||||
|
@ -216,7 +223,7 @@ func (c *Controller) getUserFromURL(ctx *core.Context, request *core.Request, re
|
|||
return nil, err
|
||||
}
|
||||
|
||||
user, err := c.store.GetUserById(userID)
|
||||
user, err := c.store.UserByID(userID)
|
||||
if err != nil {
|
||||
response.HTML().ServerError(err)
|
||||
return nil, err
|
||||
|
|
|
@ -6,9 +6,10 @@ package filter
|
|||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
|
||||
"github.com/miniflux/miniflux2/reader/url"
|
||||
"github.com/miniflux/miniflux2/server/route"
|
||||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -24,7 +25,7 @@ func ImageProxyFilter(r *mux.Router, data string) string {
|
|||
doc.Find("img").Each(func(i int, img *goquery.Selection) {
|
||||
if srcAttr, ok := img.Attr("src"); ok {
|
||||
if !url.IsHTTPS(srcAttr) {
|
||||
path := route.GetRoute(r, "proxy", "encodedURL", base64.StdEncoding.EncodeToString([]byte(srcAttr)))
|
||||
path := route.Path(r, "proxy", "encodedURL", base64.StdEncoding.EncodeToString([]byte(srcAttr)))
|
||||
img.SetAttr("src", path)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -7,10 +7,12 @@ package payload
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"io"
|
||||
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
)
|
||||
|
||||
// DecodeEntryStatusPayload unserialize JSON request to update entry statuses.
|
||||
func DecodeEntryStatusPayload(data io.Reader) (entryIDs []int64, status string, err error) {
|
||||
type payload struct {
|
||||
EntryIDs []int64 `json:"entry_ids"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue