Nenhuma descrição

login.go 459B

123456789101112131415161718192021222324252627282930
  1. package login
  2. import (
  3. "context"
  4. "net/http"
  5. "../../../core/errorHandler"
  6. "../../../core/response"
  7. "../../lib/auth"
  8. )
  9. func Mandatory(w http.ResponseWriter, r *http.Request) (logged bool) {
  10. user, logged := auth.GetUser(r)
  11. if !logged {
  12. var Errors errorHandler.Errors
  13. Errors.ActionForbidden("User must be logged in")
  14. response.JSON(Errors)
  15. } else {
  16. ctx := context.WithValue(r.Context(), "user", user)
  17. r = r.WithContext(ctx)
  18. }
  19. return
  20. }