func GetFlash(w http.ResponseWriter, r *http.Request) (string, string) { msg := strings.Split(cook.Get(r, "flash"), ":") cook.Delete(w, r, "flash") if len(msg) != 2 { return "", "" } return msg[0], msg[1] }
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 GetCook(w http.ResponseWriter, r *http.Request) { c := r.FormValue("cook") var val string if c == "" { val = "" } else { val = cook.Get(r, r.FormValue("cook")) } fmt.Fprintf(w, "Cookie: %v", val) return }
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 GetCSRF(r *http.Request) string { return cook.Get(r, "C") }
func GetAll(r *http.Request) map[string]string { return toMap(cook.Get(r, "SESS-D")) }
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) }