| 1 | package movement |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | |
| 6 | "github.com/carlosframework/rastrillo/auth" |
| 7 | "github.com/carlosframework/rastrillo/db" |
| 8 | "github.com/carlosframework/rastrillo/mail" |
| 9 | ) |
| 10 | |
| 11 | // app holds what every handler needs. |
| 12 | // |
| 13 | // There is no logger field, and that is deliberate: a handler holds the |
| 14 | // request, so a logger within reach of one is a logger within reach of an |
| 15 | // address and a stance. Handlers call logging.go's typed helpers instead. |
| 16 | type app struct { |
| 17 | db *db.DB |
| 18 | env Env |
| 19 | |
| 20 | // challengeKey is derived from the instance key with its own label, so a |
| 21 | // seal minted here can never verify inside rastrillo/auth and vice versa. |
| 22 | challengeKey []byte |
| 23 | |
| 24 | mailer mail.Sender |
| 25 | |
| 26 | // auth is nil when MOVEMENT_ADMINS is empty: with no allowlist there is |
| 27 | // no admin surface to sign in to, and none of its routes are mounted. |
| 28 | auth *auth.Auth |
| 29 | } |
| 30 | |
| 31 | // choice is one of the three positions as the landing page offers it. |
| 32 | type choice struct { |
| 33 | Slug string |
| 34 | Label string |
| 35 | } |
| 36 | |
| 37 | func (a *app) index(w http.ResponseWriter, r *http.Request) { |
| 38 | choices := make([]choice, 0, len(Stances)) |
| 39 | for _, s := range Stances { |
| 40 | choices = append(choices, choice{ |
| 41 | Slug: s.Slug(), |
| 42 | Label: T("stance." + string(s) + ".label"), |
| 43 | }) |
| 44 | } |
| 45 | render(w, "index", map[string]any{ |
| 46 | "Lede": Linked("index.lede"), |
| 47 | "Choices": choices, |
| 48 | }) |
| 49 | } |
| 50 | |