<commit_before><?php

require_once dirname(dirname(__DIR__)) . "/classes/autoload.php";
require_once dirname(dirname(__DIR__)) . "/lib/xsrf.php";
require_once("/etc/apache2/capstone-mysql/encrypted-config.php");

use Edu\Cnm\BrewCrew;

/**
 * API for user class
 *
 * @author <NAME> <EMAIL>
 *
 * @see https://github.com/CreativeCorrie/time-crunchers/blob/master/public_html/php/api/user/index.php for api I copied
 */

// Verify xsrf challenge
if(session_status() !== PHP_SESSION_ACTIVE) {
	session_start();
}
// Prepare a empty reply
$reply = new stdClass();
$reply->status = 200;
$reply->data = null;

try {
	// Grab the MySQL connection
	$pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/brewcrew.ini");

	// Determine which HTTP method was used
	$method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];
	$reply->method=$method;

	// Sanitize inputs
	$id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);

	// Make sure the id is valid for methods that require it
	if(($method === "DELETE" || $method === "PUT") && (empty($id) === true || $id < 0)) {
		throw(new InvalidArgumentException("id cannot be negative or empty", 405));
	}

	// Sanitize and trim other fields
	$userId = filter_input(INPUT_GET, "userId", FILTER_VALIDATE_INT);
	$userBreweryId = filter_input(INPUT_GET, "userBreweryId", FILTER_VALIDATE_INT);
	$userAccessLevel = filter_input(INPUT_GET, "userAccessLevel", FILTER_VALIDATE_INT);
	$userActivationToken = filter_input(INPUT_GET, "userActivationToken", FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
	$userEmail = filter_input(INPUT_GET, "userEmail", FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
	$userUsername = filter_input(INPUT_GET, "userUsername", FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);

	// Handle rest calls, while only allowing admins to access database-modifying methods
	if($method === "GET") {
		// Set XSRF cookie
		setXsrfCookie("/");

		// Get the user based on the given
		if(empty($id) === false) {
			$user = User::getUserByUserId($pdo, $id);
			if($user !== null) {
				$reply->data = $user;
			}
		} else if(empty($userBreweryId) === false) {
			$user = User::getUserByUserBreweryId($pdo, $userBreweryId);
			if($user !== null) {
				$reply->data = $user;
			}
		} else if(empty($userAccessLevel) === false) {
			$user = User::getUserByUserAccessLevel($pdo, $userAccessLevel);
			if($user !== null) {
				$reply->data = $user;
			}
		} else if(empty($userActivationToken) === false) {
			$user = User::getUserByUserActivation($pdo, $userActivationToken);
			if($user !== null) {
				$reply->data = $user;
			}
		} else if(empty($userEmail) === false) {
			$user = User::getUserByUserEmail($pdo, $userEmail);
			if($user !== null) {
				$reply->data = $user;
			}
		} else if(empty($userUsername) === false) {
			$user = User::getUserByUserUsername($pdo, $userUsername);
			if($user !== null) {
				$reply->data = $user;
			}
		} else {
			$users = User::getAllUsers($pdo);
			$reply->data = $users;
		}

	} else if($method === "PUT") {
		verifyXsrf();
		$requestContent = file_get_contents("php://input");
		$requestObject = json_decode($requestContent);

		// Make sure all fields are present in order to prevent database issues
		if(empty($requestObject->userBreweryId) === true) {
			throw(new InvalidArgumentException ("userBreweryId cannot be empty", 405));
		}
		$requestObject->userEmail = (filter_var($requestObject->userEmail, FILTER_SANITIZE_EMAIL));
		$requestObject->userFirstName = (filter_var($requestObject->userFirstName, FILTER_SANITIZE_STRING));
		$requestObject->userLastName = (filter_var($requestObject->userLastName, FILTER_SANITIZE_STRING));
		$requestObject->userUsername = (filter_var($requestObject->userUsername, FILTER_SANITIZE_STRING));

		// Perform the actual put
		$user = User::getUserByUserId($pdo, $id);
		if($user === null) {
			throw(new RuntimeException("User does not exist.", 404));
		}
<commit_msg>Fixed error in user api<commit_after><?php

require_once dirname(dirname(__DIR__)) . "/classes/autoload.php";
require_once dirname(dirname(__DIR__)) . "/lib/xsrf.php";
require_once("/etc/apache2/capstone-mysql/encrypted-config.php");

use Edu\Cnm\BrewCrew;

/**
 * API for user class
 *
 * @author <NAME> <EMAIL>
 *
 * @see https://github.com/CreativeCorrie/time-crunchers/blob/master/public_html/php/api/user/index.php for api I copied
 */

// Verify xsrf challenge
if(session_status() !== PHP_SESSION_ACTIVE) {
	session_start();
}
// Prepare a empty reply
$reply = new stdClass();
$reply->status = 200;
$reply->data = null;

try {
	// Grab the MySQL connection
	$pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/brewcrew.ini");

	// Determine which HTTP method was used
	$method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $_SERVER["REQUEST_METHOD"];
	$reply->method=$method;

	// Sanitize inputs
	$id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);

	// Make sure the id is valid for methods that require it
	if(($method === "DELETE" || $method === "PUT") && (empty($id) === true || $id < 0)) {
		throw(new InvalidArgumentException("id cannot be negative or empty", 405));
	}

	// Sanitize and trim other fields
	$userId = filter_input(INPUT_GET, "userId", FILTER_VALIDATE_INT);
	$userBreweryId = filter_input(INPUT_GET, "userBreweryId", FILTER_VALIDATE_INT);
	$userAccessLevel = filter_input(INPUT_GET, "userAccessLevel", FILTER_VALIDATE_INT);
	$userActivationToken = filter_input(INPUT_GET, "userActivationToken", FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
	$userEmail = filter_input(INPUT_GET, "userEmail", FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
	$userUsername = filter_input(INPUT_GET, "userUsername", FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);

	// Handle rest calls, while only allowing admins to access database-modifying methods
	if($method === "GET") {
		// Set XSRF cookie
		setXsrfCookie("/");

		// Get the user based on the given
		if(empty($id) === false) {
			$user = BrewCrew\User::getUserByUserId($pdo, $id);
			if($user !== null) {
				$reply->data = $user;
			}
		} else if(empty($userBreweryId) === false) {
			$user = BrewCrew\User::getUserByUserBreweryId($pdo, $userBreweryId);
			if($user !== null) {
				$reply->data = $user;
			}
		} else if(empty($userAccessLevel) === false) {
			$user = BrewCrew\User::getUserByUserAccessLevel($pdo, $userAccessLevel);
			if($user !== null) {
				$reply->data = $user;
			}
		} else if(empty($userActivationToken) === false) {
			$user = BrewCrew\User::getUserByUserActivationToken($pdo, $userActivationToken);
			if($user !== null) {
				$reply->data = $user;
			}
		} else if(empty($userEmail) === false) {
			$user = BrewCrew\User::getUserByUserEmail($pdo, $userEmail);
			if($user !== null) {
				$reply->data = $user;
			}
		} else if(empty($userUsername) === false) {
			$user = BrewCrew\User::getUserByUserUsername($pdo, $userUsername);
			if($user !== null) {
				$reply->data = $user;
			}
		} else {
			$users = BrewCrew\User::getAllUsers($pdo);
			$reply->data = $users;
		}

	} else if($method === "PUT") {
		verifyXsrf();
		$requestContent = file_get_contents("php://input");
		$requestObject = json_decode($requestContent);

		// Make sure all fields are present in order to prevent database issues
		if(empty($requestObject->userBreweryId) === true) {
			throw(new InvalidArgumentException ("userBreweryId cannot be empty", 405));
		}
		$requestObject->userEmail = (filter_var($requestObject->userEmail, FILTER_SANITIZE_EMAIL));
		$requestObject->userFirstName = (filter_var($requestObject->userFirstName, FILTER_SANITIZE_STRING));
		$requestObject->userLastName = (filter_var($requestObject->userLastName, FILTER_SANITIZE_STRING));
		$requestObject->userUsername = (filter_var($requestObject->userUsername, FILTER_SANITIZE_STRING));

		// Perform the actual put
		$user = User::getUserByUserId($pdo, $id);
		if($user === null) {
			throw(new RuntimeException("User does not exist.", 404));
		}

{'fraction_non_alphanumeric': 0.15906273245722788, 'fraction_numerical': 0.0037193156459211507, 'mean_word_length': 5.092900302114804, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 45, 'https://': 2, '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': '911765', 'n_tokens_mistral': 3019, 'n_tokens_neox': 2775, 'n_words': 544}