up
This commit is contained in:
@@ -26,7 +26,10 @@ type PortalUser struct {
|
||||
Notas string `json:"notas" gorm:"column:notas;type:text"`
|
||||
TelegramChatID string `json:"telegram_chat_id" gorm:"column:telegram_chat_id"`
|
||||
Telefono string `json:"telefono" gorm:"column:telefono"`
|
||||
Indicativo string `json:"indicativo" gorm:"column:indicativo"` // ej: +57, +1
|
||||
Pais string `json:"pais" gorm:"column:pais"`
|
||||
Documento string `json:"documento" gorm:"column:documento"` // RUT, NIT, CC, etc.
|
||||
Empresa string `json:"empresa" gorm:"column:empresa"` // empresa que representa
|
||||
PortalAccesos []PortalAcceso `json:"portal_accesos" gorm:"foreignKey:PortalUserID"`
|
||||
}
|
||||
|
||||
@@ -85,7 +88,10 @@ func UpdatePortalUser(u *PortalUser) error {
|
||||
"notas": u.Notas,
|
||||
"telegram_chat_id": u.TelegramChatID,
|
||||
"telefono": u.Telefono,
|
||||
"indicativo": u.Indicativo,
|
||||
"pais": u.Pais,
|
||||
"documento": u.Documento,
|
||||
"empresa": u.Empresa,
|
||||
}).Error
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,174 @@
|
||||
<span class="text-sm text-slate-600 hidden sm:block">
|
||||
{{ if .portalUser }}{{ .portalUser.Nombre }}{{ end }}
|
||||
</span>
|
||||
<!-- Mi cuenta -->
|
||||
<div x-data="miCuenta()" x-init="init()">
|
||||
<button @click="open=true"
|
||||
class="inline-flex items-center gap-1.5 text-sm text-slate-600 hover:text-[#8eb02f] font-medium transition-colors focus:outline-none">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M15.75 6a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0zM4.501 20.118a7.5 7.5 0 0114.998 0A17.933 17.933 0 0112 21.75c-2.676 0-5.216-.584-7.499-1.632z"/></svg>
|
||||
<span class="hidden sm:inline">Mi cuenta</span>
|
||||
</button>
|
||||
|
||||
<!-- Slide panel -->
|
||||
<div x-show="open" x-cloak class="fixed inset-0 z-50 flex justify-end">
|
||||
<!-- Backdrop -->
|
||||
<div class="absolute inset-0 bg-black/40" @click="open=false"></div>
|
||||
<!-- Panel -->
|
||||
<div class="relative w-full max-w-md bg-white h-full shadow-2xl flex flex-col overflow-hidden"
|
||||
x-transition:enter="transition ease-out duration-300"
|
||||
x-transition:enter-start="translate-x-full"
|
||||
x-transition:enter-end="translate-x-0"
|
||||
x-transition:leave="transition ease-in duration-200"
|
||||
x-transition:leave-start="translate-x-0"
|
||||
x-transition:leave-end="translate-x-full">
|
||||
|
||||
<!-- Header panel -->
|
||||
<div class="flex items-center justify-between px-5 py-4 border-b border-slate-200 flex-shrink-0">
|
||||
<h2 class="text-base font-semibold text-slate-800">Mi cuenta</h2>
|
||||
<button @click="open=false" class="p-1.5 rounded-lg hover:bg-slate-100 transition-colors text-slate-400 hover:text-slate-600">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Tabs -->
|
||||
<div class="flex border-b border-slate-200 px-5 gap-4 flex-shrink-0">
|
||||
<button @click="tab='perfil'" class="py-3 text-sm font-medium border-b-2 -mb-px transition-colors"
|
||||
:class="tab==='perfil' ? 'border-[#8eb02f] text-[#8eb02f]' : 'border-transparent text-slate-500 hover:text-slate-700'">
|
||||
Información
|
||||
</button>
|
||||
<button @click="tab='password'" class="py-3 text-sm font-medium border-b-2 -mb-px transition-colors"
|
||||
:class="tab==='password' ? 'border-[#8eb02f] text-[#8eb02f]' : 'border-transparent text-slate-500 hover:text-slate-700'">
|
||||
Contraseña
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Body scrollable -->
|
||||
<div class="flex-1 overflow-y-auto px-5 py-5">
|
||||
|
||||
<!-- Tab: Información personal -->
|
||||
<div x-show="tab==='perfil'" class="space-y-4">
|
||||
<p x-show="perfilMsg" x-text="perfilMsg"
|
||||
:class="perfilOk ? 'text-green-600 bg-green-50 border border-green-200' : 'text-red-600 bg-red-50 border border-red-200'"
|
||||
class="text-sm rounded-lg px-3 py-2"></p>
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-500 uppercase tracking-wide mb-1">Nombre completo *</label>
|
||||
<input x-model="perfil.nombre" type="text" placeholder="Tu nombre"
|
||||
class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#8eb02f] focus:ring-2 focus:ring-[#8eb02f]/20">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-500 uppercase tracking-wide mb-1">Correo electrónico *</label>
|
||||
<input x-model="perfil.email" type="email" placeholder="correo@ejemplo.com"
|
||||
class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#8eb02f] focus:ring-2 focus:ring-[#8eb02f]/20">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-500 uppercase tracking-wide mb-1">Teléfono</label>
|
||||
<div class="flex gap-2">
|
||||
<select x-model="perfil.indicativo"
|
||||
class="border border-slate-200 rounded-lg px-2 py-2 text-sm focus:outline-none focus:border-[#8eb02f] focus:ring-2 focus:ring-[#8eb02f]/20 w-32 flex-shrink-0">
|
||||
<option value="">Indicativo</option>
|
||||
<option value="+57">🇨🇴 +57</option>
|
||||
<option value="+1">🇺🇸 +1</option>
|
||||
<option value="+52">🇲🇽 +52</option>
|
||||
<option value="+34">🇪🇸 +34</option>
|
||||
<option value="+54">🇦🇷 +54</option>
|
||||
<option value="+51">🇵🇪 +51</option>
|
||||
<option value="+56">🇨🇱 +56</option>
|
||||
<option value="+58">🇻🇪 +58</option>
|
||||
<option value="+593">🇪🇨 +593</option>
|
||||
<option value="+502">🇬🇹 +502</option>
|
||||
<option value="+506">🇨🇷 +506</option>
|
||||
<option value="+507">🇵🇦 +507</option>
|
||||
<option value="+503">🇸🇻 +503</option>
|
||||
<option value="+504">🇭🇳 +504</option>
|
||||
<option value="+505">🇳🇮 +505</option>
|
||||
<option value="+591">🇧🇴 +591</option>
|
||||
<option value="+595">🇵🇾 +595</option>
|
||||
<option value="+598">🇺🇾 +598</option>
|
||||
<option value="+55">🇧🇷 +55</option>
|
||||
<option value="+44">🇬🇧 +44</option>
|
||||
<option value="+33">🇫🇷 +33</option>
|
||||
<option value="+49">🇩🇪 +49</option>
|
||||
<option value="+39">🇮🇹 +39</option>
|
||||
<option value="+351">🇵🇹 +351</option>
|
||||
<option value="+other">Otro</option>
|
||||
</select>
|
||||
<input x-model="perfil.telefono" type="tel" placeholder="Número de teléfono"
|
||||
class="flex-1 border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#8eb02f] focus:ring-2 focus:ring-[#8eb02f]/20">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-500 uppercase tracking-wide mb-1">País</label>
|
||||
<input x-model="perfil.pais" type="text" placeholder="Ej: Colombia"
|
||||
class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#8eb02f] focus:ring-2 focus:ring-[#8eb02f]/20">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-500 uppercase tracking-wide mb-1">RUT / Documento legal</label>
|
||||
<input x-model="perfil.documento" type="text" placeholder="Ej: NIT, RUT, CC, CUIT..."
|
||||
class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#8eb02f] focus:ring-2 focus:ring-[#8eb02f]/20">
|
||||
<p class="text-xs text-slate-400 mt-1">Documento legal de tu país (NIT, RUT, Cédula, CUIT, RFC, etc.)</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-500 uppercase tracking-wide mb-1">Empresa / Organización</label>
|
||||
<input x-model="perfil.empresa" type="text" placeholder="Nombre de tu empresa"
|
||||
class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#8eb02f] focus:ring-2 focus:ring-[#8eb02f]/20">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tab: Cambiar contraseña -->
|
||||
<div x-show="tab==='password'" class="space-y-4">
|
||||
<p x-show="passMsg" x-text="passMsg"
|
||||
:class="passOk ? 'text-green-600 bg-green-50 border border-green-200' : 'text-red-600 bg-red-50 border border-red-200'"
|
||||
class="text-sm rounded-lg px-3 py-2"></p>
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-500 uppercase tracking-wide mb-1">Contraseña actual *</label>
|
||||
<input x-model="pass.actual" type="password" placeholder="Tu contraseña actual"
|
||||
class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#8eb02f] focus:ring-2 focus:ring-[#8eb02f]/20">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-500 uppercase tracking-wide mb-1">Nueva contraseña *</label>
|
||||
<input x-model="pass.nueva" type="password" placeholder="Mínimo 8 caracteres"
|
||||
class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#8eb02f] focus:ring-2 focus:ring-[#8eb02f]/20">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-semibold text-slate-500 uppercase tracking-wide mb-1">Confirmar nueva contraseña *</label>
|
||||
<input x-model="pass.confirma" type="password" placeholder="Repite la nueva contraseña"
|
||||
class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:border-[#8eb02f] focus:ring-2 focus:ring-[#8eb02f]/20">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div><!-- /body -->
|
||||
|
||||
<!-- Footer con botón guardar -->
|
||||
<div class="flex-shrink-0 px-5 py-4 border-t border-slate-200 bg-slate-50">
|
||||
<template x-if="tab==='perfil'">
|
||||
<button @click="guardarPerfil()" :disabled="saving"
|
||||
class="w-full bg-[#8eb02f] hover:bg-[#6d8c24] text-white font-semibold py-2.5 rounded-lg text-sm transition-colors disabled:opacity-60">
|
||||
<span x-show="!saving">Guardar cambios</span>
|
||||
<span x-show="saving">Guardando…</span>
|
||||
</button>
|
||||
</template>
|
||||
<template x-if="tab==='password'">
|
||||
<button @click="cambiarPassword()" :disabled="saving"
|
||||
class="w-full bg-[#8eb02f] hover:bg-[#6d8c24] text-white font-semibold py-2.5 rounded-lg text-sm transition-colors disabled:opacity-60">
|
||||
<span x-show="!saving">Cambiar contraseña</span>
|
||||
<span x-show="saving">Procesando…</span>
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
</div><!-- /panel -->
|
||||
</div><!-- /slide panel -->
|
||||
</div><!-- /x-data miCuenta -->
|
||||
|
||||
<a href="/portal/logout" class="text-sm text-red-500 hover:text-red-700 font-medium transition-colors">
|
||||
Cerrar sesión
|
||||
</a>
|
||||
@@ -118,5 +286,58 @@
|
||||
Powered by U-site — © 2025
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
function miCuenta() {
|
||||
return {
|
||||
open: false,
|
||||
tab: 'perfil',
|
||||
saving: false,
|
||||
perfil: { nombre:'', email:'', telefono:'', indicativo:'', pais:'', documento:'', empresa:'' },
|
||||
perfilMsg: '', perfilOk: false,
|
||||
pass: { actual:'', nueva:'', confirma:'' },
|
||||
passMsg: '', passOk: false,
|
||||
|
||||
async init() {
|
||||
try {
|
||||
const r = await axios.get('/portal/mi-perfil');
|
||||
this.perfil = r.data;
|
||||
} catch(e) {}
|
||||
},
|
||||
|
||||
async guardarPerfil() {
|
||||
this.perfilMsg = '';
|
||||
if (!this.perfil.nombre.trim()) { this.perfilMsg = 'El nombre es requerido.'; this.perfilOk = false; return; }
|
||||
if (!this.perfil.email.trim()) { this.perfilMsg = 'El email es requerido.'; this.perfilOk = false; return; }
|
||||
this.saving = true;
|
||||
try {
|
||||
await axios.put('/portal/mi-perfil', this.perfil);
|
||||
this.perfilMsg = '✅ Información actualizada correctamente.';
|
||||
this.perfilOk = true;
|
||||
} catch(e) {
|
||||
this.perfilMsg = e.response?.data?.error || 'Error al guardar.';
|
||||
this.perfilOk = false;
|
||||
} finally { this.saving = false; }
|
||||
},
|
||||
|
||||
async cambiarPassword() {
|
||||
this.passMsg = '';
|
||||
if (!this.pass.actual) { this.passMsg = 'Ingresa tu contraseña actual.'; this.passOk = false; return; }
|
||||
if (this.pass.nueva.length < 8) { this.passMsg = 'La nueva contraseña debe tener al menos 8 caracteres.'; this.passOk = false; return; }
|
||||
if (this.pass.nueva !== this.pass.confirma) { this.passMsg = 'Las contraseñas no coinciden.'; this.passOk = false; return; }
|
||||
this.saving = true;
|
||||
try {
|
||||
await axios.put('/portal/mi-perfil/password', this.pass);
|
||||
this.passMsg = '✅ Contraseña actualizada correctamente.';
|
||||
this.passOk = true;
|
||||
this.pass = { actual:'', nueva:'', confirma:'' };
|
||||
} catch(e) {
|
||||
this.passMsg = e.response?.data?.error || 'Error al cambiar contraseña.';
|
||||
this.passOk = false;
|
||||
} finally { this.saving = false; }
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/auth"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/models"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/services"
|
||||
@@ -391,3 +392,117 @@ func PortalMarcarTicketLeido(c *fiber.Ctx) error {
|
||||
_ = models.MarkTicketMessagesReadByPortal(uint(ticketID))
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
// ─── Mi Perfil ────────────────────────────────────────────────────────────────
|
||||
|
||||
// GET /portal/mi-perfil — devuelve datos del usuario autenticado
|
||||
func PortalGetMiPerfil(c *fiber.Ctx) error {
|
||||
u := middlewares.PortalUserFromLocals(c)
|
||||
if u == nil {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "no autenticado"})
|
||||
}
|
||||
full, err := models.GetPortalUserByID(u.ID)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "error al obtener perfil"})
|
||||
}
|
||||
return c.JSON(fiber.Map{
|
||||
"id": full.ID,
|
||||
"nombre": full.Nombre,
|
||||
"email": full.Email,
|
||||
"telefono": full.Telefono,
|
||||
"indicativo": full.Indicativo,
|
||||
"pais": full.Pais,
|
||||
"documento": full.Documento,
|
||||
"empresa": full.Empresa,
|
||||
})
|
||||
}
|
||||
|
||||
// PUT /portal/mi-perfil — actualiza datos del usuario autenticado
|
||||
func PortalUpdateMiPerfil(c *fiber.Ctx) error {
|
||||
u := middlewares.PortalUserFromLocals(c)
|
||||
if u == nil {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "no autenticado"})
|
||||
}
|
||||
type Req struct {
|
||||
Nombre string `json:"nombre"`
|
||||
Email string `json:"email"`
|
||||
Telefono string `json:"telefono"`
|
||||
Indicativo string `json:"indicativo"`
|
||||
Pais string `json:"pais"`
|
||||
Documento string `json:"documento"`
|
||||
Empresa string `json:"empresa"`
|
||||
}
|
||||
var req Req
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "Datos inválidos"})
|
||||
}
|
||||
req.Nombre = strings.TrimSpace(req.Nombre)
|
||||
req.Email = strings.TrimSpace(req.Email)
|
||||
if req.Nombre == "" {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "El nombre es requerido"})
|
||||
}
|
||||
if req.Email == "" {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "El email es requerido"})
|
||||
}
|
||||
// Verificar que el email no lo use otro usuario
|
||||
existing, err := models.GetPortalUserByEmail(req.Email)
|
||||
if err == nil && existing.ID != u.ID {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "El email ya está en uso"})
|
||||
}
|
||||
full, err := models.GetPortalUserByID(u.ID)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "Usuario no encontrado"})
|
||||
}
|
||||
full.Nombre = req.Nombre
|
||||
full.Email = req.Email
|
||||
full.Telefono = req.Telefono
|
||||
full.Indicativo = req.Indicativo
|
||||
full.Pais = req.Pais
|
||||
full.Documento = req.Documento
|
||||
full.Empresa = req.Empresa
|
||||
if err := models.UpdatePortalUser(full); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
// PUT /portal/mi-perfil/password — cambia la contraseña del usuario autenticado
|
||||
func PortalCambiarPassword(c *fiber.Ctx) error {
|
||||
u := middlewares.PortalUserFromLocals(c)
|
||||
if u == nil {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "no autenticado"})
|
||||
}
|
||||
type Req struct {
|
||||
Actual string `json:"actual"`
|
||||
Nueva string `json:"nueva"`
|
||||
Confirma string `json:"confirma"`
|
||||
}
|
||||
var req Req
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "Datos inválidos"})
|
||||
}
|
||||
if strings.TrimSpace(req.Nueva) == "" {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "La nueva contraseña no puede estar vacía"})
|
||||
}
|
||||
if req.Nueva != req.Confirma {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "Las contraseñas no coinciden"})
|
||||
}
|
||||
if len(req.Nueva) < 8 {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "La contraseña debe tener al menos 8 caracteres"})
|
||||
}
|
||||
full, err := models.GetPortalUserByID(u.ID)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "Usuario no encontrado"})
|
||||
}
|
||||
if match, matchErr := app.Http.Hash.Match(req.Actual, full.Password); matchErr != nil || !match {
|
||||
return c.Status(400).JSON(fiber.Map{"error": "La contraseña actual es incorrecta"})
|
||||
}
|
||||
hashed, err := app.Http.Hash.Create(req.Nueva)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": "Error al procesar contraseña"})
|
||||
}
|
||||
if err := models.UpdatePortalUserPassword(u.ID, hashed); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
@@ -40,4 +40,9 @@ func PortalRoutes(app fiber.Router) {
|
||||
portal.Get("/partner-recursos", middlewares.PortalPartnerOnly(), controllers.PortalPartnerRecursos)
|
||||
portal.Get("/partner-recursos/:id/download", middlewares.PortalPartnerOnly(), controllers.PortalDownloadPartnerRecurso)
|
||||
portal.Get("/partner-comunicados/:id/download", middlewares.PortalPartnerOnly(), controllers.DownloadPartnerComunicadoArchivo)
|
||||
|
||||
// Mi perfil
|
||||
portal.Get("/mi-perfil", controllers.PortalGetMiPerfil)
|
||||
portal.Put("/mi-perfil", controllers.PortalUpdateMiPerfil)
|
||||
portal.Put("/mi-perfil/password", controllers.PortalCambiarPassword)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user