templates cleanup

This commit is contained in:
stryan 2020-09-17 16:47:17 -04:00
parent 8e8781b06b
commit b184d456ea
3 changed files with 37 additions and 11 deletions

34
main.go
View File

@ -21,7 +21,18 @@ func signupPage(res http.ResponseWriter, req *http.Request) {
if u != "" {
http.Redirect(res, req, "/", 302)
} else {
tpl.ExecuteTemplate(res, "register", nil)
data := struct {
Title string
Username string
ShowLogin bool
ShowLogout bool
}{
"Register",
"Unregistered",
false,
false,
}
tpl.ExecuteTemplate(res, "register", data)
}
return
}
@ -55,7 +66,18 @@ func loginPage(res http.ResponseWriter, req *http.Request) {
if u != "" {
http.Redirect(res, req, "/", 302)
} else {
tpl.ExecuteTemplate(res, "login", nil)
data := struct {
Title string
Username string
ShowLogin bool
ShowLogout bool
}{
"Login",
"Unregistered",
true,
false,
}
tpl.ExecuteTemplate(res, "login", data)
}
return
}
@ -86,11 +108,15 @@ func homePage(res http.ResponseWriter, req *http.Request) {
uname = u
}
data := struct {
Title string
Username string
Title string
Username string
ShowLogin bool
ShowLogout bool
}{
"Index",
uname,
true,
true,
}
tpl.ExecuteTemplate(res, "index", data)

View File

@ -4,11 +4,12 @@
<head>
<title>GuildGate</title>
</head>
<h1>Guild Gate: {{.Title}}</h1>
<body>
<nav>
<li>Logged in as: {{.Username}}
<!-- <li><a href="/">Home</a></li>
<li><a href="/login">Login</a></li>
<li><a href="/logout">Logout</a></li>--!>
<div style="overflow: hidden;">
<p style="float: left;">Logged in as: {{.Username}}</p>
<p style="float: right;"><a href="/">Home</a> {{if .ShowLogin}}<a href="/login">Login</a> {{end}}{{if .ShowLogout}}<a href="/logout">Logout</a>{{end}}</p>
</div>
</nav>
{{end}}

View File

@ -1,7 +1,6 @@
{{ define "index" }}
{{ template "header" .}}
<a href="/register">Register</a>
<a href="/login">Login</a>
<a href="/token">Get Token</a>
<p><a href="/register">Register</a></p>
<p><a href="/token">Get Token</a></p>
{{template "footer" .}}
{{ end }}