The backend for the project formerly known as signet, now known as beignet.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
647 B

  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/imosed/signet/auth"
  6. . "github.com/imosed/signet/data"
  7. )
  8. type GetUsersResponse struct {
  9. Users []User `json:"users"`
  10. }
  11. func GetUsers(w http.ResponseWriter, r *http.Request) {
  12. claims, err := auth.GetUserClaims(r)
  13. if claims == nil || (claims != nil && claims.Privileges > AdminPlus) {
  14. w.WriteHeader(403)
  15. return
  16. }
  17. var users []User
  18. Db.Table("users").Where("privileges >= ?", claims.Privileges).Order("id").Scan(&users)
  19. var resp GetUsersResponse
  20. resp.Users = users
  21. err = json.NewEncoder(w).Encode(resp)
  22. if err != nil {
  23. panic("Could not deliver response")
  24. }
  25. }