forked from saintpete/logrole
/
tz.go
36 lines (32 loc) · 797 Bytes
/
tz.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package server
import (
"net/http"
"net/url"
log "github.com/inconshreveable/log15"
"github.com/kevinburke/logrole/services"
)
type tzServer struct {
log.Logger
LocationFinder services.LocationFinder
AllowUnencryptedTraffic bool
}
func (t *tzServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// TODO csrf
if err := r.ParseForm(); err != nil {
t.Warn("Error parsing form on TZ page", "err", err)
http.Redirect(w, r, "/", 302)
return
}
tz := r.PostForm.Get("tz")
ok := t.LocationFinder.SetLocation(w, tz, t.AllowUnencryptedTraffic == false)
if !ok {
t.Warn("Could not set location on request", "loc", tz)
}
g := r.PostForm.Get("g")
u, err := url.Parse(g)
if err == nil {
http.Redirect(w, r, u.Path, 302)
return
}
http.Redirect(w, r, "/", 302)
}