Commit f683675a authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use a dedicated error value for anonymous users.

parent d33e4dea
...@@ -22,6 +22,7 @@ var UseMDNS bool ...@@ -22,6 +22,7 @@ var UseMDNS bool
var UDPMin, UDPMax uint16 var UDPMin, UDPMax uint16
var ErrNotAuthorised = errors.New("not authorised") var ErrNotAuthorised = errors.New("not authorised")
var ErrAnonymousNotAuthorised = errors.New("anonymous users not authorised in this group")
type UserError string type UserError string
...@@ -966,7 +967,7 @@ func GetDescription(name string) (*Description, error) { ...@@ -966,7 +967,7 @@ func GetDescription(name string) (*Description, error) {
func (desc *Description) GetPermission(group string, c Challengeable) (ClientPermissions, error) { func (desc *Description) GetPermission(group string, c Challengeable) (ClientPermissions, error) {
var p ClientPermissions var p ClientPermissions
if !desc.AllowAnonymous && c.Username() == "" { 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 found, good := matchClient(group, c, desc.Op); found {
if good { if good {
......
...@@ -1351,6 +1351,8 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1351,6 +1351,8 @@ func handleClientMessage(c *webClient, m clientMessage) error {
} else if err == group.ErrNotAuthorised { } else if err == group.ErrNotAuthorised {
s = "not authorised" s = "not authorised"
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
} else if err == group.ErrAnonymousNotAuthorised {
s = "please choose a username"
} else if e, ok := err.(group.UserError); ok { } else if e, ok := err.(group.UserError); ok {
s = string(e) s = string(e)
} else { } else {
......
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