refactor: Make "get login flows" using models package

This commit is contained in:
ChronosX88 2019-07-19 20:29:20 +04:00
parent b140a4f726
commit b0ac28ab22
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A

View File

@ -8,6 +8,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/nxshock/signaller/internal/models/common"
"github.com/nxshock/signaller/internal/models" "github.com/nxshock/signaller/internal/models"
login "github.com/nxshock/signaller/internal/models/login" login "github.com/nxshock/signaller/internal/models/login"
register "github.com/nxshock/signaller/internal/models/register" 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 // https://models.org/docs/spec/client_server/latest#get-models-client-r0-login
case "GET": case "GET":
{ {
type LoginFlow struct { response := login.GetLoginReply{
Type string `json:"type"` 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) sendJsonResponse(w, http.StatusOK, response)
} }
// https://models.org/docs/spec/client_server/latest#post-models-client-r0-login // https://models.org/docs/spec/client_server/latest#post-models-client-r0-login
case "POST": case "POST":
{ {
@ -69,7 +64,8 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
response := login.LoginReply{ response := login.LoginReply{
UserID: request.Identifier.User, UserID: request.Identifier.User,
AccessToken: token} AccessToken: token,
}
sendJsonResponse(w, http.StatusOK, response) sendJsonResponse(w, http.StatusOK, response)
} }