diff options
author | Jan Christophersen <jan@ruken.pw> | 2015-12-19 21:59:41 (UTC) |
---|---|---|
committer | Jan Christophersen <jan@ruken.pw> | 2015-12-19 21:59:41 (UTC) |
commit | 9c96dd6a8bef0d70023d4eaee748916088707765 (patch) | |
tree | 4071fccad33568eef5ef7f9981b44fdf792db415 /main.go | |
parent | 173a7213b19665ce0bccfb0f97c1606d95f52c46 (diff) |
using the logout functionality.
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -13,9 +13,19 @@ import ( | |||
13 | ) | 13 | ) |
14 | 14 | ||
15 | var renderer *frontend.Renderer | 15 | var renderer *frontend.Renderer |
16 | var charakterin *login.Charakterin | ||
16 | 17 | ||
17 | func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | 18 | func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { |
18 | renderer.RenderPage("index", w, make(map[string]interface{})) | 19 | user, err := charakterin.GetUserFromRequest(r) |
20 | if err != nil { | ||
21 | http.Redirect(w, r, "/login", 302) | ||
22 | return | ||
23 | } | ||
24 | |||
25 | data := make(map[string]interface{}) | ||
26 | |||
27 | data["username"] = user.GetName() | ||
28 | renderer.RenderPage("index", w, data) | ||
19 | } | 29 | } |
20 | 30 | ||
21 | func main() { | 31 | func main() { |
@@ -27,16 +37,17 @@ func main() { | |||
27 | if err := db.Ping(); err != nil { | 37 | if err := db.Ping(); err != nil { |
28 | log.Fatal(err) | 38 | log.Fatal(err) |
29 | } | 39 | } |
30 | 40 | ||
31 | log.Println("database connection established") | 41 | log.Println("database connection established") |
32 | 42 | ||
33 | renderer = frontend.New("views") | 43 | renderer = frontend.New("views") |
34 | charakterin := login.New(db) | 44 | charakterin = login.New(db) |
35 | charakterin.UseRenderer(renderer) | 45 | charakterin.UseRenderer(renderer) |
36 | 46 | ||
37 | router := httprouter.New() | 47 | router := httprouter.New() |
38 | router.HandlerFunc("GET", "/login", charakterin.DisplayLogin) | 48 | router.HandlerFunc("GET", "/login", charakterin.DisplayLogin) |
39 | router.HandlerFunc("POST", "/login", charakterin.Login) | 49 | router.HandlerFunc("POST", "/login", charakterin.Login) |
50 | router.HandlerFunc("GET", "/logout", charakterin.Logout) | ||
40 | router.GET("/", index) | 51 | router.GET("/", index) |
41 | 52 | ||
42 | fs := http.FileServer(http.Dir("assets")) | 53 | fs := http.FileServer(http.Dir("assets")) |