Skip to content

Commit aef306a

Browse files
committed
allow empty die(), rename unauthorized to forbidden
1 parent ce9409d commit aef306a

File tree

9 files changed

+23
-15
lines changed

9 files changed

+23
-15
lines changed

resources/lib/UnitySite.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@
77

88
class UnitySite
99
{
10-
public static function die($x)
10+
public static function die($x = null)
1111
{
1212
if (@$GLOBALS["PHPUNIT_NO_DIE_PLEASE"] == true) {
13-
throw new PhpUnitNoDieException(strval($x));
13+
if (is_null($x)) {
14+
throw new PhpUnitNoDieException();
15+
} else {
16+
throw new PhpUnitNoDieException($x);
17+
}
1418
} else {
15-
die($x);
19+
if (is_null($x)) {
20+
die();
21+
} else {
22+
die($x);
23+
}
1624
}
1725
}
1826

@@ -28,7 +36,7 @@ public static function headerResponseCode(int $code)
2836
{
2937
$responseCodeMessage = @http_response_code($code) ?? "";
3038
$msg = $_SERVER["SERVER_PROTOCOL"] . " " . strval($code) . " " . $responseCodeMessage;
31-
header($msg, true, $ncode);
39+
header($msg, true, $code);
3240
}
3341

3442
public static function errorLog(string $title, string $message)
@@ -53,10 +61,10 @@ public static function badRequest($message)
5361
self::die();
5462
}
5563

56-
public static function unauthorized($message)
64+
public static function forbidden($message)
5765
{
58-
self::headerResponseCode(401);
59-
self::errorLog("unauthorized", $message);
66+
self::headerResponseCode(403);
67+
self::errorLog("forbidden", $message);
6068
self::die();
6169
}
6270

webroot/admin/ajax/get_group_members.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use UnityWebPortal\lib\UnitySite;
77

88
if (!$USER->isAdmin()) {
9-
UnitySite::unauthorized("not an admin");
9+
UnitySite::forbidden("not an admin");
1010
}
1111

1212
if (!isset($_GET["pi_uid"])) {

webroot/admin/ajax/get_page_contents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use UnityWebPortal\lib\UnitySite;
66

77
if (!$USER->isAdmin()) {
8-
UnitySite::unauthorized("not an admin");
8+
UnitySite::forbidden("not an admin");
99
}
1010

1111
if (!isset($_GET["pageid"])) {

webroot/admin/content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use UnityWebPortal\lib\UnitySite;
66

77
if (!$USER->isAdmin()) {
8-
UnitySite::unauthorized("not an admin");
8+
UnitySite::forbidden("not an admin");
99
}
1010

1111
if ($_SERVER["REQUEST_METHOD"] == "POST") {

webroot/admin/notices.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use UnityWebPortal\lib\UnitySite;
66

77
if (!$USER->isAdmin()) {
8-
UnitySite::unauthorized("not an admin");
8+
UnitySite::forbidden("not an admin");
99
}
1010

1111
if ($_SERVER["REQUEST_METHOD"] == "POST") {

webroot/admin/pi-mgmt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use UnityWebPortal\lib\UnitySite;
88

99
if (!$USER->isAdmin()) {
10-
UnitySite::unauthorized("not an admin");
10+
UnitySite::forbidden("not an admin");
1111
}
1212

1313
if ($_SERVER["REQUEST_METHOD"] == "POST") {

webroot/admin/user-mgmt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use UnityWebPortal\lib\UnitySite;
66

77
if (!$USER->isAdmin()) {
8-
UnitySite::unauthorized("not an admin");
8+
UnitySite::forbidden("not an admin");
99
}
1010

1111
if ($_SERVER["REQUEST_METHOD"] == "POST") {

webroot/panel/ajax/get_group_members.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222

2323
if ($found) {
24-
UnitySite::unauthorized("not a group member");
24+
UnitySite::forbidden("not a group member");
2525
}
2626

2727
$count = count($members);

webroot/panel/pi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$group = $USER->getPIGroup();
99

1010
if (!$USER->isPI()) {
11-
UnitySite::unauthorized("not a PI");
11+
UnitySite::forbidden("not a PI");
1212
}
1313

1414
if ($_SERVER["REQUEST_METHOD"] == "POST") {

0 commit comments

Comments
 (0)