Esempio n. 1
0
func GetSession(w http.ResponseWriter, r *http.Request) (*session.MySession, error) {
	hmSession, err := session.GetMatchedSession(w, r)
	if err != nil {
		return nil, err
	}
	return hmSession, nil
}
Esempio n. 2
0
func Logout(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	base.Logger().Infoln(request.GetRequestInfo(r))
	hmSession, err := session.GetMatchedSession(w, r)
	if err != nil {
		base.Logger().Errorln("GetSessionErr:", err)
	}
	if hmSession != nil {
		loginName, err := hmSession.Get(session.SESSION_GRANTORS_KEY)
		if err != nil {
			base.Logger().Errorln("GetLoginNameErr:", err)
		}
		done, err := hmSession.Destroy()
		if err != nil {
			base.Logger().Errorln("DestroySessionErr:", err)
		} else {
			base.Logger().Infof("Logout: User '%s' logout. (result=%v)\n", loginName, done)
		}
	} else {
		base.Logger().Infoln("Logout: Current visitor has yet login.\n")
	}
	http.Redirect(w, r, "/", http.StatusFound)
}