Skip to content

Commit 7b6c25a

Browse files
committed
rewrite
1 parent d475f38 commit 7b6c25a

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

resources/lib/UnitySQL.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class UnitySQL
2020

2121

2222
// FIXME this string should be changed to something more intuitive, requires production sql change
23-
private const REQUEST_BECOME_PI = "admin";
23+
public const REQUEST_BECOME_PI = "admin";
2424

2525
private $conn;
2626

webroot/panel/new_account.php

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,53 @@
11
<?php
22

3-
require_once __DIR__ . "/../../resources/autoload.php";
4-
53
use UnityWebPortal\lib\UnitySite;
64
use UnityWebPortal\lib\UnityGroup;
5+
use UnityWebPortal\lib\UnitySQL;
6+
7+
require_once __DIR__ . "/../../resources/autoload.php";
78

8-
require_once $LOC_HEADER;
99
if ($USER->exists()) {
10-
UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel/index.php"); // Redirect if account already exists
10+
UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel/index.php");
1111
}
1212

1313
$pending_requests = $SQL->getRequestsByUser($USER->getUID());
1414

1515
if ($_SERVER["REQUEST_METHOD"] == "POST") {
16-
$errors = array();
17-
18-
if (!isset($_POST["eula"]) || $_POST["eula"] != "agree") {
19-
// checkbox was not checked
20-
array_push($errors, "Accepting the EULA is required");
21-
}
22-
23-
if ($_POST["new_user_sel"] == "not_pi") {
24-
$form_group = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
25-
if (!$form_group->exists()) {
26-
array_push($errors, "The selected PI does not exist");
16+
echo json_encode($_POST);
17+
if (isset($_POST["new_user_sel"])) {
18+
if (($_POST["eula"] ?? "disagree") != "agree") {
19+
UnitySite::badRequest("user did not agree to EULA");
20+
}
21+
if ($_POST["new_user_sel"] == "not_pi") {
22+
$form_group = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
23+
if (!$form_group->exists()) {
24+
UnitySite::badRequest("The selected PI does not exist");
25+
}
26+
$form_group->newUserRequest($USER);
2727
}
28-
}
29-
// Request Account Form was Submitted
30-
if (count($errors) == 0) {
3128
if ($_POST["new_user_sel"] == "pi") {
32-
if (!isset($_POST["chk_pi"]) || $_POST["chk_pi"] != "agree") {
33-
// checkbox was not checked
34-
array_push($errors, "Please confirm you have read the account policy guidelines.");
29+
if (($_POST["confirm_pi"] ?? "disagree") != "agree") {
30+
UnitySite::badRequest("user did not agree to account policy");
3531
}
36-
// requesting a PI account
3732
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS);
38-
} elseif ($_POST["new_user_sel"] == "not_pi") {
39-
$form_group->newUserRequest($USER);
4033
}
4134
}
42-
UnitySite::redirect($_SERVER['PHP_SELF']);
43-
}
44-
45-
if (isset($_GET['cancel']) && count($pending_requests) > 0) {
46-
foreach ($pending_requests as $request) {
47-
if ($request["request_for"] == "admin") {
48-
// cancel PI request
49-
$USER->getPIGroup()->cancelGroupRequest();
50-
} else {
51-
$pi_group = new UnityGroup($request["request_for"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
52-
$pi_group->cancelGroupJoinRequest($user=$USER);
35+
else if (isset($_POST["cancel"])) {
36+
foreach ($pending_requests as $request) {
37+
if ($request["request_for"] == "admin") {
38+
$USER->getPIGroup()->cancelGroupRequest();
39+
} else {
40+
$pi_group = new UnityGroup($request["request_for"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
41+
$pi_group->cancelGroupJoinRequest($user=$USER);
42+
}
5343
}
44+
UnitySite::redirect($_SERVER['PHP_SELF']);
45+
} else {
46+
UnitySite::badRequest("neither 'new_user_sel' or 'cancel' are set!");
5447
}
5548
UnitySite::redirect($_SERVER['PHP_SELF']);
5649
}
57-
50+
require_once $LOC_HEADER;
5851
?>
5952

6053
<h1>Request Account</h1>
@@ -63,21 +56,30 @@
6356
<?php if (count($pending_requests) > 0) : ?>
6457
<p>You have pending account activation requests:</p>
6558
<?php foreach ($pending_requests as $request) : ?>
59+
<ul><li>
6660
<?php
67-
$pi_uid = $request["request_for"];
68-
if ($pi_uid == "admin") {
69-
echo "<p>Requesting a PI account</p>";
70-
echo "<p>You will receive an email when your account has been approved.</p>";
71-
echo "<p>Email <a href=\"mailto:{$CONFIG['mail']['support']}\">{$CONFIG['mail']['support_name']}</a>";
72-
echo " if you have not heard back in one business day. </p>";
61+
$pi_uid = $request["request_for"];
62+
if ($pi_uid == UnitySQL::REQUEST_BECOME_PI) {
63+
$group_uid = $USER->getPIGroup()->getPIUID();
64+
echo "<p>Ownership of PI Account/Group: <code>$group_uid</code> </p>";
7365
} else {
7466
$owner_uid = UnityGroup::getUIDfromPIUID($pi_uid);
75-
echo "<p>Joining existing group owned by " . $owner_uid . "</p>";
76-
echo "<p>You will receive an email when your account has been approved by the PI.";
77-
echo "You may need to remind them.</p>";
67+
echo "<p>Membership in PI Group owned by: <code>$owner_uid</code></p>";
7868
}
7969
?>
80-
<a href="?cancel=true">Cancel Request</a>
70+
</li></ul>
71+
<hr>
72+
<p><strong>Requesting Ownership of PI Account/Group</strong></p>
73+
<p>You will receive an email when your account has been approved.</p>
74+
<p>Email <a href="mailto:<?php echo $CONFIG['mail']['support']; ?>"><?php echo $CONFIG['mail']['support_name']; ?></a> if you have not heard back in one business day. </p>
75+
<br>
76+
<p><strong>Requesting Membership in a PI Group</strong></p>
77+
<p>You will receive an email when your account has been approved by the PI.</p>
78+
<p>You may need to remind them.</p>
79+
<hr>
80+
<form action="" method="POST">
81+
<input name="cancel" style='margin-top: 10px;' type='submit' value='Cancel Request'/>
82+
</form>
8183
<?php endforeach; ?>
8284
<?php else : ?>
8385
<form id="newAccountForm" action="" method="POST">

0 commit comments

Comments
 (0)