Fix: Utiliser la méthode standard de récupération du rôle depuis la DB comme les autres controllers
This commit is contained in:
@@ -28,7 +28,18 @@ class StripeController extends Controller {
|
|||||||
public function createAccount(): void {
|
public function createAccount(): void {
|
||||||
try {
|
try {
|
||||||
$this->requireAuth();
|
$this->requireAuth();
|
||||||
$this->requireRole(2); // Admin amicale minimum
|
|
||||||
|
// Vérifier le rôle de l'utilisateur (comme dans les autres controllers)
|
||||||
|
$userId = Session::getUserId();
|
||||||
|
$stmt = $this->db->prepare('SELECT fk_role FROM users WHERE id = ?');
|
||||||
|
$stmt->execute([$userId]);
|
||||||
|
$result = $stmt->fetch();
|
||||||
|
$userRole = $result ? (int)$result['fk_role'] : 0;
|
||||||
|
|
||||||
|
if ($userRole < 2) {
|
||||||
|
$this->sendError('Droits insuffisants - Admin amicale minimum requis', 403);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$data = $this->getJsonInput();
|
$data = $this->getJsonInput();
|
||||||
$entiteId = $data['fk_entite'] ?? Session::getEntityId();
|
$entiteId = $data['fk_entite'] ?? Session::getEntityId();
|
||||||
@@ -39,7 +50,7 @@ class StripeController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Vérifier les droits sur cette entité
|
// Vérifier les droits sur cette entité
|
||||||
if (Session::getEntityId() != $entiteId && Session::getRole() < 3) {
|
if (Session::getEntityId() != $entiteId && $userRole < 3) {
|
||||||
$this->sendError('Non autorisé pour cette entité', 403);
|
$this->sendError('Non autorisé pour cette entité', 403);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -64,7 +75,18 @@ class StripeController extends Controller {
|
|||||||
public function createOnboardingLink(string $accountId): void {
|
public function createOnboardingLink(string $accountId): void {
|
||||||
try {
|
try {
|
||||||
$this->requireAuth();
|
$this->requireAuth();
|
||||||
$this->requireRole(2);
|
|
||||||
|
// Vérifier le rôle de l'utilisateur
|
||||||
|
$userId = Session::getUserId();
|
||||||
|
$stmt = $this->db->prepare('SELECT fk_role FROM users WHERE id = ?');
|
||||||
|
$stmt->execute([$userId]);
|
||||||
|
$result = $stmt->fetch();
|
||||||
|
$userRole = $result ? (int)$result['fk_role'] : 0;
|
||||||
|
|
||||||
|
if ($userRole < 2) {
|
||||||
|
$this->sendError('Droits insuffisants', 403);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$data = $this->getJsonInput();
|
$data = $this->getJsonInput();
|
||||||
$returnUrl = $data['return_url'] ?? '';
|
$returnUrl = $data['return_url'] ?? '';
|
||||||
@@ -95,7 +117,18 @@ class StripeController extends Controller {
|
|||||||
public function createLocation(): void {
|
public function createLocation(): void {
|
||||||
try {
|
try {
|
||||||
$this->requireAuth();
|
$this->requireAuth();
|
||||||
$this->requireRole(2);
|
|
||||||
|
// Vérifier le rôle de l'utilisateur
|
||||||
|
$userId = Session::getUserId();
|
||||||
|
$stmt = $this->db->prepare('SELECT fk_role FROM users WHERE id = ?');
|
||||||
|
$stmt->execute([$userId]);
|
||||||
|
$result = $stmt->fetch();
|
||||||
|
$userRole = $result ? (int)$result['fk_role'] : 0;
|
||||||
|
|
||||||
|
if ($userRole < 2) {
|
||||||
|
$this->sendError('Droits insuffisants', 403);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$data = $this->getJsonInput();
|
$data = $this->getJsonInput();
|
||||||
$entiteId = $data['fk_entite'] ?? Session::getEntityId();
|
$entiteId = $data['fk_entite'] ?? Session::getEntityId();
|
||||||
@@ -212,9 +245,14 @@ class StripeController extends Controller {
|
|||||||
|
|
||||||
// Vérifier les droits
|
// Vérifier les droits
|
||||||
$userEntityId = Session::getEntityId();
|
$userEntityId = Session::getEntityId();
|
||||||
$userRole = Session::getRole();
|
|
||||||
$userId = Session::getUserId();
|
$userId = Session::getUserId();
|
||||||
|
|
||||||
|
// Récupérer le rôle depuis la base de données
|
||||||
|
$stmt = $this->db->prepare('SELECT fk_role FROM users WHERE id = ?');
|
||||||
|
$stmt->execute([$userId]);
|
||||||
|
$result = $stmt->fetch();
|
||||||
|
$userRole = $result ? (int)$result['fk_role'] : 0;
|
||||||
|
|
||||||
if ($payment['fk_entite'] != $userEntityId &&
|
if ($payment['fk_entite'] != $userEntityId &&
|
||||||
$payment['fk_user'] != $userId &&
|
$payment['fk_user'] != $userId &&
|
||||||
$userRole < 3) {
|
$userRole < 3) {
|
||||||
@@ -255,7 +293,13 @@ class StripeController extends Controller {
|
|||||||
|
|
||||||
// Vérifier les droits : admin de l'amicale ou super admin
|
// Vérifier les droits : admin de l'amicale ou super admin
|
||||||
$userEntityId = Session::getEntityId();
|
$userEntityId = Session::getEntityId();
|
||||||
$userRole = Session::getRole();
|
$userId = Session::getUserId();
|
||||||
|
|
||||||
|
// Récupérer le rôle depuis la base de données
|
||||||
|
$stmt = $this->db->prepare('SELECT fk_role FROM users WHERE id = ?');
|
||||||
|
$stmt->execute([$userId]);
|
||||||
|
$result = $stmt->fetch();
|
||||||
|
$userRole = $result ? (int)$result['fk_role'] : 0;
|
||||||
|
|
||||||
if ($entityId != $userEntityId && $userRole < 3) {
|
if ($entityId != $userEntityId && $userRole < 3) {
|
||||||
$this->sendError('Non autorisé', 403);
|
$this->sendError('Non autorisé', 403);
|
||||||
@@ -433,7 +477,14 @@ class StripeController extends Controller {
|
|||||||
$dateTo = $_GET['date_to'] ?? date('Y-m-d');
|
$dateTo = $_GET['date_to'] ?? date('Y-m-d');
|
||||||
|
|
||||||
// Vérifier les droits
|
// Vérifier les droits
|
||||||
if ($entiteId != Session::getEntityId() && Session::getRole() < 3) {
|
// Récupérer le rôle pour vérifier les droits
|
||||||
|
$userId = Session::getUserId();
|
||||||
|
$stmt = $this->db->prepare('SELECT fk_role FROM users WHERE id = ?');
|
||||||
|
$stmt->execute([$userId]);
|
||||||
|
$result = $stmt->fetch();
|
||||||
|
$userRole = $result ? (int)$result['fk_role'] : 0;
|
||||||
|
|
||||||
|
if ($entiteId != Session::getEntityId() && $userRole < 3) {
|
||||||
$this->sendError('Non autorisé', 403);
|
$this->sendError('Non autorisé', 403);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,19 +31,6 @@ abstract class Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Vérifier que l'utilisateur a le rôle minimum requis
|
|
||||||
* @param int $minRole Rôle minimum requis (1=membre, 2=admin amicale, 3=super admin)
|
|
||||||
*/
|
|
||||||
protected function requireRole(int $minRole): void {
|
|
||||||
$this->requireAuth();
|
|
||||||
|
|
||||||
$userRole = Session::getRole();
|
|
||||||
if ($userRole < $minRole) {
|
|
||||||
$this->sendError('Droits insuffisants', 403);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Récupérer les données JSON de la requête
|
* Récupérer les données JSON de la requête
|
||||||
|
|||||||
Reference in New Issue
Block a user