Exemplo n.º 1
0
func (us BoltUserStore) GetUsers() StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var userString string
		var user *model.User
		users := []string{}

		result := StoreResult{}

		items, err := us.usersBucket.Items()

		if err != nil {
			result.Err = model.NewAppError("BoltUserStore.GetUsers", err.Error(), "")
			storeChannel <- result
			close(storeChannel)
		}

		for _, item := range items {
			userString = string(item.Value)
			user = model.UserFromJson(strings.NewReader(userString))
			user.Sanitize()
			users = append(users, string(user.ToJson()))
		}

		result.Data = users
		storeChannel <- result
		close(storeChannel)
	}()

	return storeChannel
}
Exemplo n.º 2
0
func (us BoltUserStore) Update(user *model.User) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		result := StoreResult{}

		if len(user.Password) > 0 {
			if user.PasswordConfirmation != user.Password {
				result.Err = model.NewAppError("BoltUserStore.Update", "When update password must be equal to passwordConfirmation", "user_id"+user.Id)
				storeChannel <- result
				close(storeChannel)
			}
		}
		if us.isLoginTaken(user.Login) {
			result.Err = model.NewAppError("BoltUserStore.Save", "User Login already taken", "user_login="+user.Login)
			storeChannel <- result
			close(storeChannel)
			return
		}

		user.PreSave()
		userJson := user.ToJson()
		us.usersBucket.Put([]byte(user.Id), []byte(userJson))
		us.usersByLoginBucket.Put([]byte(user.Login), []byte(user.Id))

		result.Data = user

		storeChannel <- result
		return
	}()

	return storeChannel
}
Exemplo n.º 3
0
func (us BoltUserStore) Save(user *model.User) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		result := StoreResult{}

		if len(user.Id) > 0 {
			result.Err = model.NewAppError("BoltUserStore.Save", "Must call update for exisiting user", "user_id="+user.Id)
			storeChannel <- result
			close(storeChannel)
			return
		}

		if us.isLoginTaken(user.Login) {
			result.Err = model.NewAppError("BoltUserStore.Save", "User Login already taken", "user_login="******"BoltUserStore.Save", "User Login already taken", "PasswordConformition="+user.PasswordConfirmation+" Password="+user.Password)
			storeChannel <- result
			close(storeChannel)
			return
		}

		user.PreSave()
		userJSON := user.ToJson()
		us.usersBucket.Put([]byte(user.Id), []byte(userJSON))
		us.usersByLoginBucket.Put([]byte(user.Login), []byte(user.Id))

		result.Data = user

		storeChannel <- result
		close(storeChannel)
	}()

	return storeChannel
}