示例#1
0
文件: dbstore.go 项目: coddo/gost
// DeleteCookie deletes a cookie from the cookie storage
func (store *DatabaseCookieStore) DeleteCookie(cookie *Session) error {
	session, collection := service.Connect(store.location)
	defer session.Close()

	err := collection.Remove(bson.M{"token": cookie.Token})
	return err
}
示例#2
0
// DeleteTransaction removes a Transaction from the database
func DeleteTransaction(transactionID bson.ObjectId) error {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	err := collection.RemoveId(transactionID)

	return err
}
示例#3
0
文件: user_test.go 项目: coddo/gost
func deleteUser(userID bson.ObjectId) error {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	err := collection.RemoveId(userID)

	return err
}
示例#4
0
文件: dbstore.go 项目: coddo/gost
// ReadCookie fetches a cookie from the cookie store
func (store *DatabaseCookieStore) ReadCookie(key string) (*Session, error) {
	session, collection := service.Connect(store.location)
	defer session.Close()

	cookie := Session{}
	err := collection.Find(bson.M{"token": key}).One(&cookie)

	return &cookie, err
}
示例#5
0
// GetAllTransactionsLimited retrieves the first X Transaction entities from the database, where X is the specified limit
func GetAllTransactionsLimited(limit int) ([]dbmodels.Transaction, error) {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	var transactions []dbmodels.Transaction
	err := collection.Find(bson.M{}).Limit(limit).All(&transactions)

	return transactions, err
}
示例#6
0
// GetTransaction retrieves an Transaction from the database, based on its ID
func GetTransaction(transactionID bson.ObjectId) (*dbmodels.Transaction, error) {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	transaction := dbmodels.Transaction{}
	err := collection.FindId(transactionID).One(&transaction)

	return &transaction, err
}
示例#7
0
文件: user.go 项目: coddo/gost
// GetUserByEmail retrieves an ApplicationUser from the database, based on its email address
func GetUserByEmail(emailAddress string) (*ApplicationUser, error) {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	var user = ApplicationUser{}
	var err = collection.Find(bson.M{"email": emailAddress}).One(&user)

	return &user, err
}
示例#8
0
文件: user.go 项目: coddo/gost
// GetUserByResetPasswordToken retrieves an ApplicationUser from the database, based on its reset password token
func GetUserByResetPasswordToken(token string) (*ApplicationUser, error) {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	var user = ApplicationUser{}
	var err = collection.Find(bson.M{"resetPasswordToken": token}).One(&user)

	return &user, err
}
示例#9
0
文件: user.go 项目: coddo/gost
// GetUserByActivationToken retrieves an ApplicationUser from the database, based on its account activation token
func GetUserByActivationToken(token string) (*ApplicationUser, error) {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	var user = ApplicationUser{}
	var err = collection.Find(bson.M{"activateAccountToken": token}).One(&user)

	return &user, err
}
示例#10
0
文件: user.go 项目: coddo/gost
// GetUser retrieves an ApplicationUser from the database, based on its ID
func GetUser(userID bson.ObjectId) (*ApplicationUser, error) {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	var user = ApplicationUser{}
	var err = collection.FindId(userID).One(&user)

	return &user, err
}
示例#11
0
文件: dbstore.go 项目: coddo/gost
// GetAllUserCookies returns all the cookies that a certain user has
func (store *DatabaseCookieStore) GetAllUserCookies(userID bson.ObjectId) ([]*Session, error) {
	session, collection := service.Connect(store.location)
	defer session.Close()

	var userSessions []*Session
	err := collection.Find(bson.M{"userID": userID}).All(&userSessions)

	return userSessions, err
}
示例#12
0
文件: dbstore.go 项目: coddo/gost
// WriteCookie writes a cookie in the cookie store. If that cookie already exists,
// it is overwritten
func (store *DatabaseCookieStore) WriteCookie(cookie *Session) error {
	session, collection := service.Connect(store.location)
	defer session.Close()

	err := collection.UpdateId(cookie.ID, cookie)
	if err == mgo.ErrNotFound {
		err = collection.Insert(cookie)
	}

	return err
}
示例#13
0
文件: user.go 项目: coddo/gost
// UpdateUser updates an existing ApplicationUser in the database
func UpdateUser(user *ApplicationUser) error {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	if user.ID == "" {
		return service.ErrNoIDSpecified
	}

	var err = collection.UpdateId(user.ID, user)

	return err
}
示例#14
0
// CreateTransaction adds a new Transaction to the database
func CreateTransaction(transaction *dbmodels.Transaction) error {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	if transaction.ID == "" {
		transaction.ID = bson.NewObjectId()
	}

	err := collection.Insert(transaction)

	return err
}
示例#15
0
// UpdateTransaction updates an existing Transaction in the database
func UpdateTransaction(transaction *dbmodels.Transaction) error {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	if transaction.ID == "" {
		return service.ErrNoIDSpecified
	}

	err := collection.UpdateId(transaction.ID, transaction)

	return err
}
示例#16
0
文件: user.go 项目: coddo/gost
// CreateUser adds a new ApplicationUser to the database
func CreateUser(user *ApplicationUser) error {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	if user.ID == "" {
		user.ID = bson.NewObjectId()
	}

	var err = collection.Insert(user)

	return err
}
示例#17
0
文件: dbstore.go 项目: coddo/gost
// Init initializes the cookie store
func (store *DatabaseCookieStore) Init() {
	session, collection := service.Connect(store.location)
	defer session.Close()
	session.SetMode(mgo.Monotonic, true)

	if store.hasTokenIndex(collection) {
		return
	}

	index := mgo.Index{
		Key: []string{"$text:token"},
	}

	err := collection.EnsureIndex(index)
	if err != nil {
		panic(err)
	}
}