mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
Extend userAPI to be able to query accounts
This commit is contained in:
parent
4af97d9376
commit
1f9c2148d0
|
|
@ -50,6 +50,7 @@ type KeyserverUserAPI interface {
|
|||
|
||||
type RoomserverUserAPI interface {
|
||||
QueryAccountData(ctx context.Context, req *QueryAccountDataRequest, res *QueryAccountDataResponse) error
|
||||
QueryAccountByLocalpart(ctx context.Context, req *QueryAccountByLocalpartRequest, res *QueryAccountByLocalpartResponse) (err error)
|
||||
}
|
||||
|
||||
// api functions required by the media api
|
||||
|
|
@ -654,3 +655,11 @@ type PerformForgetThreePIDRequest QueryLocalpartForThreePIDRequest
|
|||
type PerformSaveThreePIDAssociationRequest struct {
|
||||
ThreePID, Localpart, Medium string
|
||||
}
|
||||
|
||||
type QueryAccountByLocalpartRequest struct {
|
||||
Localpart string
|
||||
}
|
||||
|
||||
type QueryAccountByLocalpartResponse struct {
|
||||
Account *Account
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,6 +204,12 @@ func (t *UserInternalAPITrace) PerformSaveThreePIDAssociation(ctx context.Contex
|
|||
return err
|
||||
}
|
||||
|
||||
func (t *UserInternalAPITrace) QueryAccountByLocalpart(ctx context.Context, req *QueryAccountByLocalpartRequest, res *QueryAccountByLocalpartResponse) error {
|
||||
err := t.Impl.QueryAccountByLocalpart(ctx, req, res)
|
||||
util.GetLogger(ctx).Infof("QueryAccountByLocalpart req=%+v res=%+v", js(req), js(res))
|
||||
return err
|
||||
}
|
||||
|
||||
func js(thing interface{}) string {
|
||||
b, err := json.Marshal(thing)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -536,6 +536,11 @@ func (a *UserInternalAPI) QueryAccessToken(ctx context.Context, req *api.QueryAc
|
|||
return nil
|
||||
}
|
||||
|
||||
func (a *UserInternalAPI) QueryAccountByLocalpart(ctx context.Context, req *api.QueryAccountByLocalpartRequest, res *api.QueryAccountByLocalpartResponse) (err error) {
|
||||
res.Account, err = a.DB.GetAccountByLocalpart(ctx, req.Localpart)
|
||||
return
|
||||
}
|
||||
|
||||
// Return the appservice 'device' or nil if the token is not an appservice. Returns an error if there was a problem
|
||||
// creating a 'device'.
|
||||
func (a *UserInternalAPI) queryAppServiceToken(ctx context.Context, token, appServiceUserID string) (*api.Device, error) {
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ const (
|
|||
QueryAccountByPasswordPath = "/userapi/queryAccountByPassword"
|
||||
QueryLocalpartForThreePIDPath = "/userapi/queryLocalpartForThreePID"
|
||||
QueryThreePIDsForLocalpartPath = "/userapi/queryThreePIDsForLocalpart"
|
||||
QueryAccountByLocalpartPath = "/userapi/queryAccountType"
|
||||
)
|
||||
|
||||
// NewUserAPIClient creates a UserInternalAPI implemented by talking to a HTTP POST API.
|
||||
|
|
@ -439,3 +440,14 @@ func (h *httpUserInternalAPI) PerformSaveThreePIDAssociation(
|
|||
h.httpClient, ctx, request, response,
|
||||
)
|
||||
}
|
||||
|
||||
func (h *httpUserInternalAPI) QueryAccountByLocalpart(
|
||||
ctx context.Context,
|
||||
req *api.QueryAccountByLocalpartRequest,
|
||||
res *api.QueryAccountByLocalpartResponse,
|
||||
) error {
|
||||
return httputil.CallInternalRPCAPI(
|
||||
"QueryAccountByLocalpart", h.apiURL+QueryAccountByLocalpartPath,
|
||||
h.httpClient, ctx, req, res,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,4 +197,9 @@ func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
|
|||
PerformSaveThreePIDAssociationPath,
|
||||
httputil.MakeInternalRPCAPI("UserAPIPerformSaveThreePIDAssociation", s.PerformSaveThreePIDAssociation),
|
||||
)
|
||||
|
||||
internalAPIMux.Handle(
|
||||
QueryAccountByLocalpartPath,
|
||||
httputil.MakeInternalRPCAPI("AccountByLocalpart", s.QueryAccountByLocalpart),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue