From baf97280f684232857f7cf88d9ba7fe8957d4dbf Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 20 Apr 2017 11:52:34 +0100 Subject: [PATCH] Add stub login endpoint --- .../dendrite/clientapi/readers/login.go | 41 +++++++++++++++++++ .../dendrite/clientapi/routing/routing.go | 6 +++ 2 files changed, 47 insertions(+) create mode 100644 src/github.com/matrix-org/dendrite/clientapi/readers/login.go diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/login.go b/src/github.com/matrix-org/dendrite/clientapi/readers/login.go new file mode 100644 index 000000000..1f2733fa4 --- /dev/null +++ b/src/github.com/matrix-org/dendrite/clientapi/readers/login.go @@ -0,0 +1,41 @@ +package readers + +import ( + "github.com/matrix-org/dendrite/clientapi/jsonerror" + "github.com/matrix-org/util" + "net/http" +) + +type loginFlows struct { + Flows []flow `json:"flows"` +} + +type flow struct { + Type string `json:"type"` + Stages []string `json:"stages"` +} + +func passwordLogin() loginFlows { + f := loginFlows{} + s := flow{"m.login.password", []string{"m.login.password"}} + f.Flows = append(f.Flows, s) + return f +} + +func Login(req *http.Request) util.JSONResponse { + if req.Method == "GET" { + return util.JSONResponse{ + Code: 200, + JSON: passwordLogin(), + } + } else if req.Method == "POST" { + return util.JSONResponse{ + Code: 403, + JSON: jsonerror.Forbidden("Not implemented"), + } + } + return util.JSONResponse{ + Code: 405, + JSON: jsonerror.NotFound("Bad method"), + } +} diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go index 295953990..352b3af0f 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go @@ -6,6 +6,7 @@ import ( "github.com/gorilla/mux" "github.com/matrix-org/dendrite/clientapi/config" "github.com/matrix-org/dendrite/clientapi/producers" + "github.com/matrix-org/dendrite/clientapi/readers" "github.com/matrix-org/dendrite/clientapi/writers" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/util" @@ -42,6 +43,11 @@ func Setup(servMux *http.ServeMux, httpClient *http.Client, cfg config.ClientAPI return writers.SendEvent(req, vars["roomID"], vars["eventType"], vars["txnID"], &stateKey, cfg, queryAPI, producer) })), ) + r0mux.Handle("/login", + make("login", util.NewJSONRequestHandler(func(req *http.Request) util.JSONResponse { + return readers.Login(req) + })), + ) servMux.Handle("/metrics", prometheus.Handler()) servMux.Handle("/api/", http.StripPrefix("/api", apiMux))