From f38b130c8f4bf665676602f4faf7125be13ae1d4 Mon Sep 17 00:00:00 2001 From: gitGnome Date: Sun, 5 Apr 2026 15:13:44 +0200 Subject: [PATCH] make login return id of user also --- http.go | 12 +++++++----- structs.go | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/http.go b/http.go index d14635b..0521aaa 100644 --- a/http.go +++ b/http.go @@ -466,15 +466,15 @@ func HttpHandleTokenNew(response http.ResponseWriter, request *http.Request) { if err != nil { user = &User{Name: username} if err = DbUserGetByName(ctx, user); err != nil { - http.Error(response, "bad login1", http.StatusUnauthorized) + http.Error(response, "bad login", http.StatusUnauthorized) return } if err = DbUserGetGroups(ctx, user); err != nil { - http.Error(response, "bad login1", http.StatusUnauthorized) + http.Error(response, "bad login", http.StatusUnauthorized) return } if err = DbUserGetConnections(ctx, user); err != nil { - http.Error(response, "bad login1", http.StatusUnauthorized) + http.Error(response, "bad login", http.StatusUnauthorized) return } CacheSaveUser(user) @@ -482,7 +482,7 @@ func HttpHandleTokenNew(response http.ResponseWriter, request *http.Request) { err = bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(password)) if err != nil { - http.Error(response, "bad login2", http.StatusUnauthorized) + http.Error(response, "bad login", http.StatusUnauthorized) return } @@ -492,8 +492,10 @@ func HttpHandleTokenNew(response http.ResponseWriter, request *http.Request) { return } + json, err := json2.Marshal(LoginReturn{Token: token, UserId: user.Id}) + response.WriteHeader(http.StatusCreated) - response.Write([]byte(token)) + response.Write([]byte(json)) } func HttpHandeGroupCreate(response http.ResponseWriter, request *http.Request) { diff --git a/structs.go b/structs.go index 1ebea9c..a37f7b0 100644 --- a/structs.go +++ b/structs.go @@ -35,3 +35,8 @@ type Group struct { Color [3]uint8 `json:"color"` EnableUserColors bool `json:"enableUserColors"` } + +type LoginReturn struct { + Token string `json:"token"` + UserId uint32 `json:"userId"` +}