From 4c9e00d87479ced20ea118c2c8b4b44345a6075e Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sat, 1 Apr 2023 00:13:20 +0200 Subject: [PATCH] Report username errors to client. We now report ErrUsernameRequired and ErrDuplicateUsername errors by setting the "error" field of messages. --- rtpconn/webclient.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index d75a217..82cfebe 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -1434,8 +1434,14 @@ func handleClientMessage(c *webClient, m clientMessage) error { time.Sleep(200 * time.Millisecond) } else if err == group.ErrAnonymousNotAuthorised { s = "please choose a username" - } else if err, ok := err.(group.UserError); ok { + } else if _, ok := err.(group.UserError); ok { s = err.Error() + } else if err == token.ErrUsernameRequired { + s = err.Error() + e = "need-username" + } else if err == group.ErrDuplicateUsername { + s = err.Error() + e = "duplicate-username" } else { s = "internal server error" log.Printf("Join group: %v", err) @@ -1738,6 +1744,11 @@ func handleClientMessage(c *webClient, m clientMessage) error { return terror("error", "token doesn't expire") } + if tok.Username != nil && + c.group.UserExists(*tok.Username) { + return terror("error", "that username is taken") + } + for _, p := range tok.Permissions { if !member(p, c.permissions) { return terror(