Ejemplo 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
}
Ejemplo 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)
}
Ejemplo 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)
}