1
Fork 0

Use a dedicated error value for anonymous users.

This commit is contained in:
Juliusz Chroboczek 2021-09-09 22:24:39 +02:00
parent d33e4dea9b
commit f683675ab4
2 changed files with 4 additions and 1 deletions

View File

@ -22,6 +22,7 @@ var UseMDNS bool
var UDPMin, UDPMax uint16
var ErrNotAuthorised = errors.New("not authorised")
var ErrAnonymousNotAuthorised = errors.New("anonymous users not authorised in this group")
type UserError string
@ -966,7 +967,7 @@ func GetDescription(name string) (*Description, error) {
func (desc *Description) GetPermission(group string, c Challengeable) (ClientPermissions, error) {
var p ClientPermissions
if !desc.AllowAnonymous && c.Username() == "" {
return p, UserError("anonymous users not allowed in this group, please choose a username")
return p, ErrAnonymousNotAuthorised
}
if found, good := matchClient(group, c, desc.Op); found {
if good {

View File

@ -1351,6 +1351,8 @@ func handleClientMessage(c *webClient, m clientMessage) error {
} else if err == group.ErrNotAuthorised {
s = "not authorised"
time.Sleep(200 * time.Millisecond)
} else if err == group.ErrAnonymousNotAuthorised {
s = "please choose a username"
} else if e, ok := err.(group.UserError); ok {
s = string(e)
} else {