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
|
@ -6,6 +6,7 @@ package api
|
|||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/miniflux/miniflux2/server/api/payload"
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
)
|
||||
|
@ -65,7 +66,7 @@ func (c *Controller) UpdateCategory(ctx *core.Context, request *core.Request, re
|
|||
|
||||
// GetCategories is the API handler to get a list of categories for a given user.
|
||||
func (c *Controller) GetCategories(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
categories, err := c.store.GetCategories(ctx.UserID())
|
||||
categories, err := c.store.Categories(ctx.UserID())
|
||||
if err != nil {
|
||||
response.JSON().ServerError(errors.New("Unable to fetch categories"))
|
||||
return
|
||||
|
|
|
@ -66,7 +66,7 @@ func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, respon
|
|||
return
|
||||
}
|
||||
|
||||
originalFeed, err := c.store.GetFeedById(userID, feedID)
|
||||
originalFeed, err := c.store.FeedByID(userID, feedID)
|
||||
if err != nil {
|
||||
response.JSON().NotFound(errors.New("Unable to find this feed"))
|
||||
return
|
||||
|
@ -88,7 +88,7 @@ func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, respon
|
|||
|
||||
// GetFeeds is the API handler that get all feeds that belongs to the given user.
|
||||
func (c *Controller) GetFeeds(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
feeds, err := c.store.GetFeeds(ctx.UserID())
|
||||
feeds, err := c.store.Feeds(ctx.UserID())
|
||||
if err != nil {
|
||||
response.JSON().ServerError(errors.New("Unable to fetch feeds from the database"))
|
||||
return
|
||||
|
@ -106,7 +106,7 @@ func (c *Controller) GetFeed(ctx *core.Context, request *core.Request, response
|
|||
return
|
||||
}
|
||||
|
||||
feed, err := c.store.GetFeedById(userID, feedID)
|
||||
feed, err := c.store.FeedByID(userID, feedID)
|
||||
if err != nil {
|
||||
response.JSON().ServerError(errors.New("Unable to fetch this feed"))
|
||||
return
|
||||
|
|
|
@ -6,6 +6,7 @@ package api
|
|||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/miniflux/miniflux2/server/api/payload"
|
||||
"github.com/miniflux/miniflux2/server/core"
|
||||
)
|
||||
|
@ -67,7 +68,7 @@ func (c *Controller) UpdateUser(ctx *core.Context, request *core.Request, respon
|
|||
return
|
||||
}
|
||||
|
||||
originalUser, err := c.store.GetUserById(userID)
|
||||
originalUser, err := c.store.UserByID(userID)
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(errors.New("Unable to fetch this user from the database"))
|
||||
return
|
||||
|
@ -94,7 +95,7 @@ func (c *Controller) GetUsers(ctx *core.Context, request *core.Request, response
|
|||
return
|
||||
}
|
||||
|
||||
users, err := c.store.GetUsers()
|
||||
users, err := c.store.Users()
|
||||
if err != nil {
|
||||
response.JSON().ServerError(errors.New("Unable to fetch the list of users"))
|
||||
return
|
||||
|
@ -116,7 +117,7 @@ func (c *Controller) GetUser(ctx *core.Context, request *core.Request, response
|
|||
return
|
||||
}
|
||||
|
||||
user, err := c.store.GetUserById(userID)
|
||||
user, err := c.store.UserByID(userID)
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(errors.New("Unable to fetch this user from the database"))
|
||||
return
|
||||
|
@ -143,7 +144,7 @@ func (c *Controller) RemoveUser(ctx *core.Context, request *core.Request, respon
|
|||
return
|
||||
}
|
||||
|
||||
user, err := c.store.GetUserById(userID)
|
||||
user, err := c.store.UserByID(userID)
|
||||
if err != nil {
|
||||
response.JSON().ServerError(errors.New("Unable to fetch this user from the database"))
|
||||
return
|
||||
|
|
|
@ -12,11 +12,13 @@ import (
|
|||
"github.com/miniflux/miniflux2/model"
|
||||
)
|
||||
|
||||
// EntriesResponse represents the response sent when fetching entries.
|
||||
type EntriesResponse struct {
|
||||
Total int `json:"total"`
|
||||
Entries model.Entries `json:"entries"`
|
||||
}
|
||||
|
||||
// DecodeUserPayload unserialize JSON user object.
|
||||
func DecodeUserPayload(data io.Reader) (*model.User, error) {
|
||||
var user model.User
|
||||
|
||||
|
@ -28,6 +30,7 @@ func DecodeUserPayload(data io.Reader) (*model.User, error) {
|
|||
return &user, nil
|
||||
}
|
||||
|
||||
// DecodeURLPayload unserialize JSON subscription object.
|
||||
func DecodeURLPayload(data io.Reader) (string, error) {
|
||||
type payload struct {
|
||||
URL string `json:"url"`
|
||||
|
@ -42,6 +45,7 @@ func DecodeURLPayload(data io.Reader) (string, error) {
|
|||
return p.URL, nil
|
||||
}
|
||||
|
||||
// DecodeEntryStatusPayload unserialize JSON entry statuses object.
|
||||
func DecodeEntryStatusPayload(data io.Reader) ([]int64, string, error) {
|
||||
type payload struct {
|
||||
EntryIDs []int64 `json:"entry_ids"`
|
||||
|
@ -57,6 +61,7 @@ func DecodeEntryStatusPayload(data io.Reader) ([]int64, string, error) {
|
|||
return p.EntryIDs, p.Status, nil
|
||||
}
|
||||
|
||||
// DecodeFeedCreationPayload unserialize JSON feed creation object.
|
||||
func DecodeFeedCreationPayload(data io.Reader) (string, int64, error) {
|
||||
type payload struct {
|
||||
FeedURL string `json:"feed_url"`
|
||||
|
@ -72,6 +77,7 @@ func DecodeFeedCreationPayload(data io.Reader) (string, int64, error) {
|
|||
return p.FeedURL, p.CategoryID, nil
|
||||
}
|
||||
|
||||
// DecodeFeedModificationPayload unserialize JSON feed object.
|
||||
func DecodeFeedModificationPayload(data io.Reader) (*model.Feed, error) {
|
||||
var feed model.Feed
|
||||
|
||||
|
@ -83,6 +89,7 @@ func DecodeFeedModificationPayload(data io.Reader) (*model.Feed, error) {
|
|||
return &feed, nil
|
||||
}
|
||||
|
||||
// DecodeCategoryPayload unserialize JSON category object.
|
||||
func DecodeCategoryPayload(data io.Reader) (*model.Category, error) {
|
||||
var category model.Category
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"github.com/miniflux/miniflux2/server/middleware"
|
||||
"github.com/miniflux/miniflux2/server/route"
|
||||
"github.com/miniflux/miniflux2/storage"
|
||||
|
||||
|
@ -26,7 +27,7 @@ type Context struct {
|
|||
|
||||
// IsAdminUser checks if the logged user is administrator.
|
||||
func (c *Context) IsAdminUser() bool {
|
||||
if v := c.request.Context().Value("IsAdminUser"); v != nil {
|
||||
if v := c.request.Context().Value(middleware.IsAdminUserContextKey); v != nil {
|
||||
return v.(bool)
|
||||
}
|
||||
return false
|
||||
|
@ -34,7 +35,7 @@ func (c *Context) IsAdminUser() bool {
|
|||
|
||||
// UserTimezone returns the timezone used by the logged user.
|
||||
func (c *Context) UserTimezone() string {
|
||||
if v := c.request.Context().Value("UserTimezone"); v != nil {
|
||||
if v := c.request.Context().Value(middleware.UserTimezoneContextKey); v != nil {
|
||||
return v.(string)
|
||||
}
|
||||
return "UTC"
|
||||
|
@ -42,7 +43,7 @@ func (c *Context) UserTimezone() string {
|
|||
|
||||
// IsAuthenticated returns a boolean if the user is authenticated.
|
||||
func (c *Context) IsAuthenticated() bool {
|
||||
if v := c.request.Context().Value("IsAuthenticated"); v != nil {
|
||||
if v := c.request.Context().Value(middleware.IsAuthenticatedContextKey); v != nil {
|
||||
return v.(bool)
|
||||
}
|
||||
return false
|
||||
|
@ -50,7 +51,7 @@ func (c *Context) IsAuthenticated() bool {
|
|||
|
||||
// UserID returns the UserID of the logged user.
|
||||
func (c *Context) UserID() int64 {
|
||||
if v := c.request.Context().Value("UserId"); v != nil {
|
||||
if v := c.request.Context().Value(middleware.UserIDContextKey); v != nil {
|
||||
return v.(int64)
|
||||
}
|
||||
return 0
|
||||
|
@ -60,7 +61,7 @@ func (c *Context) UserID() int64 {
|
|||
func (c *Context) LoggedUser() *model.User {
|
||||
if c.user == nil {
|
||||
var err error
|
||||
c.user, err = c.store.GetUserById(c.UserID())
|
||||
c.user, err = c.store.UserByID(c.UserID())
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
@ -81,7 +82,7 @@ func (c *Context) UserLanguage() string {
|
|||
|
||||
// CsrfToken returns the current CSRF token.
|
||||
func (c *Context) CsrfToken() string {
|
||||
if v := c.request.Context().Value("CsrfToken"); v != nil {
|
||||
if v := c.request.Context().Value(middleware.CsrfContextKey); v != nil {
|
||||
return v.(string)
|
||||
}
|
||||
|
||||
|
@ -91,7 +92,7 @@ func (c *Context) CsrfToken() string {
|
|||
|
||||
// Route returns the path for the given arguments.
|
||||
func (c *Context) Route(name string, args ...interface{}) string {
|
||||
return route.GetRoute(c.router, name, args...)
|
||||
return route.Path(c.router, name, args...)
|
||||
}
|
||||
|
||||
// NewContext creates a new Context.
|
||||
|
|
|
@ -27,7 +27,7 @@ type Handler struct {
|
|||
translator *locale.Translator
|
||||
template *template.Engine
|
||||
router *mux.Router
|
||||
middleware *middleware.MiddlewareChain
|
||||
middleware *middleware.Chain
|
||||
}
|
||||
|
||||
// Use is a wrapper around an HTTP handler.
|
||||
|
@ -51,7 +51,7 @@ func (h *Handler) Use(f HandlerFunc) http.Handler {
|
|||
}
|
||||
|
||||
// NewHandler returns a new Handler.
|
||||
func NewHandler(store *storage.Storage, router *mux.Router, template *template.Engine, translator *locale.Translator, middleware *middleware.MiddlewareChain) *Handler {
|
||||
func NewHandler(store *storage.Storage, router *mux.Router, template *template.Engine, translator *locale.Translator, middleware *middleware.Chain) *Handler {
|
||||
return &Handler{
|
||||
store: store,
|
||||
translator: translator,
|
||||
|
|
|
@ -6,15 +6,18 @@ package middleware
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/miniflux/miniflux2/storage"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/miniflux/miniflux2/storage"
|
||||
)
|
||||
|
||||
// BasicAuthMiddleware is the middleware for HTTP Basic authentication.
|
||||
type BasicAuthMiddleware struct {
|
||||
store *storage.Storage
|
||||
}
|
||||
|
||||
// Handler executes the middleware.
|
||||
func (b *BasicAuthMiddleware) Handler(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||
|
@ -35,7 +38,7 @@ func (b *BasicAuthMiddleware) Handler(next http.Handler) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
user, err := b.store.GetUserByUsername(username)
|
||||
user, err := b.store.UserByUsername(username)
|
||||
if err != nil || user == nil {
|
||||
log.Println("[Middleware:BasicAuth] User not found:", username)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
|
@ -47,15 +50,16 @@ func (b *BasicAuthMiddleware) Handler(next http.Handler) http.Handler {
|
|||
b.store.SetLastLogin(user.ID)
|
||||
|
||||
ctx := r.Context()
|
||||
ctx = context.WithValue(ctx, "UserId", user.ID)
|
||||
ctx = context.WithValue(ctx, "UserTimezone", user.Timezone)
|
||||
ctx = context.WithValue(ctx, "IsAdminUser", user.IsAdmin)
|
||||
ctx = context.WithValue(ctx, "IsAuthenticated", true)
|
||||
ctx = context.WithValue(ctx, UserIDContextKey, user.ID)
|
||||
ctx = context.WithValue(ctx, UserTimezoneContextKey, user.Timezone)
|
||||
ctx = context.WithValue(ctx, IsAdminUserContextKey, user.IsAdmin)
|
||||
ctx = context.WithValue(ctx, IsAuthenticatedContextKey, true)
|
||||
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
// NewBasicAuthMiddleware returns a new BasicAuthMiddleware.
|
||||
func NewBasicAuthMiddleware(s *storage.Storage) *BasicAuthMiddleware {
|
||||
return &BasicAuthMiddleware{store: s}
|
||||
}
|
||||
|
|
26
server/middleware/context_keys.go
Normal file
26
server/middleware/context_keys.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
// 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 middleware
|
||||
|
||||
type contextKey struct {
|
||||
name string
|
||||
}
|
||||
|
||||
var (
|
||||
// UserIDContextKey is the context key used to store the user ID.
|
||||
UserIDContextKey = &contextKey{"UserID"}
|
||||
|
||||
// UserTimezoneContextKey is the context key used to store the user timezone.
|
||||
UserTimezoneContextKey = &contextKey{"UserTimezone"}
|
||||
|
||||
// IsAdminUserContextKey is the context key used to store the user role.
|
||||
IsAdminUserContextKey = &contextKey{"IsAdminUser"}
|
||||
|
||||
// IsAuthenticatedContextKey is the context key used to store the authentication flag.
|
||||
IsAuthenticatedContextKey = &contextKey{"IsAuthenticated"}
|
||||
|
||||
// CsrfContextKey is the context key used to store CSRF token.
|
||||
CsrfContextKey = &contextKey{"CSRF"}
|
||||
)
|
|
@ -6,11 +6,13 @@ package middleware
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/miniflux/miniflux2/helper"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/miniflux/miniflux2/helper"
|
||||
)
|
||||
|
||||
// Csrf is a middleware that handle CSRF tokens.
|
||||
func Csrf(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var csrfToken string
|
||||
|
@ -32,7 +34,7 @@ func Csrf(next http.Handler) http.Handler {
|
|||
}
|
||||
|
||||
ctx := r.Context()
|
||||
ctx = context.WithValue(ctx, "CsrfToken", csrfToken)
|
||||
ctx = context.WithValue(ctx, CsrfContextKey, csrfToken)
|
||||
|
||||
w.Header().Add("Vary", "Cookie")
|
||||
isTokenValid := csrfToken == r.FormValue("csrf") || csrfToken == r.Header.Get("X-Csrf-Token")
|
||||
|
|
|
@ -8,13 +8,16 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
// Middleware represents a HTTP middleware.
|
||||
type Middleware func(http.Handler) http.Handler
|
||||
|
||||
type MiddlewareChain struct {
|
||||
// Chain handles a list of middlewares.
|
||||
type Chain struct {
|
||||
middlewares []Middleware
|
||||
}
|
||||
|
||||
func (m *MiddlewareChain) Wrap(h http.Handler) http.Handler {
|
||||
// Wrap adds a HTTP handler into the chain.
|
||||
func (m *Chain) Wrap(h http.Handler) http.Handler {
|
||||
for i := range m.middlewares {
|
||||
h = m.middlewares[len(m.middlewares)-1-i](h)
|
||||
}
|
||||
|
@ -22,10 +25,12 @@ func (m *MiddlewareChain) Wrap(h http.Handler) http.Handler {
|
|||
return h
|
||||
}
|
||||
|
||||
func (m *MiddlewareChain) WrapFunc(fn http.HandlerFunc) http.Handler {
|
||||
// WrapFunc adds a HTTP handler function into the chain.
|
||||
func (m *Chain) WrapFunc(fn http.HandlerFunc) http.Handler {
|
||||
return m.Wrap(fn)
|
||||
}
|
||||
|
||||
func NewMiddlewareChain(middlewares ...Middleware) *MiddlewareChain {
|
||||
return &MiddlewareChain{append(([]Middleware)(nil), middlewares...)}
|
||||
// NewChain returns a new Chain.
|
||||
func NewChain(middlewares ...Middleware) *Chain {
|
||||
return &Chain{append(([]Middleware)(nil), middlewares...)}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,13 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// SessionMiddleware represents a session middleware.
|
||||
type SessionMiddleware struct {
|
||||
store *storage.Storage
|
||||
router *mux.Router
|
||||
}
|
||||
|
||||
// Handler execute the middleware.
|
||||
func (s *SessionMiddleware) Handler(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session := s.getSessionFromCookie(r)
|
||||
|
@ -30,13 +32,13 @@ func (s *SessionMiddleware) Handler(next http.Handler) http.Handler {
|
|||
if s.isPublicRoute(r) {
|
||||
next.ServeHTTP(w, r)
|
||||
} else {
|
||||
http.Redirect(w, r, route.GetRoute(s.router, "login"), http.StatusFound)
|
||||
http.Redirect(w, r, route.Path(s.router, "login"), http.StatusFound)
|
||||
}
|
||||
} else {
|
||||
log.Println("[Middleware:Session]", session)
|
||||
ctx := r.Context()
|
||||
ctx = context.WithValue(ctx, "UserId", session.UserID)
|
||||
ctx = context.WithValue(ctx, "IsAuthenticated", true)
|
||||
ctx = context.WithValue(ctx, UserIDContextKey, session.UserID)
|
||||
ctx = context.WithValue(ctx, IsAuthenticatedContextKey, true)
|
||||
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
}
|
||||
|
@ -59,7 +61,7 @@ func (s *SessionMiddleware) getSessionFromCookie(r *http.Request) *model.Session
|
|||
return nil
|
||||
}
|
||||
|
||||
session, err := s.store.GetSessionByToken(sessionCookie.Value)
|
||||
session, err := s.store.SessionByToken(sessionCookie.Value)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil
|
||||
|
@ -68,6 +70,7 @@ func (s *SessionMiddleware) getSessionFromCookie(r *http.Request) *model.Session
|
|||
return session
|
||||
}
|
||||
|
||||
// NewSessionMiddleware returns a new SessionMiddleware.
|
||||
func NewSessionMiddleware(s *storage.Storage, r *mux.Router) *SessionMiddleware {
|
||||
return &SessionMiddleware{store: s, router: r}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func GetRoute(router *mux.Router, name string, args ...interface{}) string {
|
||||
// Path returns the defined route based on given arguments.
|
||||
func Path(router *mux.Router, name string, args ...interface{}) string {
|
||||
route := router.Get(name)
|
||||
if route == nil {
|
||||
log.Fatalln("Route not found:", name)
|
||||
|
|
|
@ -31,11 +31,11 @@ func getRoutes(cfg *config.Config, store *storage.Storage, feedHandler *feed.Han
|
|||
apiController := api_controller.NewController(store, feedHandler)
|
||||
uiController := ui_controller.NewController(cfg, store, pool, feedHandler, opml.NewHandler(store))
|
||||
|
||||
apiHandler := core.NewHandler(store, router, templateEngine, translator, middleware.NewMiddlewareChain(
|
||||
apiHandler := core.NewHandler(store, router, templateEngine, translator, middleware.NewChain(
|
||||
middleware.NewBasicAuthMiddleware(store).Handler,
|
||||
))
|
||||
|
||||
uiHandler := core.NewHandler(store, router, templateEngine, translator, middleware.NewMiddlewareChain(
|
||||
uiHandler := core.NewHandler(store, router, templateEngine, translator, middleware.NewChain(
|
||||
middleware.NewSessionMiddleware(store, router).Handler,
|
||||
middleware.Csrf,
|
||||
))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2017-11-25 10:47:30.351686806 -0800 PST m=+0.007814912
|
||||
// 2017-11-27 21:07:53.21170439 -0800 PST m=+0.005890618
|
||||
|
||||
package static
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2017-11-25 10:47:30.352812144 -0800 PST m=+0.008940250
|
||||
// 2017-11-27 21:07:53.213299146 -0800 PST m=+0.007485374
|
||||
|
||||
package static
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2017-11-25 10:47:30.357950671 -0800 PST m=+0.014078777
|
||||
// 2017-11-27 21:07:53.215205872 -0800 PST m=+0.009392100
|
||||
|
||||
package static
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2017-11-25 10:47:30.370347794 -0800 PST m=+0.026475900
|
||||
// 2017-11-27 21:07:53.233262137 -0800 PST m=+0.027448365
|
||||
|
||||
package template
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ func (e *Engine) parseAll() {
|
|||
return false
|
||||
},
|
||||
"route": func(name string, args ...interface{}) string {
|
||||
return route.GetRoute(e.router, name, args...)
|
||||
return route.Path(e.router, name, args...)
|
||||
},
|
||||
"noescape": func(str string) template.HTML {
|
||||
return template.HTML(str)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2017-11-25 17:05:58.40092186 -0800 PST m=+0.019242510
|
||||
// 2017-11-27 21:07:53.218349526 -0800 PST m=+0.012535754
|
||||
|
||||
package template
|
||||
|
||||
|
|
|
@ -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