forked from tangled.org/core
this repo has no description

add timeline page

we can start clicking links and stuff now

Changed files
+45 -2
routes
templates
+2 -1
routes/handler.go
···
auth: auth,
}
+
r.Get("/", h.Timeline)
+
r.Group(func(r chi.Router) {
-
r.Use(h.AuthMiddleware)
r.Get("/login", h.Login)
r.Post("/login", h.Login)
})
+17 -1
routes/routes.go
···
}
log.Printf("successfully saved session for %s (%s)", atSession.Handle, atSession.Did)
-
http.Redirect(w, r, "/", http.StatusPermanentRedirect)
+
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
}
···
w.WriteHeader(http.StatusOK)
}
}
+
+
func (h *Handle) Timeline(w http.ResponseWriter, r *http.Request) {
+
session, err := h.s.Get(r, "bild-session")
+
user := make(map[string]string)
+
if err != nil || session.IsNew {
+
// user is not logged in
+
} else {
+
user["handle"] = session.Values["handle"].(string)
+
user["did"] = session.Values["did"].(string)
+
}
+
+
if err := h.t.ExecuteTemplate(w, "timeline", user); err != nil {
+
log.Println(err)
+
return
+
}
+
}
+12
templates/layouts/topbar.html
···
+
<nav>
+
<ul>
+
{{ if . }}
+
<li>logged in as
+
<a href="/@{{ .handle }}">{{ .handle }}</a> (with {{ .did }})
+
</li>
+
{{ else }}
+
<li><a href="/login">login</a></li>
+
{{ end }}
+
</ul>
+
</nav>
+
+14
templates/timeline.html
···
+
{{ define "timeline" }}
+
<html>
+
{{ template "layouts/head" . }}
+
+
<header>
+
<h1>timeline</h1>
+
</header>
+
<body>
+
<main>
+
{{ template "layouts/topbar" . }}
+
</main>
+
</body>
+
</html>
+
{{ end }}