35 lines
916 B
Go
35 lines
916 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
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{}{})
|
|
}
|
|
|
|
func loginHandler(w http.ResponseWriter, req *http.Request) {
|
|
pwAttempt := req.FormValue("passwd")
|
|
if check_password(*passes_file, pwAttempt) {
|
|
session, _ := store.Get(req, "creds")
|
|
session.Values["logged in"] = true
|
|
session.Save(req, w)
|
|
http.Redirect(w, req, "/", http.StatusSeeOther)
|
|
return
|
|
}
|
|
T("login.html").Execute(w, map[string]interface{}{})
|
|
}
|
|
|
|
func logoutHandler(w http.ResponseWriter, req *http.Request) {
|
|
session, _ := store.Get(req, "creds")
|
|
delete(session.Values, "logged in")
|
|
session.Save(req, w)
|
|
http.Redirect(w, req, "/", http.StatusSeeOther)
|
|
return
|
|
}
|