api getme
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* api_me_role.php
|
||||
* --------------------------------------------------------------------------
|
||||
* Restituisce il ruolo dell'utente autenticato e un flag comodo
|
||||
* "is_staff" (Admin o teacher) per abilitare le funzioni insegnante nell'app.
|
||||
*
|
||||
* Posizione: public/api/api_me_role.php
|
||||
* Metodo: GET
|
||||
* Auth: Bearer token (Sanctum) via _bootstrap.php
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/_bootstrap.php';
|
||||
|
||||
$roleId = (int) $user->role_id;
|
||||
|
||||
// nome ruolo da auth_roles (per debug / display)
|
||||
$stmt = $db->prepare("SELECT name FROM auth_roles WHERE id = :rid LIMIT 1");
|
||||
$stmt->execute([':rid' => $roleId]);
|
||||
$roleRow = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$roleName = $roleRow ? (string) $roleRow['name'] : '';
|
||||
|
||||
// Admin = 1, teacher = 3 → staff (accesso pannello classi)
|
||||
$isStaff = in_array($roleId, [1, 3], true);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'role_id' => $roleId,
|
||||
'role_name' => $roleName,
|
||||
'is_staff' => $isStaff,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
Reference in New Issue
Block a user