diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-09-03 14:26:40 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-09-03 14:26:40 -0700 |
commit | eee1f3190355224eef63a4dcdef8c36eb3ca3738 (patch) | |
tree | 009b7ca67b96d9be473d8ddf2c8c95f22a6749d1 /api/user.go | |
parent | 88e81d4d800ff6433518522954197d75203a25c2 (diff) |
Refactor HTTP context handling
Diffstat (limited to 'api/user.go')
-rw-r--r-- | api/user.go | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/api/user.go b/api/user.go index 5ad056e..167fd72 100644 --- a/api/user.go +++ b/api/user.go @@ -8,15 +8,13 @@ import ( "errors" "net/http" - "miniflux.app/http/context" "miniflux.app/http/request" "miniflux.app/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()) + user, err := c.store.UserByID(request.UserID(r)) if err != nil { json.ServerError(w, err) return @@ -27,8 +25,7 @@ func (c *Controller) CurrentUser(w http.ResponseWriter, r *http.Request) { // CreateUser is the API handler to create a new user. func (c *Controller) CreateUser(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - if !ctx.IsAdminUser() { + if !request.IsAdminUser(r) { json.Forbidden(w) return } @@ -61,8 +58,7 @@ func (c *Controller) CreateUser(w http.ResponseWriter, r *http.Request) { // UpdateUser is the API handler to update the given user. func (c *Controller) UpdateUser(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - if !ctx.IsAdminUser() { + if !request.IsAdminUser(r) { json.Forbidden(w) return } @@ -106,8 +102,7 @@ func (c *Controller) UpdateUser(w http.ResponseWriter, r *http.Request) { // Users is the API handler to get the list of users. func (c *Controller) Users(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - if !ctx.IsAdminUser() { + if !request.IsAdminUser(r) { json.Forbidden(w) return } @@ -118,14 +113,13 @@ func (c *Controller) Users(w http.ResponseWriter, r *http.Request) { return } - users.UseTimezone(ctx.UserTimezone()) + users.UseTimezone(request.UserTimezone(r)) json.OK(w, r, users) } // UserByID is the API handler to fetch the given user by the ID. func (c *Controller) UserByID(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - if !ctx.IsAdminUser() { + if !request.IsAdminUser(r) { json.Forbidden(w) return } @@ -147,14 +141,13 @@ func (c *Controller) UserByID(w http.ResponseWriter, r *http.Request) { return } - user.UseTimezone(ctx.UserTimezone()) + user.UseTimezone(request.UserTimezone(r)) json.OK(w, r, user) } // UserByUsername is the API handler to fetch the given user by the username. func (c *Controller) UserByUsername(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - if !ctx.IsAdminUser() { + if !request.IsAdminUser(r) { json.Forbidden(w) return } @@ -176,8 +169,7 @@ func (c *Controller) UserByUsername(w http.ResponseWriter, r *http.Request) { // RemoveUser is the API handler to remove an existing user. func (c *Controller) RemoveUser(w http.ResponseWriter, r *http.Request) { - ctx := context.New(r) - if !ctx.IsAdminUser() { + if !request.IsAdminUser(r) { json.Forbidden(w) return } |