Пример #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)
}
Пример #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()
}
Пример #3
0
//@Mapper("/admin/logout")
func (oc *Operator) Logout(session *peony.Session) peony.Renderer {
	session.Del("operatorId")
	session.Del("operator")
	return peony.Redirect("/admin")
}