MCPcopy
hub / github.com/writefreely/writefreely / viewMeAPI

Function viewMeAPI

account.go:687–709  ·  view source on GitHub ↗
(app *App, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

685}
686
687func viewMeAPI(app *App, w http.ResponseWriter, r *http.Request) error {
688 reqJSON := IsJSON(r)
689 uObj := struct {
690 ID int64 `json:"id,omitempty"`
691 Username string `json:"username,omitempty"`
692 }{}
693 var err error
694
695 if reqJSON {
696 _, uObj.Username, err = app.db.GetUserDataFromToken(r.Header.Get("Authorization"))
697 if err != nil {
698 return err
699 }
700 } else {
701 u := getUserSession(app, r)
702 if u == nil {
703 return impart.WriteSuccess(w, uObj, http.StatusOK)
704 }
705 uObj.Username = u.Username
706 }
707
708 return impart.WriteSuccess(w, uObj, http.StatusOK)
709}
710
711func viewMyPostsAPI(app *App, u *User, w http.ResponseWriter, r *http.Request) error {
712 reqJSON := IsJSON(r)

Callers

nothing calls this directly

Calls 3

IsJSONFunction · 0.85
getUserSessionFunction · 0.85
GetUserDataFromTokenMethod · 0.65

Tested by

no test coverage detected