From b3d5587415d2f21be659547f9564c95f26e82fda Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Thu, 25 Mar 2021 20:07:28 +0100 Subject: [PATCH] require account approval flags --- cmd/gotosocial/main.go | 8 +++++++- example/config.yaml | 27 +++++++++++++++++++++++---- internal/config/accounts.go | 7 ++++++- internal/config/config.go | 7 +++++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/cmd/gotosocial/main.go b/cmd/gotosocial/main.go index 173c82d..41837c1 100644 --- a/cmd/gotosocial/main.go +++ b/cmd/gotosocial/main.go @@ -120,9 +120,15 @@ func main() { &cli.BoolFlag{ Name: flagNames.AccountsOpenRegistration, Usage: "Allow anyone to submit an account signup request. If false, server will be invite-only.", - Value: false, + Value: true, EnvVars: []string{envNames.AccountsOpenRegistration}, }, + &cli.BoolFlag{ + Name: flagNames.AccountsRequireApproval, + Usage: "Do account signups require approval by an admin or moderator before user can log in? If false, new registrations will be automatically approved.", + Value: true, + EnvVars: []string{envNames.AccountsRequireApproval}, + }, }, Commands: []*cli.Command{ { diff --git a/example/config.yaml b/example/config.yaml index 58766a2..81e4727 100644 --- a/example/config.yaml +++ b/example/config.yaml @@ -14,10 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -################### -##### CONFIG ###### -################### - +########################### +##### GENERAL CONFIG ###### +########################### # String. Log level to use throughout the application. Must be lower-case. # Options: ["debug","info","warn","error","fatal"] # Default: "info" @@ -39,6 +38,9 @@ host: "localhost" # Default: "https" protocol: "https" +############################ +##### DATABASE CONFIG ###### +############################ # Config pertaining to the Gotosocial database connection db: # String. Database type. @@ -72,9 +74,26 @@ db: # Default: "postgres" database: "postgres" +############################### +##### WEB TEMPLATE CONFIG ##### +############################### # Config pertaining to templating of web pages/email notifications and the like template: # String. Directory from which gotosocial will attempt to load html templates (.tmpl files). # Examples: ["/some/absolute/path/", "./relative/path/", "../../some/weird/path/"] # Default: "./web/template/" baseDir: "./web/template/" + +########################### +##### ACCOUNTS CONFIG ##### +########################### +# Config pertaining to creation and maintenance of accounts on the server, as well as defaults for new accounts. +accounts: + # Bool. Do we want people to be able to just submit sign up requests, or do we want invite only? + # Options: [true, false] + # Default: true + openRegistration: true + # Bool. Do sign up requests require approval from an admin/moderator before an account can sign in/use the server? + # Options: [true, false] + # Default: true + requireApproval: true diff --git a/internal/config/accounts.go b/internal/config/accounts.go index d5be1cb..3fc9e90 100644 --- a/internal/config/accounts.go +++ b/internal/config/accounts.go @@ -18,7 +18,12 @@ package config +// AccountsConfig contains configuration to do with creating accounts, new registrations, and defaults. type AccountsConfig struct { // Do we want people to be able to just submit sign up requests, or do we want invite only? - OpenRegistration bool + OpenRegistration bool `yaml:"openRegistration"` + // Do sign up requests require approval from an admin/moderator? + RequireApproval bool `yaml:"requireApproval"` + // Do we require a reason for a sign up or is an empty string OK? + ReasonRequired bool `yaml:"reasonRequired"` } diff --git a/internal/config/config.go b/internal/config/config.go index 6172de3..a0ec714 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -142,6 +142,10 @@ func (c *Config) ParseCLIFlags(f KeyedFlags) { if f.IsSet(fn.AccountsOpenRegistration) { c.AccountsConfig.OpenRegistration = f.Bool(fn.AccountsOpenRegistration) } + + if f.IsSet(fn.AccountsRequireApproval) { + c.AccountsConfig.RequireApproval = f.Bool(fn.AccountsRequireApproval) + } } // KeyedFlags is a wrapper for any type that can store keyed flags and give them back. @@ -169,6 +173,7 @@ type Flags struct { DbDatabase string TemplateBaseDir string AccountsOpenRegistration string + AccountsRequireApproval string } // GetFlagNames returns a struct containing the names of the various flags used for @@ -188,6 +193,7 @@ func GetFlagNames() Flags { DbDatabase: "db-database", TemplateBaseDir: "template-basedir", AccountsOpenRegistration: "accounts-open-registration", + AccountsRequireApproval: "accounts-require-approval", } } @@ -208,5 +214,6 @@ func GetEnvNames() Flags { DbDatabase: "GTS_DB_DATABASE", TemplateBaseDir: "GTS_TEMPLATE_BASEDIR", AccountsOpenRegistration: "GTS_ACCOUNTS_OPEN_REGISTRATION", + AccountsRequireApproval: "GTS_ACCOUNTS_REQUIRE_APPROVAL", } }