Exemple #1
0
func (sm *MemSessionManager) Store(c *peony.Controller, s *peony.Session) {
	sm.saveSession(s)
	cookie := &http.Cookie{
		Name:     "PEONY_SESSIONID",
		HttpOnly: CookieSecure,
		Secure:   CookieHttpOnly,
		Value:    s.GetId(),
		Path:     "/",
		Expires:  time.Now().Add(time.Duration(SessionTimeout) * time.Minute).UTC(),
	}
	http.SetCookie(c.Resp, cookie)
}
Exemple #2
0
func (sm *MemSessionManager) saveSession(session *peony.Session) {
	sm.mtx.Lock()
	defer sm.mtx.Unlock()
	it := sm.sessions[session.GetId()]
	if it == nil {
		it = &item{}
		wrap := &sessionWrap{Session: session}
		el := sm.list.PushBack(wrap)
		it.elem = el
		it.wrap = wrap
		sm.sessions[session.GetId()] = it
	} else {
		sm.list.MoveToBack(it.elem)
	}
	it.wrap.lastAccess = time.Now().Unix()
}