up
This commit is contained in:
@@ -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})
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user