- Created membership_links table to associate secondary users with primary memberships - Created membership_permissions table for granular permission control - Added linkSecondaryUserToMembership() function to create links with validation - Added getUserMembershipLink() to check access via secondary links - Added getLinkedSecondaryUsers() to list all secondary users for a primary member - Added unlinkSecondaryUser() to remove links - Updated getUserMemberStatus() to check both direct and linked memberships - Created link_membership_user processor to handle linking via API - Created unlink_membership_user processor to handle unlinking via API - Added .htaccess routes for linking endpoints - Grants default permissions: access_member_areas, member_pricing, book_campsites, book_courses, book_trips - Includes transaction safety with rollback on errors - Includes comprehensive documentation with usage examples - Validates primary user has active membership before allowing links - Prevents duplicate links and self-linking
38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
$rootPath = dirname(dirname(__DIR__));
|
|
require_once($rootPath . '/src/config/env.php');
|
|
require_once($rootPath . '/src/config/session.php');
|
|
require_once($rootPath . '/src/config/connection.php');
|
|
require_once($rootPath . '/src/config/functions.php');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
if (!isset($_SESSION['user_id']) || $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
http_response_code(403);
|
|
exit(json_encode(['success' => false, 'message' => 'Forbidden']));
|
|
}
|
|
|
|
// Validate CSRF token
|
|
if (!isset($_POST['csrf_token']) || !validateCSRFToken($_POST['csrf_token'])) {
|
|
http_response_code(400);
|
|
exit(json_encode(['success' => false, 'message' => 'Invalid request']));
|
|
}
|
|
|
|
$primary_user_id = intval($_SESSION['user_id']);
|
|
$link_id = intval($_POST['link_id'] ?? 0);
|
|
|
|
if (!$link_id) {
|
|
http_response_code(400);
|
|
exit(json_encode(['success' => false, 'message' => 'Link ID is required']));
|
|
}
|
|
|
|
// Use the unlinking function from functions.php
|
|
$result = unlinkSecondaryUser($link_id, $primary_user_id);
|
|
|
|
http_response_code($result['success'] ? 200 : 400);
|
|
echo json_encode([
|
|
'success' => $result['success'],
|
|
'message' => $result['message']
|
|
]);
|
|
?>
|