mejora del portal

This commit is contained in:
Lizandro Guarnizo
2026-05-15 15:39:48 -05:00
parent d7fe292f05
commit 04fd456a4c
3 changed files with 14 additions and 1 deletions
+4
View File
@@ -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()
}
+4 -1
View File
@@ -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
}
+6
View File
@@ -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")
}