4
0

restapi_auth_local.go 733 B

12345678910111213141516171819202122232425262728293031323334
  1. package httpservers
  2. import (
  3. "net/http"
  4. "github.com/OliveTin/OliveTin/internal/auth"
  5. "github.com/OliveTin/OliveTin/internal/config"
  6. log "github.com/sirupsen/logrus"
  7. )
  8. func parseLocalUserCookie(cfg *config.Config, req *http.Request) (string, string, string) {
  9. cookie, err := req.Cookie("olivetin-sid-local")
  10. if err != nil {
  11. return "", "", ""
  12. }
  13. cookieValue := cookie.Value
  14. session := auth.GetUserSession("local", cookieValue)
  15. if session == nil {
  16. return "", "", ""
  17. }
  18. user := cfg.FindUserByUsername(session.Username)
  19. if user == nil {
  20. log.WithFields(log.Fields{
  21. "username": session.Username,
  22. }).Warnf("User not found in config")
  23. return "", "", ""
  24. }
  25. return user.Username, user.Usergroup, cookie.Value
  26. }