示例#1
0
文件: session.go 项目: Joinhack/peony
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
文件: session.go 项目: Joinhack/peony
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")
}