Beispiel #1
0
func Start(ctx *web.Context, handler *MHandler) *Session {
	session := new(Session)
	session.handler = handler
	session.handler.Clean()
	old := false
	if ctx.Cookies != nil {
		if id, exists := ctx.Cookies["bloody_sess"]; exists {
			session.id = id
			old = true
		}
	}
	if !old {
		// Starts new session
		session.generateId()
		session.handler.Store(session.GetID(), nil)
	}
	rt := session.handler.Retrieve(session.GetID())
	json.Unmarshal(rt.SessionData, &session.Data)
	if session.Data == nil {
		t := make(map[string]interface{})
		session.Data = t
	}
	ctx.SetCookie("bloody_sess", session.GetID(), time.Now().Unix()+3600)
	return session
}
Beispiel #2
0
func update(ctx *web.Context) {
	if ctx.Params["submit"] == "Delete" {
		ctx.SetCookie(web.NewCookie(cookieName, "", -1))
	} else {
		ctx.SetCookie(web.NewCookie(cookieName, ctx.Params["cookie"], 0))
	}
	ctx.Redirect(301, "/")
}