From 6191847ed58db38917f6590fcb59c9e7c87a0eef Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 11 Feb 2016 01:45:05 +0100 Subject: [PATCH] Disable sign-up by default, enable by new --signup flag. --- README.md | 13 +++++++++---- main.go | 12 ++++++++++++ templates/nosignup.html | 6 ++++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 templates/nosignup.html diff --git a/README.md b/README.md index f28fc00..04e6ba7 100644 --- a/README.md +++ b/README.md @@ -64,17 +64,22 @@ This is [a common privilege problem](http://stackoverflow.com/q/413807) and sudo setcap 'cap_net_bind_service=+ep' $GOPATH/bin/htwtxt -### Changing HTML templates +### Opening up sign-up -By default, HTML templates are read out of `$GOPATH/src/htwtxt/templates/`. An -alternate directory can be given with the flag `--templates` (it should contain -template files of the same names as the default ones, however). +By default, sign up / account creation is not open to the public. The `--signup` +flag must be set explicitely to change that. ### Setting site owner contact info The server serves a `/info` page (from the `info.html` template) that may include the site owner's contact info, as given with the `--info` flag. +### Changing HTML templates + +By default, HTML templates are read out of `$GOPATH/src/htwtxt/templates/`. An +alternate directory can be given with the flag `--templates` (it should contain +template files of the same names as the default ones, however). + ## Copyright, license htwtxt (c) 2016 Christian Heller a.k.a. plomlompom diff --git a/main.go b/main.go index e472345..0c6cdd1 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ var feedsPath string var templPath string var templ *template.Template var contactString string +var signupOpen bool func createFileIfNotExists(path string) { if _, err := os.Stat(path); err != nil { @@ -149,10 +150,19 @@ func infoHandler(w http.ResponseWriter, r *http.Request) { } func signUpFormHandler(w http.ResponseWriter, r *http.Request) { + if !signupOpen { + execTemplate(w, "nosignup.html", "") + return + } execTemplate(w, "signupform.html", "") } func signUpHandler(w http.ResponseWriter, r *http.Request) { + if !signupOpen { + execTemplate(w, "error.html", + "Account creation currently not allowed.") + return + } newLine, err := accountLine(w, r, true) if err != nil { return @@ -268,6 +278,8 @@ func main() { flag.StringVar(&contactString, "contact", "[operator passed no contact info to server]", "operator contact info to display on info page") + flag.BoolVar(&signupOpen, "signup", false, + "enable on-site account creation") flag.Parse() log.Println("Using as templates dir:", templPath) log.Println("Using as data dir:", dataDir) diff --git a/templates/nosignup.html b/templates/nosignup.html new file mode 100644 index 0000000..18192db --- /dev/null +++ b/templates/nosignup.html @@ -0,0 +1,6 @@ +{{ template "header" }} +
+

Account creation closed

+

The site operator has not decided to open up account creation on this site for the public.

+
+{{ template "footer" }}