Skip to content

Commit

Permalink
Update callback.php (#227)
Browse files Browse the repository at this point in the history
* Update callback.php

* Update Src/callback.php

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update Src/callback.php

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: gstraccini[bot] <150967461+gstraccini[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent 8e9db46 commit dbae69b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Src/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,35 @@

$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $token",
"User-Agent: GStraccini-bot-website/1.0 (+https://github.com/guibranco/gstraccini-bot-website)",
"Accept: application/vnd.github+json",
"X-GitHub-Api-Version: 2022-11-28"
]);

$userData = curl_exec($ch);
$response = curl_exec($ch);

$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $headerSize);
$body = json_decode(substr($response, $headerSize), true);

curl_close($ch);

$user = json_decode($userData, true);
if (isset($body["message"])) {
header("Location: signin.php?error=" . urlencode($body["message"]));
exit();
}

if (isset($user['name']) === true && preg_match('/^(\w+)(?:\s+[\w\s]+)?\s+(\w+)$/', $user['name'], $matches)) {
if (isset($body['name']) === true && preg_match('/^(\w+)(?:\s+[\w\s]+)?\s+(\w+)$/', $body['name'], $matches)) {
$user['first_name'] = $matches[1];
$user['last_name'] = $matches[2];
}

$_SESSION['token'] = $token;
$_SESSION['user'] = $user;
$_SESSION['user'] = $body;

header('Location: dashboard.php');
exit();

0 comments on commit dbae69b

Please sign in to comment.