The backend for the project formerly known as signet, now known as beignet.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

50 rindas
1.0 KiB

  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "github.com/imosed/signet/auth"
  5. . "github.com/imosed/signet/data"
  6. "net/http"
  7. )
  8. type EscalatePrivilegesRequest struct {
  9. Username string
  10. }
  11. func EscalatePrivileges(w http.ResponseWriter, r *http.Request) {
  12. var req EscalatePrivilegesRequest
  13. err := json.NewDecoder(r.Body).Decode(&req)
  14. if err != nil {
  15. panic("Could not decode body")
  16. }
  17. var resp SuccessResponse
  18. var user User
  19. var claims *auth.Claims
  20. claims, err = auth.GetUserClaims(r)
  21. if claims.Privileges == SuperUser {
  22. Db.Table("users").Where("username = ?", req.Username).Find(&user)
  23. if user.Privileges == SuperUser || user.Privileges == AdminPlus {
  24. resp.Success = false
  25. err = json.NewEncoder(w).Encode(resp)
  26. if err != nil {
  27. panic("Could not deliver failed escalate privileges response")
  28. }
  29. return
  30. }
  31. user.Privileges = AdminPlus
  32. resp.Success = true
  33. } else {
  34. resp.Success = false
  35. }
  36. err = json.NewEncoder(w).Encode(resp)
  37. if err != nil {
  38. panic("Could not deliver successful escalate privileges response")
  39. }
  40. }