Disable sign-up by default, enable by new --signup flag.

このコミットが含まれているのは:
Christian Heller 2016-02-11 01:45:05 +01:00
コミット 6191847ed5
3個のファイルの変更27行の追加4行の削除

ファイルの表示

@ -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 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 By default, sign up / account creation is not open to the public. The `--signup`
alternate directory can be given with the flag `--templates` (it should contain flag must be set explicitely to change that.
template files of the same names as the default ones, however).
### Setting site owner contact info ### Setting site owner contact info
The server serves a `/info` page (from the `info.html` template) that may 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. 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 ## Copyright, license
htwtxt (c) 2016 Christian Heller a.k.a. plomlompom htwtxt (c) 2016 Christian Heller a.k.a. plomlompom

12
main.go
ファイルの表示

@ -25,6 +25,7 @@ var feedsPath string
var templPath string var templPath string
var templ *template.Template var templ *template.Template
var contactString string var contactString string
var signupOpen bool
func createFileIfNotExists(path string) { func createFileIfNotExists(path string) {
if _, err := os.Stat(path); err != nil { 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) { func signUpFormHandler(w http.ResponseWriter, r *http.Request) {
if !signupOpen {
execTemplate(w, "nosignup.html", "")
return
}
execTemplate(w, "signupform.html", "") execTemplate(w, "signupform.html", "")
} }
func signUpHandler(w http.ResponseWriter, r *http.Request) { 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) newLine, err := accountLine(w, r, true)
if err != nil { if err != nil {
return return
@ -268,6 +278,8 @@ func main() {
flag.StringVar(&contactString, "contact", flag.StringVar(&contactString, "contact",
"[operator passed no contact info to server]", "[operator passed no contact info to server]",
"operator contact info to display on info page") "operator contact info to display on info page")
flag.BoolVar(&signupOpen, "signup", false,
"enable on-site account creation")
flag.Parse() flag.Parse()
log.Println("Using as templates dir:", templPath) log.Println("Using as templates dir:", templPath)
log.Println("Using as data dir:", dataDir) log.Println("Using as data dir:", dataDir)

6
templates/nosignup.html ノーマルファイル
ファイルの表示

@ -0,0 +1,6 @@
{{ template "header" }}
<section>
<h2>Account creation closed</h2>
<p>The site operator has not decided to open up account creation on this site for the public.</p>
</section>
{{ template "footer" }}