Add username validation function for non-scripted actors
This commit is contained in:
parent
087728cfe5
commit
b00f5e9777
2 changed files with 27 additions and 1 deletions
|
@ -8,5 +8,6 @@ const (
|
||||||
// where multiple releases in a day are required
|
// where multiple releases in a day are required
|
||||||
Version = "0.0.1 pre-alpha"
|
Version = "0.0.1 pre-alpha"
|
||||||
// Username for the server actor
|
// Username for the server actor
|
||||||
ServerActorName = "server.actor"
|
ServerActorName = "server.actor"
|
||||||
|
FeedUsernameSuffix = "-feed"
|
||||||
)
|
)
|
||||||
|
|
25
shared/validation.go
Normal file
25
shared/validation.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
package shared
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.mstar.dev/mstar/goutils/sliceutils"
|
||||||
|
)
|
||||||
|
|
||||||
|
var forbiddenUsernames = []string{
|
||||||
|
"server.actor",
|
||||||
|
"feed",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reports whether a given user name is valid (for non-internal systems)
|
||||||
|
//
|
||||||
|
// TODO: Include compat check for Mastodon?
|
||||||
|
func ValidateUsername(username string) bool {
|
||||||
|
if strings.HasSuffix(username, FeedUsernameSuffix) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if sliceutils.Contains(forbiddenUsernames, username) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
Loading…
Reference in a new issue