add register template
alex wennerberg alex@alexwennerberg.com
Thu, 22 Oct 2020 17:18:53 -0700
2 files changed,
51 insertions(+),
2 deletions(-)
M
http.go
→
http.go
@@ -84,7 +84,7 @@ // show page
data := struct { Error string PageTitle string - }{"", c.SiteTitle} + }{"", "Login"} err := t.ExecuteTemplate(w, "login.html", data) if err != nil { log.Println(err)@@ -118,8 +118,19 @@ // check for errors
} } -func register(w http.ResponseWriter, r *http.Request) { +func registerHandler(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { + data := struct { + Domain string + Errors []string + PageTitle string + }{c.RootDomain, nil, "Register"} + err := t.ExecuteTemplate(w, "register.html", data) + if err != nil { + log.Println(err) + renderError(w, InternalServerErrorMsg, 500) + return + } } else if r.Method == "POST" { } }@@ -144,6 +155,7 @@ http.HandleFunc(c.RootDomain+"/", indexHandler)
http.HandleFunc(c.RootDomain+"/my_site", mySiteHandler) http.HandleFunc(c.RootDomain+"/edit/", editFileHandler) http.HandleFunc(c.RootDomain+"/login", loginHandler) + http.HandleFunc(c.RootDomain+"/register", registerHandler) // http.HandleFunc("/delete/", deleteFileHandler) // login+register functions
A
templates/register.html
@@ -0,0 +1,37 @@
+{{template "header" .}} +<h1>Register</h1> +<form action="/register" method="post"> + <div> + <label for="username">Username</label> + <input + id="username" + name="username" + size="32" + type="text" + value="" + />.{{.Domain}} + </div> + <div> + <label for="email">Email</label> + <input id="email" name="email" size="64" type="text" value="" /> + </div> + <div> + <label for="password">Password</label> + <input id="password" name="password" size="32" type="password" value="" /> + </div> + <div> + <label for="password2">Repeat Password</label> + <input id="password2" name="password2" size="32" type="password" value="" /> + </div> + <div class="error">{{ range .Errors}}<p>{{.}}</p>{{end}} </div> + <div> + <input + class="button" + id="submit" + name="submit" + type="submit" + value="Join" + /> + </div> +</form> +{{template "footer" .}}