mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
Redirect to correct summary page if interval cookie is set
This adds an additional 302 redirect when the user doesn't specify an `interval` as a query param, but has the `wakapi_summary_interval` cookie set.
This commit is contained in:
parent
ebe1836ac6
commit
97fab3e109
|
@ -45,13 +45,16 @@ func (h *SummaryHandler) GetIndex(w http.ResponseWriter, r *http.Request) {
|
||||||
rawQuery := r.URL.RawQuery
|
rawQuery := r.URL.RawQuery
|
||||||
q := r.URL.Query()
|
q := r.URL.Query()
|
||||||
if q.Get("interval") == "" && q.Get("from") == "" {
|
if q.Get("interval") == "" && q.Get("from") == "" {
|
||||||
|
// If the PersistentIntervalKey cookie is set, redirect to the correct summary page
|
||||||
if intervalCookie, _ := r.Cookie(models.PersistentIntervalKey); intervalCookie != nil {
|
if intervalCookie, _ := r.Cookie(models.PersistentIntervalKey); intervalCookie != nil {
|
||||||
q.Set("interval", intervalCookie.Value)
|
redirectAddress := fmt.Sprintf("%s/summary?interval=%s", h.config.Server.BasePath, intervalCookie.Value)
|
||||||
} else {
|
http.Redirect(w, r, redirectAddress, http.StatusFound)
|
||||||
q.Set("interval", "today")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
q.Set("interval", "today")
|
||||||
r.URL.RawQuery = q.Encode()
|
r.URL.RawQuery = q.Encode()
|
||||||
} else if q.Get("interval") != "" {
|
} else if q.Get("interval") != "" {
|
||||||
|
// Send a Set-Cookie header to persist the interval
|
||||||
headerValue := fmt.Sprintf("%s=%s", models.PersistentIntervalKey, q.Get("interval"))
|
headerValue := fmt.Sprintf("%s=%s", models.PersistentIntervalKey, q.Get("interval"))
|
||||||
w.Header().Add("Set-Cookie", headerValue)
|
w.Header().Add("Set-Cookie", headerValue)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user