knowyt/server/src/handler/userinfo.go
Settel 786a1c46f1
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
bugfix: fix compiler warning
2022-11-06 15:44:48 +01:00

41 lines
870 B
Go

package handler
import (
"encoding/json"
"fmt"
"net/http"
"sirlab.de/go/knowyt/user"
)
type UserInfoJson struct {
Id string `json:"id"`
Name string `json:"name"`
Lang string `json:"lang"`
Role string `json:"role"`
GameId string `json:"game"`
IsCameo string `json:"isCameo,omitempty"`
}
func (authMux *AuthMux) GetUserInfo(usr *user.User, w http.ResponseWriter, r *http.Request) {
gameId := usr.GetGameId()
lang := "de"
if gm, err := authMux.app.GetGameById(gameId); err == nil {
lang = gm.GetLang()
}
usrLight := UserInfoJson{
Id: usr.GetId(),
Name: usr.GetName(),
Role: usr.GetRole(),
Lang: lang,
GameId: gameId,
}
if usr.GetCameo() != nil {
usrLight.IsCameo = "true"
}
w.Header().Add("Content-Type", "application/json")
jsonString, _ := json.Marshal(usrLight)
fmt.Fprintf(w, "%s", string(jsonString))
}