Exemplo n.º 1
0
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]
}
Exemplo n.º 2
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
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
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)
}
Exemplo n.º 5
0
func GetCSRF(r *http.Request) string {
	return cook.Get(r, "C")
}
Exemplo n.º 6
0
func GetAll(r *http.Request) map[string]string {
	return toMap(cook.Get(r, "SESS-D"))
}
Exemplo n.º 7
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)
}