<commit_before><?php
$key = 'token';

$token = isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : (isset($_COOKIE['chalmersItAuth']) ? $_COOKIE['chalmersItAuth'] : false));
$cid = isset($_GET['cid']) ? $_GET['cid'] : false;
if (!$token && !$cid) {
	die('Need more params, read the documentation for more info');
}

require_once('ldap.php');
require_once('auth.php');

$auth = new auth();
$ldap = new ldap('***REMOVED***');

$user = false;
if ($token) {
	$tokenUser = $auth->getUsername($token);
	$user = $tokenUser ? $tokenUser['username'] : null;
	if (!$user) {
		die('invalid token');
	}
}

$json = json_encode($ldap->search_by_cid($user));
if (isset($_GET['callback']) && $callback = $_GET['callback']) {
	header("Content-Type: application/javascript");
	echo "$callback($json);";
} else {
	header("Content-Type: application/json");
	echo $json;
}
<commit_msg>cid must be checked before cookie<commit_after><?php
$key = 'token';

$token = isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : (isset($_COOKIE['chalmersItAuth']) ? $_COOKIE['chalmersItAuth'] : false));
$cid = isset($_GET['cid']) ? $_GET['cid'] : false;
if (!$token && !$cid) {
	die('Need more params, read the documentation for more info');
}

require_once('ldap.php');
require_once('auth.php');

$auth = new auth();
$ldap = new ldap('***REMOVED***');

$user = false;
if (!$cid) {
	$tokenUser = $auth->getUsername($token);
	$user = $tokenUser ? $tokenUser['username'] : null;
	if (!$user) {
		die('invalid token');
	}
}

$json = json_encode($ldap->search_by_cid($user));
if (isset($_GET['callback']) && $callback = $_GET['callback']) {
	header("Content-Type: application/javascript");
	echo "$callback($json);";
} else {
	header("Content-Type: application/json");
	echo $json;
}

{'fraction_non_alphanumeric': 0.24203465623253215, 'fraction_numerical': 0.0, 'mean_word_length': 6.276422764227642, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1620486', 'n_tokens_mistral': 636, 'n_tokens_neox': 652, 'n_words': 133}