From c652fcaca408cb4529df77cee08980a17a7eb21e Mon Sep 17 00:00:00 2001 From: nxshock Date: Wed, 31 Jul 2019 20:05:28 +0500 Subject: [PATCH] Complete Devices method handler --- internal/handlers.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/handlers.go b/internal/handlers.go index 30b6a71..e480fc8 100644 --- a/internal/handlers.go +++ b/internal/handlers.go @@ -8,6 +8,8 @@ import ( "strconv" "strings" + "github.com/nxshock/signaller/internal/models/devices" + "github.com/gorilla/mux" "github.com/nxshock/signaller/internal/models/common" @@ -293,6 +295,22 @@ func DevicesHandler(w http.ResponseWriter, r *http.Request) { return } + token := getTokenFromResponse(r) + if token == "" { + errorResponse(w, models.M_FORBIDDEN, http.StatusForbidden, "") + return + } + + user := currServer.Backend.GetUserByToken(token) + if user == nil { + errorResponse(w, models.M_UNKNOWN_TOKEN, http.StatusBadRequest, "") + return + } + + var response devices.Response + response.Devices = user.Devices() + + sendJsonResponse(w, http.StatusOK, response) } // https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-directory-list-room-roomid