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
}
Exemple #2
0
func updateUser(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
	sessionContext := context.Get(r, "context").(Context)
	if sessionContext.Err != nil {
		sessionContext.SetInvalidParam("all Users", "user")
		w.WriteHeader(sessionContext.Err.StatusCode)
		return
	}

	user := model.UserFromJson(r.Body)
	result := <-Srv.Store.User().Update(user)
	if result.Err != nil {
		sessionContext.SetInvalidParam("update Users", "user")
		w.WriteHeader(sessionContext.Err.StatusCode)
		return
	}

	updatedUser := result.Data.(*model.User)
	updatedUser.Sanitize()
	w.Write([]byte(updatedUser.ToJson()))
}
Exemple #3
0
func createUser(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
	user := model.UserFromJson(r.Body)
	sessionContext := context.Get(r, "context").(Context)
	w.Header().Set("Content-Type", "application/json")
	if user == nil {
		sessionContext.SetInvalidParam("Create User", "user")
		w.WriteHeader(sessionContext.Err.StatusCode)
		return
	}

	cr := <-Srv.Store.User().GetCount()
	if cr.Err != nil {
		sessionContext.SetInvalidParam("Create User", "user")
		w.WriteHeader(sessionContext.Err.StatusCode)
		return
	}

	usersCount := cr.Data.(int)
	if usersCount <= 0 {
		user.Role = model.USER_ROLE_ADMIN
	} else {
		user.Role = model.USER_ROLE_USER
	}

	result := <-Srv.Store.User().Save(user)
	if result.Err != nil {
		sessionContext.SetInvalidParam("Create User", "user")
		w.WriteHeader(sessionContext.Err.StatusCode)
		return
	}
	w.WriteHeader(http.StatusOK)
	createdUser := result.Data.(*model.User)
	createdUser.Sanitize()
	createdUser.SetToken()
	w.Write([]byte(createdUser.ToJson()))
}
func (us BoltUserStore) getByLogin(login string) *model.User {
	userId := us.getIdByLogin(login)
	user := string(us.getJson(userId))
	return model.UserFromJson(strings.NewReader(user))
}
func (us BoltUserStore) get(id string) *model.User {
	user := string(us.getJson(id))
	return model.UserFromJson(strings.NewReader(user))
}