All checks were successful
check / check (push) Successful in 1m53s
/ now checks for an authenticated session: - Authenticated users → 303 redirect to /sources - Unauthenticated users → 303 redirect to /pages/login Removes the old index page template rendering and formatUptime helper (now dead code). Adds tests for both redirect cases.
21 lines
568 B
Go
21 lines
568 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
// HandleIndex returns a handler for the root path that redirects based
|
|
// on authentication state: authenticated users go to /sources (the
|
|
// dashboard), unauthenticated users go to the login page.
|
|
func (s *Handlers) HandleIndex() http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
sess, err := s.session.Get(r)
|
|
if err == nil && s.session.IsAuthenticated(sess) {
|
|
http.Redirect(w, r, "/sources", http.StatusSeeOther)
|
|
return
|
|
}
|
|
|
|
http.Redirect(w, r, "/pages/login", http.StatusSeeOther)
|
|
}
|
|
}
|