41 lines
870 B
Go
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))
|
|
}
|