add client and groups member logic

This commit is contained in:
2026-03-27 18:49:45 +01:00
parent a95bc43be6
commit c5fc74d142
9 changed files with 256 additions and 70 deletions
+8 -7
View File
@@ -117,15 +117,15 @@ func HttpHandleLogin(response http.ResponseWriter, request *http.Request) {
err := DbSetClientByName(ctx, client)
if err != nil {
http.Error(response, "bad login", http.StatusUnauthorized)
http.Error(response, "bad login1", http.StatusUnauthorized)
return
}
CacheSetClient(client)
CacheSaveClient(client)
}
err = bcrypt.CompareHashAndPassword([]byte(client.PasswordHash), []byte(password))
if err != nil {
http.Error(response, "bad login", http.StatusUnauthorized)
http.Error(response, "bad login2", http.StatusUnauthorized)
return
}
@@ -178,7 +178,7 @@ func HttpHandleGroupCreate(response http.ResponseWriter, request *http.Request)
if err == nil {
client = *cacheClient
} else {
err = DbSetClientById(ctx, &client)
err = DbSetClientByIdWithoutGroups(ctx, &client)
if err != nil {
http.Error(response, "internal server error", http.StatusInternalServerError)
return
@@ -191,6 +191,7 @@ func HttpHandleGroupCreate(response http.ResponseWriter, request *http.Request)
OwnerId: clientId,
CreatorId: clientId,
Color: color,
Clients: map[uint32]struct{}{clientId: {}},
}
enableClientColors := request.FormValue("enableClientColors")
@@ -200,14 +201,14 @@ func HttpHandleGroupCreate(response http.ResponseWriter, request *http.Request)
err = DbSaveGroupWithoutClients(ctx, &group)
if err != nil {
http.Error(response, "internal server error", http.StatusInternalServerError)
http.Error(response, err.Error(), http.StatusInternalServerError)
return
}
groupIdBytes := make([]byte, 4)
binary.BigEndian.PutUint32(groupIdBytes, group.Id)
response.WriteHeader(http.StatusCreated)
response.Write([]byte(groupIdBytes))
response.Write(groupIdBytes)
}
func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Request) {
@@ -236,7 +237,7 @@ func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Reques
if err == nil {
group = *groupPtr
} else {
err = DbSetGroupById(ctx, &group)
err = DbSetGroupByIdWithoutClients(ctx, &group)
if err != nil {
http.Error(response, "no such group", http.StatusUnauthorized)
return