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
|
@ -9,4 +9,5 @@ const (
|
|||
Version = "0.0.1 pre-alpha"
|
||||
// Username for the 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