flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit c638731f1fc483ce0e113894b512c5b6468b27f3
parent 161962dc4b3ea854aebdda56410ee5a1524e426f
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon, 23 Nov 2020 19:34:06 -0800

Add reference entry to user registration

Fix admin commands

Diffstat:
Madmin.go | 8++++----
Mhttp.go | 3++-
Mmain.go | 6++++--
Mtemplates/admin.html | 1+
Mtemplates/register.html | 2++
Mtemplates/static/style.css | 6+++++-
6 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/admin.go b/admin.go @@ -23,18 +23,18 @@ func runAdminCommand() { fmt.Println("Expected subcommand with parameter activate-user|delete-user|make-admin") os.Exit(1) } - switch args[0] { + switch args[1] { case "activate-user": - username := args[1] + username := args[2] err := activateUser(username) log.Fatal(err) case "delete-user": - username := args[1] + username := args[2] // TODO add confirmation err := deleteUser(username) log.Fatal(err) case "make-admin": - username := args[1] + username := args[2] err := makeAdmin(username) log.Fatal(err) } diff --git a/http.go b/http.go @@ -363,8 +363,9 @@ func registerHandler(w http.ResponseWriter, r *http.Request) { errors = append(errors, "Username is invalid: can only contain letters, numbers and hypens. Maximum 32 characters.") } hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), 8) // TODO handle error + reference := r.Form.Get("reference") if len(errors) == 0 { - _, err = DB.Exec("insert into user (username, email, password_hash) values ($1, $2, $3)", username, email, string(hashedPassword)) + _, err = DB.Exec("insert into user (username, email, password_hash, reference) values ($1, $2, $3, $4)", username, email, string(hashedPassword), reference) if err != nil { log.Println(err) errors = append(errors, "Username or email is already used") diff --git a/main.go b/main.go @@ -40,6 +40,7 @@ type User struct { Active bool Admin bool CreatedAt int // timestamp + Reference string } // returns in a random order @@ -67,14 +68,14 @@ func getActiveUserNames() ([]string, error) { } func getUsers() ([]User, error) { - rows, err := DB.Query(`SELECT username, email, active, admin, created_at from user ORDER BY created_at DESC`) + rows, err := DB.Query(`SELECT username, email, active, admin, created_at, reference from user ORDER BY created_at DESC`) if err != nil { return nil, err } var users []User for rows.Next() { var user User - err = rows.Scan(&user.Username, &user.Email, &user.Active, &user.Admin, &user.CreatedAt) + err = rows.Scan(&user.Username, &user.Email, &user.Active, &user.Admin, &user.CreatedAt, &user.Reference) if err != nil { return nil, err } @@ -162,6 +163,7 @@ func createTablesIfDNE() { username TEXT NOT NULL UNIQUE, email TEXT NOT NULL UNIQUE, password_hash TEXT NOT NULL, + reference TEXT, active boolean NOT NULL DEFAULT false, admin boolean NOT NULL DEFAULT false, created_at INTEGER DEFAULT (strftime('%s', 'now')) diff --git a/templates/admin.html b/templates/admin.html @@ -9,6 +9,7 @@ <div class="user-admin-details"> <p>Home: <a href="//{{.Username}}.{{$domain}}">{{.Username}}</a> </p> <p>Email: <a href=mailto:{{.Email}}>{{.Email}}</a></p> + <p>Reference: {{.Reference}}</p> {{ if not .Active }} <p> <form action="/admin/user/{{.Username}}/activate" method="POST" class="inline"> diff --git a/templates/register.html b/templates/register.html @@ -23,6 +23,8 @@ <label for="password2">Repeat Password</label> <input id="password2" name="password2" size="55" type="password" value="" /> </div> + <label for="reference">How did you find Flounder? Did an existing user invite you, if so, whom? Could you provide a link to your website or social media?</label> + <textarea id="reference" name="reference" class="textform" cols=4></textarea> <div class="error">{{ range .Errors}}{{.}}<br>{{end}} </div> <div> <input diff --git a/templates/static/style.css b/templates/static/style.css @@ -36,12 +36,16 @@ img { #editor { width: 100%; border: 1px solid #999999; - width: 100%; margin: 5px 0; padding: 3px; resize: vertical; } +.textform { +width: 100%; +resize: vertical; +} + .button { background-color: white; /* Green */ border: 1px solid black;