Add reference entry to user registration Fix admin commands
alex wennerberg alex@alexwennerberg.com
Mon, 23 Nov 2020 19:34:06 -0800
6 files changed,
18 insertions(+),
8 deletions(-)
M
admin.go
→
admin.go
@@ -23,18 +23,18 @@ if len(args) < 3 {
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) }
M
http.go
→
http.go
@@ -363,8 +363,9 @@ if !isOkUsername(username) {
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")
M
main.go
→
main.go
@@ -40,6 +40,7 @@ Email string
Active bool Admin bool CreatedAt int // timestamp + Reference string } // returns in a random order@@ -67,14 +68,14 @@ return dest, nil
} 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 @@ id INTEGER PRIMARY KEY NOT NULL,
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'))
M
templates/admin.html
→
templates/admin.html
@@ -9,6 +9,7 @@ <summary><b>{{.Username}}</b> {{if not .Active}}<em>(inactive)</em>{{end}}</summary>
<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">
M
templates/register.html
→
templates/register.html
@@ -23,6 +23,8 @@ <div>
<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
M
templates/static/style.css
→
templates/static/style.css
@@ -36,10 +36,14 @@
#editor { width: 100%; border: 1px solid #999999; - width: 100%; margin: 5px 0; padding: 3px; resize: vertical; +} + +.textform { +width: 100%; +resize: vertical; } .button {