add getting user
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
data
|
data
|
||||||
|
config
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ func main() {
|
|||||||
http.HandleFunc("/mod/user/about", withCORS(httpRequest.HandleUserModProfile))
|
http.HandleFunc("/mod/user/about", withCORS(httpRequest.HandleUserModProfile))
|
||||||
http.HandleFunc("/mod/connection/accept", withCORS(httpRequest.HandleUserElevateConnection))
|
http.HandleFunc("/mod/connection/accept", withCORS(httpRequest.HandleUserElevateConnection))
|
||||||
|
|
||||||
|
http.HandleFunc("/get/user", withCORS(httpRequest.HandleUserGetUser))
|
||||||
http.HandleFunc("/get/connections", withCORS(httpRequest.HandleUserGetConnections))
|
http.HandleFunc("/get/connections", withCORS(httpRequest.HandleUserGetConnections))
|
||||||
http.HandleFunc("/get/connection/messages", withCORS(httpRequest.HandleUserGetConnectionMessages))
|
http.HandleFunc("/get/connection/messages", withCORS(httpRequest.HandleUserGetConnectionMessages))
|
||||||
http.HandleFunc("/get/file", withCORS(httpRequest.HandleAttachmentFileDownload))
|
http.HandleFunc("/get/file", withCORS(httpRequest.HandleAttachmentFileDownload))
|
||||||
|
|||||||
@@ -333,6 +333,7 @@ func HandleUserGetConnections(response http.ResponseWriter, request *http.Reques
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := request.Context()
|
ctx := request.Context()
|
||||||
|
|
||||||
user, err := getUserByToken(ctx, request.FormValue("token"))
|
user, err := getUserByToken(ctx, request.FormValue("token"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, "invalid token", http.StatusUnauthorized)
|
http.Error(response, "invalid token", http.StatusUnauthorized)
|
||||||
|
|||||||
@@ -314,6 +314,39 @@ func HandleUserModProfileBg(response http.ResponseWriter, request *http.Request)
|
|||||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response.WriteHeader(http.StatusAccepted)
|
response.WriteHeader(http.StatusAccepted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HandleUserGetUser(response http.ResponseWriter, request *http.Request) {
|
||||||
|
if !postValidCheckWithResponseOnFail(&response, request, postNormal) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx := request.Context()
|
||||||
|
|
||||||
|
_, err := getUserByToken(ctx, request.FormValue("token"))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(response, "invalid token", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
targetId, err := convertions.ConvertStringUuid(request.FormValue("targetid"))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(response, "invalid userid", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
target, err := getUserById(ctx, targetId)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(response, "invalid userid", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
json, err := json2.Marshal(target)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(response, "json parse error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.WriteHeader(http.StatusAccepted)
|
||||||
|
response.Write(json)
|
||||||
|
}
|
||||||
|
|||||||
+12
-12
@@ -25,18 +25,18 @@ func (r Rgba) GetRandom() *Rgba {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Mu sync.RWMutex
|
Mu sync.RWMutex `json:"-"`
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
Pronouns string
|
Pronouns string `json:"pronouns"`
|
||||||
Description string
|
Description string `json:"description"`
|
||||||
Avatar string
|
Avatar string `json:"avatar"`
|
||||||
ProfileBg string
|
ProfileBg string `json:"profileBg"`
|
||||||
PasswordHash string
|
PasswordHash string `json:"passwordHash"`
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
WsConn *websocket.Conn
|
WsConn *websocket.Conn `json:"-"`
|
||||||
Id uuid.UUID
|
Id uuid.UUID `json:"-"`
|
||||||
Connections map[uuid.UUID]*Connection
|
Connections map[uuid.UUID]*Connection `json:"-"`
|
||||||
Color *Rgba
|
Color *Rgba `json:"color"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserProfileUpdateList struct {
|
type UserProfileUpdateList struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user