This commit is contained in:
Stephen McQuay 2013-02-21 00:19:38 -08:00
parent e2d1c76142
commit bc53e1a1ff
2 changed files with 13 additions and 7 deletions

View File

@ -5,13 +5,19 @@ import (
"net/http" "net/http"
) )
func homeHandler(c http.ResponseWriter, req *http.Request) { func homeHandler(w http.ResponseWriter, req *http.Request) {
log.Printf("%v\n", req.URL) session, _ := store.Get(req, "creds")
T("index.html").Execute(c, map[string]interface{}{}) loggedIn := session.Values["logged in"]
if loggedIn == nil {
http.Redirect(w, req, "/login", http.StatusSeeOther)
}
T("index.html").Execute(w, map[string]interface{}{})
} }
func loginHandler(c http.ResponseWriter, req *http.Request) { func loginHandler(w http.ResponseWriter, req *http.Request) {
pwAttempt := req.FormValue("passwd") pwAttempt := req.FormValue("passwd")
// if pw matches, set session.Values["logged in"], then redirect to "/"
// else come back here..
log.Printf("%v\n", pwAttempt) log.Printf("%v\n", pwAttempt)
T("login.html").Execute(c, map[string]interface{}{}) T("login.html").Execute(w, map[string]interface{}{})
} }

View File

@ -20,6 +20,6 @@ func T(name string) *template.Template {
"templates/_base.html", "templates/_base.html",
filepath.Join(*template_dir, name), filepath.Join(*template_dir, name),
)) ))
cachedTemplates[name] = t cachedTemplates[name] = t
return t return t
} }