Пример #1
0
// 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
func deleteUser(userID bson.ObjectId) error {
	session, collection := service.Connect(collectionName)
	defer session.Close()

	err := collection.RemoveId(userID)

	return err
}
Пример #4
0
// 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
// 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
// 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
// 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)
	}
}