<commit_before><?php
//// Allow from any origin
    if (isset($_SERVER['HTTP_ORIGIN'])) {
        //header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Max-Age: 86400');    // cache for 1 day
    }
    // Access-Control headers are received during OPTIONS requests
    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
            header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");         

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
            header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

    }

chdir("../server");

require_once('system/includes.php');
require_once('libs/Slim/Slim.php');

\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();
$app->config('debug', true);


//===========================================================
$authenticateForRole = function () 
{
	//global $conOptions;
	$_dsn = diyConfig::read('db.dsn');
	$_username = diyConfig::read('db.username');
	$_password = diyConfig::read('db.password');
	$storage = new OAuth2\Storage\Pdo(array('dsn' => $_dsn, 'username' => $_username, 'password' => $_password));
	$server = new OAuth2\Server($storage);
	$server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage), array(
			'allow_credentials_in_request_body => true'
		)); 

	$cryptoStorage = new OAuth2\Storage\CryptoToken($storage);
	$server->addStorage($cryptoStorage, "access_token");
		
	$cryptoResponseType = new OAuth2\ResponseType\CryptoToken($storage);
	$server->addResponseType($cryptoResponseType);
	return $server;

};

$diy_storage = function () 
{
	//global $conOptions;
	$_dbfile = diyConfig::read('db.file');
 	$db = new PDO(sprintf('sqlite:%s', $_dbfile));
	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
	return $db;
};

$diy_exception = function () 
{
 	$exception = new CustomException();
	return $exception;<commit_msg>added email verification check in the /token function<commit_after><?php
//// Allow from any origin
    if (isset($_SERVER['HTTP_ORIGIN'])) {
        //header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Max-Age: 86400');    // cache for 1 day
    }
    // Access-Control headers are received during OPTIONS requests
    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
            header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");         

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
            header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

    }

chdir("../server");

require_once('system/includes.php');
require_once('libs/Slim/Slim.php');

\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();
$app->config('debug', true);


//===========================================================
class PdoStorageWithEmailVerification extends OAuth2\Storage\Pdo {
	// Override checkClientCredentials to add a check about whether the user is verified or not
    public function checkClientCredentials($client_id, $client_secret = null)
    {
        $stmt = $this->db->prepare(sprintf('SELECT * from %s c JOIN %s u ON c.user_id = u.user_id where c.client_id = :client_id and u.email_verified = 1',
			$this->config['client_table'],
			$this->config['user_table']
			));
        $stmt->execute(compact('client_id'));
        $result = $stmt->fetch();

        // make this extensible
        return $result && $result['client_secret'] == $client_secret;
    }
}
$authenticateForRole = function () 
{
	//global $conOptions;
	$_dsn = diyConfig::read('db.dsn');
	$_username = diyConfig::read('db.username');
	$_password = diyConfig::read('db.password');
	$storage = new PdoStorageWithEmailVerification(array('dsn' => $_dsn, 'username' => $_username, 'password' => $_password));
	$server = new OAuth2\Server($storage);
	$server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage), array(
			'allow_credentials_in_request_body => true'
		)); 

	$cryptoStorage = new OAuth2\Storage\CryptoToken($storage);
	$server->addStorage($cryptoStorage, "access_token");
		
	$cryptoResponseType = new OAuth2\ResponseType\CryptoToken($storage);
	$server->addResponseType($cryptoResponseType);
	return $server;

};

$diy_storage = function () 
{
	//global $conOptions;
	$_dbfile = diyConfig::read('db.file');
 	$db = new PDO(sprintf('sqlite:%s', $_dbfile));
	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
	return $db;
};

$diy_exception = function () 
{
 	$exception = new CustomException();
	return $exception;
{'fraction_non_alphanumeric': 0.1883656509695291, 'fraction_numerical': 0.004550850811238623, 'mean_word_length': 4.757403189066059, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '1155450', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1602, 'n_words': 276}