Session

package revel

// A signed cookie (and thus limited to 4kb in size).
// Restriction: Keys may not have a colon in them.
type Session map[string]string

const (
    SESSION_ID_KEY = "_ID"
    TS_KEY         = "_TS"
)

// Return a UUID identifying this session.
func (s Session) Id() string {
    if uuidStr, ok := s[SESSION_ID_KEY]; ok {
        return uuidStr
    }

    uuid, err := simpleuuid.NewTime(time.Now())
    if err != nil {
        panic(err) // I don't think this can actually happen.
    }
    s[SESSION_ID_KEY] = uuid.String()
    return s[SESSION_ID_KEY]
}

func SessionFilter(c *Controller, fc []Filter) {
    c.Session = restoreSession(c.Request.Request)
    // Make session vars available in templates as 
    c.RenderArgs["session"] = c.Session

    fc[0](c, fc[1:])

    // Store the session (and sign it).
    c.SetCookie(c.Session.cookie())
}