From b0ac28ab22708d554d873449359397959ce3cb5b Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Fri, 19 Jul 2019 20:29:20 +0400 Subject: [PATCH] refactor: Make "get login flows" using models package --- internal/handlers.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/internal/handlers.go b/internal/handlers.go index 0eee6b0..71d8e78 100644 --- a/internal/handlers.go +++ b/internal/handlers.go @@ -8,6 +8,8 @@ import ( "strconv" "strings" + "github.com/nxshock/signaller/internal/models/common" + "github.com/nxshock/signaller/internal/models" login "github.com/nxshock/signaller/internal/models/login" register "github.com/nxshock/signaller/internal/models/register" @@ -35,21 +37,14 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) { // https://models.org/docs/spec/client_server/latest#get-models-client-r0-login case "GET": { - type LoginFlow struct { - Type string `json:"type"` + response := login.GetLoginReply{ + Flows: []login.Flow{ + login.Flow{Type: common.AuthenticationTypePassword}, + }, } - type Response struct { - Flows []LoginFlow `json:"flows"` - } - - response := Response{ - Flows: []LoginFlow{ - LoginFlow{Type: string(M_LOGIN_PASSWORD)}}} - sendJsonResponse(w, http.StatusOK, response) } - // https://models.org/docs/spec/client_server/latest#post-models-client-r0-login case "POST": { @@ -69,7 +64,8 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) { response := login.LoginReply{ UserID: request.Identifier.User, - AccessToken: token} + AccessToken: token, + } sendJsonResponse(w, http.StatusOK, response) }