Skip to content

Commit ee27823

Browse files
committed
replace hacky JS with standard alert function
1 parent d1c4f66 commit ee27823

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

resources/lib/UnitySite.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ public static function testValidSSHKey($key_str)
5656
return false;
5757
}
5858
}
59+
60+
public function alert(string $msg): void{
61+
echo "<script type='text/javascript'>alert(" . json_encode($msg) . ");</script>";
62+
}
5963
}

webroot/panel/account.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
require_once $LOC_HEADER;
88

9-
$invalid_ssh_dialogue = "<script type='text/javascript'>
10-
alert('Invalid SSH key. Please verify your public key file is valid.');
11-
</script>";
9+
$invalid_ssh_dialogue = "Invalid SSH key. Please verify your public key file is valid.";
1210

1311
if ($_SERVER['REQUEST_METHOD'] == "POST") {
1412
switch ($_POST["form_type"]) {
@@ -21,7 +19,7 @@
2119
if (UnitySite::testValidSSHKey($key)) {
2220
array_push($added_keys, $key);
2321
} else {
24-
echo $invalid_ssh_dialogue;
22+
$SITE->alert($invalid_ssh_dialogue);
2523
}
2624
break;
2725
case "import":
@@ -30,7 +28,7 @@
3028
if (UnitySite::testValidSSHKey($key)) {
3129
array_push($added_keys, $key);
3230
} else {
33-
echo $invalid_ssh_dialogue;
31+
$SITE->alert($invalid_ssh_dialogue);
3432
}
3533
break;
3634
case "generate":

webroot/panel/groups.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
$errors = array();
1010

1111
if (isset($_POST["form_name"])) {
12+
$ok = true;
1213
if (isset($_POST["pi"])) {
1314
$pi_account = new UnityGroup(trim($_POST["pi"]), $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
1415
if (!$pi_account->exists()) {
15-
// "\'" instead of "'", otherwise it will close a single quote used to place the message
16-
array_push($modalErrors, "This PI doesn\'t exist");
16+
$SITE->alert("This PI doesn't exist");
17+
$ok = false;
1718
}
1819
}
1920

@@ -23,15 +24,17 @@
2324
// existing PI request
2425

2526
if ($pi_account->requestExists($USER)) {
26-
array_push($modalErrors, "You\'ve already requested this");
27+
$SITE->alert("You\'ve already requested this");
28+
$ok = false;
2729
}
2830

2931
if ($pi_account->userExists($USER)) {
30-
array_push($modalErrors, "You\'re already in this PI group");
32+
$SITE->alert("You\'re already in this PI group");
33+
$ok = false;
3134
}
3235

3336
// Add row to sql
34-
if (empty($modalErrors)) {
37+
if ($ok) {
3538
$pi_account->newUserRequest($USER);
3639
}
3740
break;
@@ -145,19 +148,6 @@
145148
openModal("Add New PI", "<?php echo $CONFIG["site"]["prefix"]; ?>/panel/modal/new_pi.php");
146149
});
147150

148-
<?php
149-
// This is here to re-open the modal if there are errors
150-
if (isset($modalErrors) && is_array($modalErrors) && count($modalErrors) > 0) {
151-
$errorHTML = "";
152-
foreach ($modalErrors as $error) {
153-
$errorHTML .= "<span>$error</span>";
154-
}
155-
156-
echo "openModal('Add New PI', '" .
157-
$CONFIG["site"]["prefix"] . "/panel/modal/new_pi.php', '" . $errorHTML . "');";
158-
}
159-
?>
160-
161151
var ajax_url = "<?php echo $CONFIG["site"]["prefix"]; ?>/panel/ajax/get_group_members.php?pi_uid=";
162152
</script>
163153

0 commit comments

Comments
 (0)