Esempio n. 1
0
func (d *dalStore) delete(session *gSessions.Session) error {
	if !dal.IsObjectIDHex(session.ID) {
		return nSessions.ErrInvalidId
	}

	conn := d.connection.Clone()
	defer conn.Close()
	db := conn.DB(d.database)
	c := db.C(d.collection)

	return c.RemoveID(dal.ObjectIDHex(session.ID))
}
Esempio n. 2
0
func (d *dalStore) save(session *gSessions.Session) error {
	if !dal.IsObjectIDHex(session.ID) {
		return nSessions.ErrInvalidId
	}

	conn := d.connection.Clone()
	defer conn.Close()
	db := conn.DB(d.database)
	c := db.C(d.collection)

	var modified time.Time
	if val, ok := session.Values["modified"]; ok {
		modified, ok = val.(time.Time)
		if !ok {
			return nSessions.ErrInvalidModified
		}
	} else {
		modified = time.Now()
	}

	encoded, err := securecookie.EncodeMulti(session.Name(), session.Values, d.Codecs...)
	if err != nil {
		return err
	}

	s := dalSession{
		ID:       dal.ObjectIDHex(session.ID),
		Data:     encoded,
		Modified: modified,
	}
	_, err = c.UpsertID(dal.ObjectIDHex(session.ID), &s)
	if err != nil {
		return err
	}

	return nil
}
Esempio n. 3
0
func (d *dalStore) load(session *gSessions.Session) (bool, error) {
	if !dal.IsObjectIDHex(session.ID) {
		return false, nSessions.ErrInvalidId
	}
	conn := d.connection.Clone()
	defer conn.Close()
	db := conn.DB(d.database)
	c := db.C(d.collection)

	s := dalSession{}
	err := c.FindID(dal.ObjectIDHex(session.ID)).One(&s)
	if err != nil {
		return false, err
	}
	if err := securecookie.DecodeMulti(session.Name(), s.Data, &session.Values, d.Codecs...); err != nil {
		return false, err
	}
	return true, nil
}