MCPcopy
hub / github.com/writefreely/writefreely / UserWebAPI

Method UserWebAPI

handle.go:297–314  ·  view source on GitHub ↗

UserWebAPI handles endpoints that accept a user authorized either via the web (cookies) or an Authorization header.

(f userHandlerFunc)

Source from the content-addressed store, hash-verified

295
296// UserWebAPI handles endpoints that accept a user authorized either via the web (cookies) or an Authorization header.
297func (h *Handler) UserWebAPI(f userHandlerFunc) http.HandlerFunc {
298 return h.UserAll(false, f, func(app *App, r *http.Request) (*User, error) {
299 // Authorize user via cookies
300 u := getUserSession(app, r)
301 if u != nil {
302 return u, nil
303 }
304
305 // Fall back to access token, since user isn't logged in via web
306 var err error
307 u, err = apiAuth(app, r)
308 if err != nil {
309 return nil, err
310 }
311
312 return u, nil
313 })
314}
315
316func (h *Handler) UserAll(web bool, f userHandlerFunc, a authFunc) http.HandlerFunc {
317 return func(w http.ResponseWriter, r *http.Request) {

Callers 1

InitRoutesFunction · 0.80

Calls 3

UserAllMethod · 0.95
getUserSessionFunction · 0.85
apiAuthFunction · 0.85

Tested by

no test coverage detected