/home/techb158/workloadmatch.com/api
NameSizeModeActions
chat/-0755rm
notifications/-0755rm
reports/-0755rm
routes/-0700rm
teacher/-0755rm
.htaccess7620644editdlrm
admin.php331100644editdlrm
api_functions.php214740644editdlrm
Auth.php45040644editdlrm
change_status.php13320644editdlrm
cors_test.php1840644editdlrm
Database.php9740644editdlrm
db_connect.php6230644editdlrm
forgetpassword.php74150644editdlrm
index.php239320644editdlrm
logout.php11670644editdlrm
psl-config.php3500644editdlrm
reports_schedule_by_course.php12870644editdlrm
reports_schedule_by_group.php13520644editdlrm
Response.php19380644editdlrm
tasks.php29930644editdlrm
teacher_profile.php11770644editdlrm
test.php11130644editdlrm
Edit: /home/techb158/workloadmatch.com/api/Auth.php (4504B)
['Admin_ID', 'admin_profile'], 'master_profile' => ['Master_ID', 'master_profile'], 'manager_profile' => ['Manager_ID', 'manager_profile'], 'teacher_profile' => ['Teacher_ID', 'teacher_profile'], ]; if (!isset($tableMap[$userType])) { return null; } [$idCol, $table] = $tableMap[$userType]; $stmt = $mysqli->prepare("SELECT * FROM $table WHERE $idCol = ? LIMIT 1"); if (!$stmt) return null; $stmt->bind_param('s', $userId); $stmt->execute(); $result = $stmt->get_result(); $user = $result->fetch_assoc(); $stmt->close(); if (!$user) return null; // Verify login string $loginCheck = hash('sha512', $user['Password'] . $_SERVER['HTTP_USER_AGENT']); if ($loginCheck !== $_SESSION['login_string']) { return null; } // Check if user is disabled if (isset($user['User_Access']) && (int)$user['User_Access'] !== 1) { return null; } self::$currentUser = $user; return $user; } public static function requireLogin(): array { $user = self::getUser(); if (!$user) { Response::unauthorized('Authentication required. Please log in.'); } return $user; } public static function requireRole(string $role): array { $user = self::requireLogin(); if ($_SESSION['User_type'] !== $role) { Response::forbidden("Access denied. Requires role: $role"); } return $user; } public static function requireAnyRole(array $roles): array { $user = self::requireLogin(); if (!in_array($_SESSION['User_type'], $roles)) { Response::forbidden('Access denied. Insufficient permissions.'); } return $user; } public static function getUserType(): string { return $_SESSION['User_type'] ?? ''; } public static function getUserId(): ?string { return $_SESSION['user_id'] ?? null; } public static function getEffectiveManagerId(): int { if (!empty($_SESSION['manage_as'])) { return (int)$_SESSION['manage_as']; } return (int)($_SESSION['user_id'] ?? 0); } public static function isMasterActingAsManager(): bool { return self::getUserType() === 'master_profile' && !empty($_SESSION['manage_as']); } public static function getRoleDir(): string { $dirMap = [ 'master_profile' => 'Master', 'manager_profile' => 'Manager', 'teacher_profile' => 'Teacher', 'admin_profile' => 'Admin', ]; $type = self::getUserType(); $dir = $dirMap[$type] ?? ''; if ($type === 'master_profile' && !empty($_SESSION['manage_as'])) { $dir = 'Manager'; } return $dir; } public static function hasPermission(mysqli $mysqli, string $module, string $action): bool { $userType = $_SESSION['User_type'] ?? ''; $roleId = $_SESSION['role_id'] ?? null; if ($userType === 'admin_profile') return true; if (!$roleId) return false; $actionCol = 'can_' . $action; $stmt = $mysqli->prepare("SELECT $actionCol FROM role_permissions WHERE role_id = ? AND module = ? LIMIT 1"); if ($stmt) { $stmt->bind_param('is', $roleId, $module); $stmt->execute(); $stmt->bind_result($allowed); $stmt->fetch(); $stmt->close(); return (bool)$allowed; } return false; } public static function requirePermission(mysqli $mysqli, string $module, string $action): void { if (!self::hasPermission($mysqli, $module, $action)) { Response::forbidden("Permission denied: $module/$action"); } } }