Make start on session management
This commit is contained in:
parent
352d9555ba
commit
17dd20478d
4 changed files with 65 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"flag"
|
||||
"log"
|
||||
"net"
|
||||
|
|
@ -16,6 +17,8 @@ import (
|
|||
func main() {
|
||||
var confFile string
|
||||
|
||||
cache := make(map[string]string, 20)
|
||||
|
||||
flag.StringVar(&confFile, "c", "/etc/gonotes/conf.toml", "Specify path to config file.")
|
||||
flag.Parse()
|
||||
|
||||
|
|
@ -33,8 +36,28 @@ func main() {
|
|||
|
||||
etag := middleware.NewETag("static", cacheExpiration)
|
||||
|
||||
if !conf.Conf.Production {
|
||||
router.HandleFunc("/login/", func(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.FormValue("user")
|
||||
log.Printf("Trying to log in %s", user)
|
||||
|
||||
sessionID := rand.Text()
|
||||
cache[sessionID] = user
|
||||
|
||||
// TODO: omg remove this
|
||||
log.Printf("Session id is %s", sessionID)
|
||||
|
||||
cookie := http.Cookie{
|
||||
Name: "id", Value: sessionID, MaxAge: 3600,
|
||||
Secure: true, HttpOnly: true, Path: "/",
|
||||
}
|
||||
http.SetCookie(w, &cookie)
|
||||
http.Redirect(w, r, "/notes/", http.StatusFound)
|
||||
})
|
||||
}
|
||||
|
||||
router.Handle("/", middleware.LoggingMiddleware(http.RedirectHandler("/notes/", http.StatusFound)))
|
||||
router.Handle("/notes/", middleware.LoggingMiddleware(http.StripPrefix("/notes", notesRouter)))
|
||||
router.Handle("/notes/", middleware.SessionMiddleware(cache, middleware.LoggingMiddleware(http.StripPrefix("/notes", notesRouter))))
|
||||
router.Handle(
|
||||
"/static/",
|
||||
middleware.LoggingMiddleware(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue