1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-31 18:31:01 +00:00

Improve Fever middleware and handle groupID=0

This commit is contained in:
Frédéric Guillot 2018-10-26 19:49:49 -07:00
parent 92c98bd986
commit f6028f3863
3 changed files with 22 additions and 4 deletions

View file

@ -13,21 +13,28 @@ import (
"miniflux.app/logger"
)
var feverAuthFailureResponse = map[string]int{"api_version": 3, "auth": 0}
// FeverAuth handles Fever API authentication.
func (m *Middleware) FeverAuth(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
apiKey := r.FormValue("api_key")
if apiKey == "" {
logger.Info("[Middleware:Fever] No API key provided")
json.OK(w, r, feverAuthFailureResponse)
return
}
user, err := m.store.UserByFeverToken(apiKey)
if err != nil {
logger.Error("[Middleware:Fever] %v", err)
json.OK(w, r, map[string]int{"api_version": 3, "auth": 0})
json.OK(w, r, feverAuthFailureResponse)
return
}
if user == nil {
logger.Info("[Middleware:Fever] No user found with this API key")
json.OK(w, r, map[string]int{"api_version": 3, "auth": 0})
json.OK(w, r, feverAuthFailureResponse)
return
}