Skip to content

Commit bef3510

Browse files
committed
handle github keys api properly
1 parent a1679de commit bef3510

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

resources/lib/UnitySite.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ public static function getGithubKeys($username)
3636
curl_setopt($curl, CURLOPT_URL, $url);
3737
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
3838
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
39-
$output = json_decode(curl_exec($curl), true);
39+
$keys = json_decode(curl_exec($curl), false);
4040
curl_close($curl);
4141

42-
$out = array();
43-
foreach ($output as $value) {
44-
array_push($out, $value["key"]);
42+
// normally returns array of objects each with a ->key attribute
43+
// if bad URL or no such user, returns status=404 object
44+
// if no keys, returns []
45+
if ((!is_array($keys)) || (count($keys) == 0)) {
46+
return [];
4547
}
46-
47-
return $out;
48+
return array_map(function($x){return $x->key;}, $keys);
4849
}
4950

5051
public static function testValidSSHKey($key_str)

webroot/panel/account.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
break;
3939
case "github":
4040
$gh_user = $_POST["gh_user"];
41-
if (empty($gh_user)) {
42-
break;
43-
}
4441
$keys = UnitySite::getGithubKeys($gh_user);
4542
foreach ($keys as $key) {
4643
if (UnitySite::testValidSSHKey($key)) {

0 commit comments

Comments
 (0)