<commit_before><?php

require_once __DIR__.'/config.php';
require_once __DIR__.'/vendor/autoload.php';
require_once(__DIR__."/lib/connect.php");
require_once(__DIR__."/lib/oauth_server.php");

$db = connect();

// Handle a request to a resource and authenticate the access token
$server = oauth_server($db);
$request = OAuth2\Request::createFromGlobals();
$token = $server->getAccessTokenData($request);
$response = new OAuth2\Response();
if (!$server->verifyResourceRequest($request, $response)) {
    $response->send();
    die;
}
$user_id = $token['user_id'];

$stmt = $db->prepare("SELECT `id`, `sLogin`, `sFirstName`, `sLastName` FROM `users` WHERE `id` = :user_id");
$stmt->execute(['user_id' => $user_id]);
$user = $stmt->fetchObject();

$stmt = $db->prepare("SELECT `sBadge` FROM `user_badges` WHERE `idUser` = :user_id");
$stmt->execute(['user_id' => $user_id]);
$badges = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);

if (false /* TODO: interroger la base castor */)
  $badges[] = 'alkindi2015_tour2';

echo json_encode([
  'id' => $user_id,
  'sLogin' => $user->sLogin,
  'sFirstName' => $user->sFirstName,
  'sLastName' => $user->sLastName,
  'badges' => $badges
]);
<commit_msg>clean up and use idUser key in profile<commit_after><?php

require_once __DIR__.'/config.php';
require_once __DIR__.'/vendor/autoload.php';
require_once(__DIR__."/lib/connect.php");
require_once(__DIR__."/lib/oauth_server.php");

$db = connect();

// Handle a request to a resource and authenticate the access token
$server = oauth_server($db);
$request = OAuth2\Request::createFromGlobals();
$token = $server->getAccessTokenData($request);
$response = new OAuth2\Response();
if (!$server->verifyResourceRequest($request, $response)) {
    $response->send();
    die;
}
$user_id = $token['user_id'];

$stmt = $db->prepare("SELECT `id`, `sLogin`, `sFirstName`, `sLastName` FROM `users` WHERE `id` = :user_id");
$stmt->execute(['user_id' => $user_id]);
$user = $stmt->fetchObject();

$stmt = $db->prepare("SELECT `sBadge` FROM `user_badges` WHERE `idUser` = :user_id");
$stmt->execute(['user_id' => $user_id]);
$badges = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);

echo json_encode([
  'idUser' => $user_id,
  'sLogin' => $user->sLogin,
  'sFirstName' => $user->sFirstName,
  'sLastName' => $user->sLastName,
  'badges' => $badges
]);

{'fraction_non_alphanumeric': 0.2048401037165082, 'fraction_numerical': 0.004753673292999135, 'mean_word_length': 5.951951951951952, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '2801986', 'n_tokens_mistral': 856, 'n_tokens_neox': 845, 'n_words': 168}