api: add option to forbid new owner registrations
Closes https://gitlab.com/commento/commento-ce/issues/10
This commit is contained in:
parent
58be6a44b6
commit
9fb33fbd9d
@ -24,6 +24,8 @@ func configParse() error {
|
|||||||
|
|
||||||
"CDN_PREFIX": "",
|
"CDN_PREFIX": "",
|
||||||
|
|
||||||
|
"FORBID_NEW_OWNERS": "false",
|
||||||
|
|
||||||
"STATIC": binPath,
|
"STATIC": binPath,
|
||||||
|
|
||||||
"GZIP_STATIC": "false",
|
"GZIP_STATIC": "false",
|
||||||
@ -53,7 +55,7 @@ func configParse() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mandatory config parameters
|
// Mandatory config parameters
|
||||||
for _, env := range []string{"POSTGRES", "PORT", "ORIGIN"} {
|
for _, env := range []string{"POSTGRES", "PORT", "ORIGIN", "FORBID_NEW_OWNERS"} {
|
||||||
if os.Getenv(env) == "" {
|
if os.Getenv(env) == "" {
|
||||||
logger.Errorf("missing COMMENTO_%s environment variable", env)
|
logger.Errorf("missing COMMENTO_%s environment variable", env)
|
||||||
return errorMissingConfig
|
return errorMissingConfig
|
||||||
@ -64,6 +66,11 @@ func configParse() error {
|
|||||||
os.Setenv("CDN_PREFIX", os.Getenv("ORIGIN"))
|
os.Setenv("CDN_PREFIX", os.Getenv("ORIGIN"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if os.Getenv("FORBID_NEW_OWNERS") != "true" && os.Getenv("FORBID_NEW_OWNERS") != "false" {
|
||||||
|
logger.Errorf("COMMENTO_FORBID_NEW_OWNERS neither 'true' nor 'false'")
|
||||||
|
return errorInvalidConfigValue
|
||||||
|
}
|
||||||
|
|
||||||
static := os.Getenv("STATIC")
|
static := os.Getenv("STATIC")
|
||||||
for strings.HasSuffix(static, "/") {
|
for strings.HasSuffix(static, "/") {
|
||||||
static = static[0 : len(static)-1]
|
static = static[0 : len(static)-1]
|
||||||
|
@ -39,3 +39,5 @@ var errorGzip = errors.New("Cannot GZip content.")
|
|||||||
var errorCannotDownloadDisqus = errors.New("We could not download your Disqus export file.")
|
var errorCannotDownloadDisqus = errors.New("We could not download your Disqus export file.")
|
||||||
var errorSelfVote = errors.New("You cannot vote on your own comment.")
|
var errorSelfVote = errors.New("You cannot vote on your own comment.")
|
||||||
var errorInvalidConfigFile = errors.New("Invalid config file.")
|
var errorInvalidConfigFile = errors.New("Invalid config file.")
|
||||||
|
var errorInvalidConfigValue = errors.New("Invalid config value.")
|
||||||
|
var errorNewOwnerForbidden = errors.New("New user registrations are forbidden and closed.")
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,6 +12,10 @@ func ownerNew(email string, name string, password string) (string, error) {
|
|||||||
return "", errorMissingField
|
return "", errorMissingField
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if os.Getenv("FORBID_NEW_OWNERS") == "true" {
|
||||||
|
return "", errorNewOwnerForbidden
|
||||||
|
}
|
||||||
|
|
||||||
ownerHex, err := randomHex(32)
|
ownerHex, err := randomHex(32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("cannot generate ownerHex: %v", err)
|
logger.Errorf("cannot generate ownerHex: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user