diff --git a/config.yml.sample b/config.yml.sample index 1330486d995..acd6f1c977f 100644 --- a/config.yml.sample +++ b/config.yml.sample @@ -22,6 +22,8 @@ service: motd: "" # Enable sharing of lists via a link enablelinksharing: true + # Whether to let new users registering themselves or not + enableregistration: true database: # Database type to use. Supported types are mysql and sqlite. diff --git a/docs/content/doc/setup/config.md b/docs/content/doc/setup/config.md index f97360758c9..b32dc210395 100644 --- a/docs/content/doc/setup/config.md +++ b/docs/content/doc/setup/config.md @@ -65,6 +65,8 @@ service: motd: "" # Enable sharing of lists via a link enablelinksharing: true + # Whether to let new users registering themselves or not + enableregistration: true database: # Database type to use. Supported types are mysql and sqlite. diff --git a/go.mod b/go.mod index f22c264bd14..b1a8ffc57f0 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/c2h5oh/datasize v0.0.0-20171227191756-4eba002a5eae github.com/client9/misspell v0.3.4 github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect + github.com/cweill/gotests v1.5.3 github.com/d4l3k/messagediff v1.2.1 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835 @@ -78,7 +79,6 @@ require ( golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d // indirect google.golang.org/appengine v1.5.0 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect - gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/d4l3k/messagediff.v1 v1.2.1 gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df gopkg.in/testfixtures.v2 v2.5.3 diff --git a/go.sum b/go.sum index f591dffc178..f88cb8a669c 100644 --- a/go.sum +++ b/go.sum @@ -35,6 +35,8 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cweill/gotests v1.5.3 h1:k3t4wW/x/YNixWZJhUIn+mivmK5iV1tJVOwVYkx0UcU= +github.com/cweill/gotests v1.5.3/go.mod h1:XZYOJkGVkCRoymaIzmp9Wyi3rUgfA3oOnkuljYrjFV8= github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U= github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -360,8 +362,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/d4l3k/messagediff.v1 v1.2.1 h1:70AthpjunwzUiarMHyED52mj9UwtAnE89l1Gmrt3EU0= gopkg.in/d4l3k/messagediff.v1 v1.2.1/go.mod h1:EUzikiKadqXWcD1AzJLagx0j/BeeWGtn++04Xniyg44= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= diff --git a/pkg/config/config.go b/pkg/config/config.go index 6d3adb67ee6..bd6db5cbcdc 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -33,15 +33,16 @@ type Key string // These constants hold all config value keys const ( - ServiceJWTSecret Key = `service.JWTSecret` - ServiceInterface Key = `service.interface` - ServiceFrontendurl Key = `service.frontendurl` - ServiceEnableCaldav Key = `service.enablecaldav` - ServiceRootpath Key = `service.rootpath` - ServiceMaxItemsPerPage Key = `service.maxitemsperpage` - ServiceEnableMetrics Key = `service.enablemetrics` - ServiceMotd Key = `service.motd` - ServiceEnableLinkSharing Key = `service.enablelinksharing` + ServiceJWTSecret Key = `service.JWTSecret` + ServiceInterface Key = `service.interface` + ServiceFrontendurl Key = `service.frontendurl` + ServiceEnableCaldav Key = `service.enablecaldav` + ServiceRootpath Key = `service.rootpath` + ServiceMaxItemsPerPage Key = `service.maxitemsperpage` + ServiceEnableMetrics Key = `service.enablemetrics` + ServiceMotd Key = `service.motd` + ServiceEnableLinkSharing Key = `service.enablelinksharing` + ServiceEnableRegistration Key = `service.enableregistration` DatabaseType Key = `database.type` DatabaseHost Key = `database.host` @@ -150,6 +151,7 @@ func InitDefaultConfig() { ServiceEnableMetrics.setDefault(false) ServiceMotd.setDefault("") ServiceEnableLinkSharing.setDefault(true) + ServiceEnableRegistration.setDefault(true) // Database DatabaseType.setDefault("sqlite") diff --git a/pkg/routes/api/v1/info.go b/pkg/routes/api/v1/info.go index ed8e55b126a..7500ae069e8 100644 --- a/pkg/routes/api/v1/info.go +++ b/pkg/routes/api/v1/info.go @@ -24,11 +24,12 @@ import ( ) type vikunjaInfos struct { - Version string `json:"version"` - FrontendURL string `json:"frontend_url"` - Motd string `json:"motd"` - LinkSharingEnabled bool `json:"link_sharing_enabled"` - MaxFileSize string `json:"max_file_size"` + Version string `json:"version"` + FrontendURL string `json:"frontend_url"` + Motd string `json:"motd"` + LinkSharingEnabled bool `json:"link_sharing_enabled"` + MaxFileSize string `json:"max_file_size"` + RegistrationEnabled bool `json:"registration_enabled"` } // Info is the handler to get infos about this vikunja instance @@ -40,10 +41,11 @@ type vikunjaInfos struct { // @Router /info [get] func Info(c echo.Context) error { return c.JSON(http.StatusOK, vikunjaInfos{ - Version: version.Version, - FrontendURL: config.ServiceFrontendurl.GetString(), - Motd: config.ServiceMotd.GetString(), - LinkSharingEnabled: config.ServiceEnableLinkSharing.GetBool(), - MaxFileSize: config.FilesMaxSize.GetString(), + Version: version.Version, + FrontendURL: config.ServiceFrontendurl.GetString(), + Motd: config.ServiceMotd.GetString(), + LinkSharingEnabled: config.ServiceEnableLinkSharing.GetBool(), + MaxFileSize: config.FilesMaxSize.GetString(), + RegistrationEnabled: config.ServiceEnableRegistration.GetBool(), }) } diff --git a/pkg/routes/api/v1/user_add_update.go b/pkg/routes/api/v1/user_add_update.go index 60fdbb8c53e..a20a396af3b 100644 --- a/pkg/routes/api/v1/user_add_update.go +++ b/pkg/routes/api/v1/user_add_update.go @@ -17,6 +17,7 @@ package v1 import ( + "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/models" "code.vikunja.io/web/handler" "github.com/labstack/echo/v4" @@ -35,6 +36,9 @@ import ( // @Failure 500 {object} models.Message "Internal error" // @Router /register [post] func RegisterUser(c echo.Context) error { + if !config.ServiceEnableRegistration.GetBool() { + return echo.ErrNotFound + } // Check for Request Content var datUser *models.APIUserPassword if err := c.Bind(&datUser); err != nil { diff --git a/tools.go b/tools.go index c49501da3c0..f1dec3d6caf 100644 --- a/tools.go +++ b/tools.go @@ -22,7 +22,7 @@ package tools import ( _ "github.com/client9/misspell/cmd/misspell" - _ "github.com/cweill/gotests/..." + _ "github.com/cweill/gotests" _ "github.com/fzipp/gocyclo" _ "github.com/gordonklaus/ineffassign" _ "github.com/swaggo/swag/cmd/swag"