+6
appview/auth/auth.go
+6
appview/auth/auth.go
···
127
return s.Status
128
}
129
130
+
func (a *Auth) ClearSession(r *http.Request, w http.ResponseWriter) error {
131
+
clientSession, _ := a.Store.Get(r, appview.SessionName)
132
+
clientSession.Options.MaxAge = -1
133
+
return clientSession.Save(r, w)
134
+
}
135
+
136
func (a *Auth) StoreSession(r *http.Request, w http.ResponseWriter, atSessionish Sessionish, pdsEndpoint string) error {
137
clientSession, _ := a.Store.Get(r, appview.SessionName)
138
clientSession.Values[appview.SessionHandle] = atSessionish.GetHandle()
+4
-1
appview/pages/templates/layouts/topbar.html
+4
-1
appview/pages/templates/layouts/topbar.html
···
1
{{ define "layouts/topbar" }}
2
{{ with .LoggedInUser }}
3
-
<nav class="flex items-center justify-center space-x-4 mb-4 py-2 border-b border-l border-r border-black">
4
<a
5
href="/"
6
hx-boost="true"
···
40
>my profile</a
41
>
42
{{ end }}
43
</nav>
44
{{ else }}
45
<a href="/login" class="btn my-2 no-underline">login</a>
···
1
{{ define "layouts/topbar" }}
2
{{ with .LoggedInUser }}
3
+
<nav
4
+
class="flex items-center justify-center space-x-4 mb-4 py-2 border-b border-l border-r border-black"
5
+
>
6
<a
7
href="/"
8
hx-boost="true"
···
42
>my profile</a
43
>
44
{{ end }}
45
+
<button hx-get="/logout" class="btn">logout</a>
46
</nav>
47
{{ else }}
48
<a href="/login" class="btn my-2 no-underline">login</a>
+7
appview/state/state.go
+7
appview/state/state.go
···
150
}
151
}
152
153
func (s *State) Timeline(w http.ResponseWriter, r *http.Request) {
154
user := s.auth.GetUser(r)
155
s.pages.Timeline(w, pages.TimelineParams{
···
728
r.Handle("/static/*", s.pages.Static())
729
730
r.Get("/", s.Timeline)
731
732
r.Get("/login", s.Login)
733
r.Post("/login", s.Login)
···
150
}
151
}
152
153
+
func (s *State) Logout(w http.ResponseWriter, r *http.Request) {
154
+
s.auth.ClearSession(r, w)
155
+
s.pages.HxRedirect(w, "/")
156
+
}
157
+
158
func (s *State) Timeline(w http.ResponseWriter, r *http.Request) {
159
user := s.auth.GetUser(r)
160
s.pages.Timeline(w, pages.TimelineParams{
···
733
r.Handle("/static/*", s.pages.Static())
734
735
r.Get("/", s.Timeline)
736
+
737
+
r.Get("/logout", s.Logout)
738
739
r.Get("/login", s.Login)
740
r.Post("/login", s.Login)