From c3d1d097d8ec9c378a7601efb4ab3f602eec10f9 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 22 Sep 2020 14:00:43 -0400 Subject: [PATCH] we know if a user is logger in so use it --- main.go | 38 ++++++++++++++++---------------------- templates/header.html | 2 +- templates/index.html | 5 ++++- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/main.go b/main.go index f52a51a..d70e2c5 100644 --- a/main.go +++ b/main.go @@ -22,15 +22,13 @@ func signupPage(res http.ResponseWriter, req *http.Request) { http.Redirect(res, req, "/", 302) } else { data := struct { - Title string - Username string - ShowLogin bool - ShowLogout bool + Title string + Username string + LoggedIn bool }{ "Register", "Unregistered", false, - false, } tpl.ExecuteTemplate(res, "register", data) } @@ -71,14 +69,12 @@ func loginPage(res http.ResponseWriter, req *http.Request) { http.Redirect(res, req, "/", 302) } else { data := struct { - Title string - Username string - ShowLogin bool - ShowLogout bool + Title string + Username string + LoggedIn bool }{ "Login", "Unregistered", - true, false, } tpl.ExecuteTemplate(res, "login", data) @@ -116,15 +112,13 @@ func tokenPage(res http.ResponseWriter, req *http.Request) { tpl.ExecuteTemplate(res, "error", nil) } data := struct { - Title string - Username string - ShowLogin bool - ShowLogout bool - Token string + Title string + Username string + LoggedIn bool + Token string }{ "Token Generation", u, - false, true, token, } @@ -133,20 +127,20 @@ func tokenPage(res http.ResponseWriter, req *http.Request) { func homePage(res http.ResponseWriter, req *http.Request) { u := getUserName(req) + active := false uname := "Unregistered" if u != "" { uname = u + active = true } data := struct { - Title string - Username string - ShowLogin bool - ShowLogout bool + Title string + Username string + LoggedIn bool }{ "Index", uname, - true, - true, + active, } tpl.ExecuteTemplate(res, "index", data) diff --git a/templates/header.html b/templates/header.html index f9ea387..89f3185 100644 --- a/templates/header.html +++ b/templates/header.html @@ -9,7 +9,7 @@ {{end}} diff --git a/templates/index.html b/templates/index.html index 523f50b..d3d9b14 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,6 +1,9 @@ {{ define "index" }} {{ template "header" .}} -

Register

+{{if .LoggedIn }}

Get Token

+{{else}} +

Register

+{{end}} {{template "footer" .}} {{ end }}