Commit 4c9e00d8 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Report username errors to client.

We now report ErrUsernameRequired and ErrDuplicateUsername
errors by setting the "error" field of messages.
parent 8c151002
...@@ -1434,8 +1434,14 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1434,8 +1434,14 @@ func handleClientMessage(c *webClient, m clientMessage) error {
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
} else if err == group.ErrAnonymousNotAuthorised { } else if err == group.ErrAnonymousNotAuthorised {
s = "please choose a username" s = "please choose a username"
} else if err, ok := err.(group.UserError); ok { } else if _, ok := err.(group.UserError); ok {
s = err.Error() 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 { } else {
s = "internal server error" s = "internal server error"
log.Printf("Join group: %v", err) log.Printf("Join group: %v", err)
...@@ -1738,6 +1744,11 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1738,6 +1744,11 @@ func handleClientMessage(c *webClient, m clientMessage) error {
return terror("error", "token doesn't expire") 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 { for _, p := range tok.Permissions {
if !member(p, c.permissions) { if !member(p, c.permissions) {
return terror( return terror(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment