예제 #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)
	}
}