From 9c96dd6a8bef0d70023d4eaee748916088707765 Mon Sep 17 00:00:00 2001 From: Jan Christophersen Date: Sat, 19 Dec 2015 22:59:41 +0100 Subject: using the logout functionality. diff --git a/main.go b/main.go index 863dd3a..c3d8ef6 100644 --- a/main.go +++ b/main.go @@ -13,9 +13,19 @@ import ( ) var renderer *frontend.Renderer +var charakterin *login.Charakterin func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { - renderer.RenderPage("index", w, make(map[string]interface{})) + user, err := charakterin.GetUserFromRequest(r) + if err != nil { + http.Redirect(w, r, "/login", 302) + return + } + + data := make(map[string]interface{}) + + data["username"] = user.GetName() + renderer.RenderPage("index", w, data) } func main() { @@ -27,16 +37,17 @@ func main() { if err := db.Ping(); err != nil { log.Fatal(err) } - + log.Println("database connection established") renderer = frontend.New("views") - charakterin := login.New(db) + charakterin = login.New(db) charakterin.UseRenderer(renderer) router := httprouter.New() router.HandlerFunc("GET", "/login", charakterin.DisplayLogin) router.HandlerFunc("POST", "/login", charakterin.Login) + router.HandlerFunc("GET", "/logout", charakterin.Logout) router.GET("/", index) fs := http.FileServer(http.Dir("assets")) diff --git a/views/index.html b/views/index.html index fd8c87f..81c801f 100644 --- a/views/index.html +++ b/views/index.html @@ -1,43 +1,33 @@ {{ define "index" }} - + {{ template "materialize" }} grilist - -
-
-

grilist
#tamtam

-
+ +
+
+

grilist#tamtam

+ + Ausloggen +
-- cgit v0.10.1