aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Leviathan Jeanis <isavegas2006@gmail.com>2018-05-14 18:41:41 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-05-14 18:41:41 -0700
commite81e4f0ac34569f9ab3f05b33fb05125c1d52026 (patch)
tree189f2b35d322750161e6180e44fe68d6ed563374
parent4674d559a4e8e36d1440165c2bb991a5a27da811 (diff)
Add API endpoint to get logged user
-rw-r--r--api/user.go12
-rw-r--r--daemon/routes.go3
2 files changed, 14 insertions, 1 deletions
diff --git a/api/user.go b/api/user.go
index 3cddb46..a231e8c 100644
--- a/api/user.go
+++ b/api/user.go
@@ -13,6 +13,18 @@ import (
"github.com/miniflux/miniflux/http/response/json"
)
+// CurrentUser is the API handler to retrieve the authenticated user.
+func (c *Controller) CurrentUser(w http.ResponseWriter, r *http.Request) {
+ ctx := context.New(r)
+ user, err := c.store.UserByID(ctx.UserID())
+ if err != nil {
+ json.ServerError(w, err)
+ return
+ }
+
+ json.OK(w, user)
+}
+
// CreateUser is the API handler to create a new user.
func (c *Controller) CreateUser(w http.ResponseWriter, r *http.Request) {
ctx := context.New(r)
diff --git a/daemon/routes.go b/daemon/routes.go
index a3a373a..998df5c 100644
--- a/daemon/routes.go
+++ b/daemon/routes.go
@@ -58,13 +58,14 @@ func routes(cfg *config.Config, store *storage.Storage, feedHandler *feed.Handle
apiRouter.HandleFunc("/users/{userID:[0-9]+}", apiController.UpdateUser).Methods("PUT")
apiRouter.HandleFunc("/users/{userID:[0-9]+}", apiController.RemoveUser).Methods("DELETE")
apiRouter.HandleFunc("/users/{username}", apiController.UserByUsername).Methods("GET")
+ apiRouter.HandleFunc("/me", apiController.CurrentUser).Methods("GET")
apiRouter.HandleFunc("/categories", apiController.CreateCategory).Methods("POST")
apiRouter.HandleFunc("/categories", apiController.GetCategories).Methods("GET")
apiRouter.HandleFunc("/categories/{categoryID}", apiController.UpdateCategory).Methods("PUT")
apiRouter.HandleFunc("/categories/{categoryID}", apiController.RemoveCategory).Methods("DELETE")
apiRouter.HandleFunc("/discover", apiController.GetSubscriptions).Methods("POST")
apiRouter.HandleFunc("/feeds", apiController.CreateFeed).Methods("POST")
- apiRouter.HandleFunc("/feeds", apiController.GetFeeds).Methods("Get")
+ apiRouter.HandleFunc("/feeds", apiController.GetFeeds).Methods("GET")
apiRouter.HandleFunc("/feeds/{feedID}/refresh", apiController.RefreshFeed).Methods("PUT")
apiRouter.HandleFunc("/feeds/{feedID}", apiController.GetFeed).Methods("GET")
apiRouter.HandleFunc("/feeds/{feedID}", apiController.UpdateFeed).Methods("PUT")