2013-02-20 21:27:09 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2013-02-21 00:19:38 -08:00
|
|
|
func homeHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
|
session, _ := store.Get(req, "creds")
|
|
|
|
loggedIn := session.Values["logged in"]
|
|
|
|
if loggedIn == nil {
|
|
|
|
http.Redirect(w, req, "/login", http.StatusSeeOther)
|
|
|
|
}
|
|
|
|
T("index.html").Execute(w, map[string]interface{}{})
|
2013-02-20 21:27:09 -08:00
|
|
|
}
|
|
|
|
|
2013-02-21 00:19:38 -08:00
|
|
|
func loginHandler(w http.ResponseWriter, req *http.Request) {
|
2013-02-20 21:27:09 -08:00
|
|
|
pwAttempt := req.FormValue("passwd")
|
2013-02-26 22:30:23 -08:00
|
|
|
if check_password(*passes_file, pwAttempt) {
|
|
|
|
session, _ := store.Get(req, "creds")
|
|
|
|
session.Values["logged in"] = true
|
|
|
|
session.Save(req, w)
|
2013-02-21 00:36:32 -08:00
|
|
|
http.Redirect(w, req, "/", http.StatusSeeOther)
|
2013-02-26 22:30:23 -08:00
|
|
|
return
|
|
|
|
}
|
2013-02-21 00:19:38 -08:00
|
|
|
T("login.html").Execute(w, map[string]interface{}{})
|
2013-02-20 21:27:09 -08:00
|
|
|
}
|
2013-02-26 22:39:26 -08:00
|
|
|
|
|
|
|
func logoutHandler(w http.ResponseWriter, req *http.Request) {
|
2013-02-26 23:19:21 -08:00
|
|
|
session, _ := store.Get(req, "creds")
|
|
|
|
delete(session.Values, "logged in")
|
|
|
|
session.Save(req, w)
|
|
|
|
http.Redirect(w, req, "/", http.StatusSeeOther)
|
|
|
|
return
|
2013-02-26 22:39:26 -08:00
|
|
|
}
|