This commit is contained in:
Lizandro Guarnizo
2026-05-15 14:46:11 -05:00
parent b340d29583
commit d7fe292f05
4 changed files with 104 additions and 2 deletions
@@ -8,6 +8,7 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/sujit-baniya/fiber-boilerplate/app"
"github.com/sujit-baniya/fiber-boilerplate/pkg/models"
"github.com/sujit-baniya/fiber-boilerplate/pkg/services"
)
func PortalUsuariosIndex(c *fiber.Ctx) error {
@@ -172,3 +173,29 @@ func RemovePortalAcceso(c *fiber.Ctx) error {
}
return c.JSON(fiber.Map{"ok": true})
}
// SendPortalCredentials envía las credenciales de acceso al portal al correo del usuario.
func SendPortalCredentials(c *fiber.Ctx) error {
id, err := strconv.ParseUint(c.Params("id"), 10, 32)
if err != nil {
return c.Status(400).JSON(fiber.Map{"error": "ID inválido"})
}
u, err := models.GetPortalUserByID(uint(id))
if err != nil {
return c.Status(404).JSON(fiber.Map{"error": "Usuario no encontrado"})
}
type Req struct {
Password string `json:"password"`
}
var req Req
_ = c.BodyParser(&req)
password := req.Password
if password == "" {
password = "(la contraseña que configuraste)"
}
services.SendPortalCredentialsEmail(u.Email, u.Nombre, password)
return c.JSON(fiber.Map{"ok": true, "message": "Correo enviado a " + u.Email})
}
+1
View File
@@ -254,6 +254,7 @@ func UserRoutes(app fiber.Router) {
protected.Delete("/portal-usuarios/:id", controllers.DeletePortalUsuario)
protected.Post("/portal-usuarios/:id/acceso", controllers.AddPortalAcceso)
protected.Delete("/portal-usuarios/:id/acceso/:clienteID", controllers.RemovePortalAcceso)
protected.Post("/portal-usuarios/:id/send-credentials", controllers.SendPortalCredentials)
protected.Get("/facturas", middlewares.MenuMiddleware, controllers.FacturasIndex)
protected.Get("/loadfacturas", controllers.LoadFacturas)