func Authorized(w http.ResponseWriter, r *http.Request) (string, bool) { m := toMap(cook.Get(r, "SESS-D")) if m == nil || m["ROLE"] == "" { return "", false } cookie := cook.FreshCookie("SESS-D", toString(m), SessDur()) cook.PutCookie(w, &cookie) return m["ROLE"], true }
func Login(w http.ResponseWriter, r *http.Request, role string) { if role == "" { return } m := toMap(cook.Get(r, "SESS-D")) if m == nil { m = make(map[string]string) } if _, ok := m["ROLE"]; ok { return } m["ROLE"] = role cookie := cook.FreshCookie("SESS-D", toString(m), SessDur()) cook.PutCookie(w, &cookie) }
func Put(w http.ResponseWriter, r *http.Request, name, val string) { m := toMap(cook.Get(r, "SESS-D")) m[name] = val cookie := cook.FreshCookie("SESS-D", toString(m), SessDur()) cook.PutCookie(w, &cookie) }