diff --git a/pkg/auth/portal.go b/pkg/auth/portal.go index 906d196..36c9fbd 100644 --- a/pkg/auth/portal.go +++ b/pkg/auth/portal.go @@ -35,6 +35,10 @@ func PortalUser(c *fiber.Ctx) (*models.PortalUser, error) { // SetPortalSession guarda el portal_user_id en la sesión. func SetPortalSession(c *fiber.Ctx, userID uint) error { store := app.Http.Session.Get(c) + // Regenerar ID de sesión para evitar session fixation + if err := store.Regenerate(); err != nil { + return err + } store.Set(portalSessionKey, userID) return store.Save() } diff --git a/pkg/models/proyecto.go b/pkg/models/proyecto.go index 2e57fca..4afb518 100644 --- a/pkg/models/proyecto.go +++ b/pkg/models/proyecto.go @@ -124,8 +124,11 @@ func GetAllProyectos(limit, offset int, search string) ([]Proyecto, int64, error } func GetProyectosByClienteIDs(clienteIDs []uint) ([]Proyecto, error) { + if len(clienteIDs) == 0 { + return []Proyecto{}, nil + } var items []Proyecto - err := app.Http.Database.DB.Where("cliente_id IN ?", clienteIDs).Order("created_at DESC").Find(&items).Error + err := app.Http.Database.DB.Preload("Cliente").Where("cliente_id IN ?", clienteIDs).Order("created_at DESC").Find(&items).Error return items, err } diff --git a/rest/controllers/portal_controller.go b/rest/controllers/portal_controller.go index 5e537cb..0982b7c 100644 --- a/rest/controllers/portal_controller.go +++ b/rest/controllers/portal_controller.go @@ -2,6 +2,7 @@ package controllers import ( "fmt" + "log" "net/url" "strings" @@ -27,11 +28,14 @@ func PortalLoginPost(c *fiber.Ctx) error { password := c.FormValue("password") u, err := models.CheckPortalLogin(email, password) if err != nil { + log.Printf("[PORTAL LOGIN] Fallo para %q: %v", email, err) return c.Redirect("/portal/login?error=" + url.QueryEscape(err.Error())) } if err := auth.SetPortalSession(c, u.ID); err != nil { + log.Printf("[PORTAL LOGIN] Error guardando sesión para usuario %d: %v", u.ID, err) return c.Redirect("/portal/login?error=Error+interno") } + log.Printf("[PORTAL LOGIN] OK usuario %d (%s)", u.ID, email) return c.Redirect("/portal/dashboard") } @@ -45,12 +49,14 @@ func PortalLogout(c *fiber.Ctx) error { func PortalDashboard(c *fiber.Ctx) error { u := middlewares.PortalUserFromLocals(c) if u == nil { + log.Println("[PORTAL DASHBOARD] Usuario no en locals, redirigiendo a login") return c.Redirect("/portal/login") } // Recargar con accesos fullUser, err := models.GetPortalUserByID(u.ID) if err != nil { + log.Printf("[PORTAL DASHBOARD] Error cargando usuario %d: %v", u.ID, err) return c.Redirect("/portal/login") }