From 09d61aa5c71c4ad2679579c71e318fb15506821d Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 21 Aug 2022 15:56:41 -0700 Subject: [PATCH] Reserved Usernames on Signup --- pkg/config/config.go | 11 ++++++++++- pkg/controller/account/signup.go | 9 +++++++++ web/templates/account/settings.html | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 36fcc6a..e79b586 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -59,7 +59,16 @@ const ( ) var ( - UsernameRegexp = regexp.MustCompile(`^[a-z0-9_-]{3,32}$`) + UsernameRegexp = regexp.MustCompile(`^[a-z0-9_-]{3,32}$`) + ReservedUsernames = []string{ + "admin", + "admins", + "administrator", + "moderator", + "support", + "staff", + "nonshy", + } ) // Photo Galleries diff --git a/pkg/controller/account/signup.go b/pkg/controller/account/signup.go index 188e1b5..d4cdac7 100644 --- a/pkg/controller/account/signup.go +++ b/pkg/controller/account/signup.go @@ -86,6 +86,15 @@ func Signup() http.HandlerFunc { return } + // Reserved username check. + for _, cmp := range config.ReservedUsernames { + if username == cmp { + session.FlashError(w, r, "That username is reserved, please choose a different username.") + templates.Redirect(w, r.URL.Path+"?token="+tokenStr) + return + } + } + // Cache username in case of passwd validation errors. vars["Email"] = email vars["Username"] = username diff --git a/web/templates/account/settings.html b/web/templates/account/settings.html index 73e7eff..6e9d30c 100644 --- a/web/templates/account/settings.html +++ b/web/templates/account/settings.html @@ -230,7 +230,8 @@

Check this box if you are OK seeing explicit content on this site, which may - include erections or sexually charged content. + include erections or sexually charged content. These may appear on the Site + Gallery as well as user profile pages.