示例#1
0
// Returns nil if there is no session user
func OfSession(session *view.Session) (userDoc interface{}) {
	if session.User != nil {
		return session.User
	}
	id, ok := session.ID()
	if !ok {
		return nil
	}
	userDoc, _, _ = FindByID(id)
	session.User = userDoc
	return userDoc
}
示例#2
0
func Logout(session *view.Session) {
	session.DeleteID()
	session.User = nil
}
示例#3
0
func Login(session *view.Session, userDoc interface{}) {
	session.SetID(userDoc.(mongo.Document).ObjectId().Hex())
	session.User = userDoc
}