longevity: ruoli cliente e trainer con le rispettive rotte
This commit is contained in:
+8
-1
@@ -5,7 +5,7 @@ import { randomBytes } from 'node:crypto';
|
||||
export const SESSION_COOKIE = 'session';
|
||||
const SESSION_DAYS = 7;
|
||||
|
||||
export type Role = 'admin' | 'superuser' | 'user' | 'piattaforme';
|
||||
export type Role = 'admin' | 'superuser' | 'user' | 'piattaforme' | 'cliente' | 'trainer';
|
||||
|
||||
export function hashPassword(plain: string): string {
|
||||
return bcrypt.hashSync(plain, 12);
|
||||
@@ -62,6 +62,11 @@ const RULES: [RegExp, Role[]][] = [
|
||||
// sotto /piattaforme. Stesso ruolo per entrambe.
|
||||
[/^\/campus(\/|$)/, ['admin', 'piattaforme']],
|
||||
[/^\/piattaforme(\/|$)/, ['admin', 'piattaforme']],
|
||||
// Longevity: il cliente vede solo il proprio spazio, il gestionale è del trainer.
|
||||
[/^\/longevity\/gestionale(\/|$)/, ['admin', 'trainer']],
|
||||
[/^\/api\/longevity\/gestionale(\/|$)/, ['admin', 'trainer']],
|
||||
[/^\/longevity(\/|$)/, ['admin', 'trainer', 'cliente']],
|
||||
[/^\/api\/longevity(\/|$)/, ['admin', 'trainer', 'cliente']],
|
||||
];
|
||||
|
||||
export function canAccessAdminPath(role: string, pathname: string): boolean {
|
||||
@@ -71,6 +76,8 @@ export function canAccessAdminPath(role: string, pathname: string): boolean {
|
||||
}
|
||||
// piattaforme vede solo le sue sezioni (coperte da RULES) e il logout
|
||||
if (role === 'piattaforme') return pathname === '/admin/logout';
|
||||
// cliente e trainer non sono utenti del sito: fuori dalle rotte elencate non passano.
|
||||
if (role === 'cliente' || role === 'trainer') return pathname === '/admin/logout';
|
||||
return true; // blog, upload, logout, showtags: tutti i loggati
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user