Esempio n. 1
0
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
}
Esempio n. 2
0
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)
}
Esempio n. 3
0
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)
}