Trim code, update against merged changes

This commit is contained in:
Anant Prakash 2018-07-26 23:13:24 +05:30
parent c1f23b8023
commit 7b8c12247c
No known key found for this signature in database
GPG key ID: C5D399F626523045
2 changed files with 11 additions and 23 deletions

View file

@ -181,6 +181,12 @@ func Setup(
}),
).Methods(http.MethodPut, http.MethodOptions)
r0mux.Handle("/account/whoami",
common.MakeAuthAPI("whoami", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
return Whoami(req, device)
}),
).Methods(http.MethodGet, http.MethodOptions)
// Stub endpoints required by Riot
r0mux.Handle("/login",
@ -379,12 +385,6 @@ func Setup(
}),
).Methods(http.MethodPut, http.MethodOptions)
r0mux.Handle("/account/whoami",
common.MakeAuthAPI("whoami", accountDB, deviceDB, cfg.Derived.ApplicationServices, func(req *http.Request, user string, device *authtypes.Device) util.JSONResponse {
return Whoami(req, user)
}),
).Methods(http.MethodGet, http.MethodOptions)
// Stub implementations for sytest
r0mux.Handle("/events",
common.MakeExternalAPI("events", func(req *http.Request) util.JSONResponse {

View file

@ -15,7 +15,7 @@ package routing
import (
"net/http"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/util"
)
@ -24,23 +24,11 @@ type whoamiResponse struct {
UserID string `json:"user_id"`
}
// Whoami implements `/account/whoami` which enables client to query owner of the HTTP request.
// Whoami implements `/account/whoami` which enables client to query their account user id.
// https://matrix.org/docs/spec/client_server/r0.3.0.html#get-matrix-client-r0-account-whoami
func Whoami(req *http.Request, userID string) util.JSONResponse {
if req.Method == http.MethodGet {
util.GetLogger(req.Context()).WithField("user", userID).Info("Processing whoami request")
return util.JSONResponse{
Code: http.StatusOK,
JSON: whoamiResponse{
UserID: userID,
},
}
}
func Whoami(req *http.Request, device *authtypes.Device) util.JSONResponse {
return util.JSONResponse{
Code: http.StatusMethodNotAllowed,
JSON: jsonerror.NotFound("Bad method"),
Code: http.StatusOK,
JSON: whoamiResponse{UserID: device.UserID},
}
}