|
12345678910111213141516171819202122232425262728293031323334353637 |
- package endpoints
-
- import (
- "encoding/json"
- "net/http"
-
- "github.com/imosed/signet/auth"
- . "github.com/imosed/signet/data"
- )
-
- type GetUsersResponse struct {
- Users []User `json:"users"`
- }
-
- func GetUsers(w http.ResponseWriter, r *http.Request) {
- claims, err := auth.GetUserClaims(r)
-
- if claims == nil {
- w.WriteHeader(401)
- return
- }
- if claims.Privileges > AdminPlus {
- w.WriteHeader(403)
- return
- }
-
- var users []User
- Db.Table("users").Where("privileges >= ?", claims.Privileges).Order("id").Scan(&users)
-
- var resp GetUsersResponse
- resp.Users = users
-
- err = json.NewEncoder(w).Encode(resp)
- if err != nil {
- panic("Could not deliver response")
- }
- }
|