feat: pagina principal configurable por rol (HomeUrl)
This commit is contained in:
@@ -13,6 +13,7 @@ type Roles struct {
|
||||
CreatedAt time.Time `json:"created_at" gorm:"column:created_at"`
|
||||
Description string `json:"description" gorm:"column:description"`
|
||||
Name string `json:"name" gorm:"column:name"`
|
||||
HomeUrl string `json:"home_url" gorm:"column:home_url"`
|
||||
EsPortalCliente bool `json:"es_portal_cliente" gorm:"column:es_portal_cliente;default:false"`
|
||||
EsPortalPartner bool `json:"es_portal_partner" gorm:"column:es_portal_partner;default:false"`
|
||||
Submodules []Submodules `json:"submodules" gorm:"many2many:roles_submodules"`
|
||||
|
||||
+1
-2
@@ -190,8 +190,7 @@ func GetUserByUsuario(usuario string) (*Users, error) {
|
||||
var user Users
|
||||
fmt.Println(usuario) // Verifica el usuario recibido
|
||||
db := app.Http.Database.DB.Model(&Users{})
|
||||
// Usamos 1 explícitamente para indicar que el estado debe ser "activo"
|
||||
if err := db.Where("nombre_usuario = ? AND email_verified = ? AND estado = ?", usuario, true, true).First(&user).Error; err != nil {
|
||||
if err := db.Where("nombre_usuario = ? AND email_verified = ? AND estado = ?", usuario, true, true).Preload("Role").First(&user).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
<th class="py-2 px-4 border-b">Descripción</th>
|
||||
<th class="py-2 px-4 border-b">Submodulos</th>
|
||||
<th class="py-2 px-4 border-b w-28">Portal</th>
|
||||
<th class="py-2 px-4 border-b w-40">Página principal</th>
|
||||
<th class="py-2 px-4 border-b w-32"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -97,6 +98,9 @@
|
||||
</template>
|
||||
</div>
|
||||
</td>
|
||||
<td class="py-3 text-xs px-4 border-b">
|
||||
<span x-text="registro.home_url || 'Predeterminada'" class="text-xs text-slate-500"></span>
|
||||
</td>
|
||||
<td class="py-3 text-xs px-4 border-b ">
|
||||
<div class="flex justify-between space-x-1">
|
||||
<button
|
||||
@@ -118,6 +122,7 @@
|
||||
Submodules = [...registro.submodules];
|
||||
EsPortalCliente = registro.es_portal_cliente || false;
|
||||
EsPortalPartner = registro.es_portal_partner || false;
|
||||
HomeUrl = registro.home_url || '';
|
||||
modulos.forEach(modulo => {
|
||||
modulo.submodules.forEach(submodulo => {
|
||||
submodulo.checked = Submodules.some(sm => sm.ID === submodulo.ID);
|
||||
@@ -235,6 +240,20 @@
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 p-3 border rounded-md bg-slate-50">
|
||||
<label class="font-semibold text-sm mb-2 block" for="editHomeUrl">Página principal después del login</label>
|
||||
<select id="editHomeUrl" x-model="HomeUrl"
|
||||
class="border border-gray-300 rounded w-full p-2 text-sm">
|
||||
<option value="">Predeterminada (/app/servidor)</option>
|
||||
<template x-for="modulo in modulos" :key="modulo.ID">
|
||||
<optgroup :label="modulo.title">
|
||||
<template x-for="submodulo in modulo.submodules" :key="submodulo.ID">
|
||||
<option :value="submodulo.url" x-text="submodulo.title + ' (' + submodulo.url + ')'"></option>
|
||||
</template>
|
||||
</optgroup>
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mt-4 flex justify-between">
|
||||
<button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar Cambios</button>
|
||||
<button type="button" class="bg-gray-600 text-white px-4 py-2 rounded"
|
||||
@@ -293,6 +312,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 p-3 border rounded-md bg-slate-50">
|
||||
<label class="font-semibold text-sm mb-2 block" for="addHomeUrl">Página principal después del login</label>
|
||||
<select id="addHomeUrl" x-model="newHomeUrl"
|
||||
class="border border-gray-300 rounded w-full p-2 text-sm">
|
||||
<option value="">Predeterminada (/app/servidor)</option>
|
||||
<template x-for="modulo in modulos" :key="modulo.ID">
|
||||
<optgroup :label="modulo.title">
|
||||
<template x-for="submodulo in modulo.submodules" :key="submodulo.ID">
|
||||
<option :value="submodulo.url" x-text="submodulo.title + ' (' + submodulo.url + ')'"></option>
|
||||
</template>
|
||||
</optgroup>
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mt-4 flex justify-between">
|
||||
<button type="submit" class="bg-[#8eb02f] text-white px-4 py-2 rounded">Guardar</button>
|
||||
<button type="button" class="bg-gray-600 text-white px-4 py-2 rounded"
|
||||
@@ -332,11 +365,13 @@
|
||||
newDescription: '',
|
||||
newEsPortalCliente: false,
|
||||
newEsPortalPartner: false,
|
||||
newHomeUrl: '',
|
||||
|
||||
Name: '',
|
||||
Description: '',
|
||||
EsPortalCliente: false,
|
||||
EsPortalPartner: false,
|
||||
HomeUrl: '',
|
||||
modulos: [],
|
||||
Submodules: [],
|
||||
submodulos: [],
|
||||
@@ -460,6 +495,7 @@
|
||||
description: this.newDescription,
|
||||
es_portal_cliente: this.newEsPortalCliente,
|
||||
es_portal_partner: this.newEsPortalPartner,
|
||||
home_url: this.newHomeUrl,
|
||||
submodules: selectedSubmodules.flatMap(modulo => modulo.submodules)
|
||||
};
|
||||
|
||||
@@ -520,6 +556,7 @@
|
||||
description: this.Description,
|
||||
es_portal_cliente: this.EsPortalCliente,
|
||||
es_portal_partner: this.EsPortalPartner,
|
||||
home_url: this.HomeUrl,
|
||||
submodules: this.submodulos
|
||||
})
|
||||
})
|
||||
|
||||
@@ -37,8 +37,12 @@ func LoginPost(c *fiber.Ctx) error {
|
||||
return c.Redirect("/login?error=" + url.QueryEscape(err.Error()))
|
||||
}
|
||||
|
||||
// Si todo está bien, redirige al inicio de la app
|
||||
return c.Redirect("/app/servidor")
|
||||
// Redirige según la página principal del rol, o por defecto a /app/servidor
|
||||
homeUrl := "/app/servidor"
|
||||
if user.Role.HomeUrl != "" {
|
||||
homeUrl = user.Role.HomeUrl
|
||||
}
|
||||
return c.Redirect(homeUrl)
|
||||
}
|
||||
|
||||
var store = session.New()
|
||||
|
||||
@@ -11,7 +11,11 @@ import (
|
||||
|
||||
func RedirectToHomePageOnLogin(c *fiber.Ctx) error {
|
||||
if auth.IsLoggedIn(c) {
|
||||
return c.Redirect("/app/dashboard")
|
||||
user, err := auth.User(c)
|
||||
if err == nil && user != nil && user.Role.HomeUrl != "" {
|
||||
return c.Redirect(user.Role.HomeUrl)
|
||||
}
|
||||
return c.Redirect("/app/servidor")
|
||||
}
|
||||
// Si tiene sesión de portal activa, ir al portal
|
||||
if user, err := auth.PortalUser(c); err == nil && user != nil {
|
||||
|
||||
Reference in New Issue
Block a user