Skip to content

Commit f7e1dc3

Browse files
authored
Cancel2 (#226)
* add period * getNonExistentUser should be in htpasswd * move account policy checkbox down * rewrite * remove errors * remove debugging * fix autoload location * remove unnecessary redirect * revert unnecessary changes * phpcs * confirm account policy in test * post not get * agree not true * agree not true * add comments * revert
1 parent 5c84a6a commit f7e1dc3

File tree

3 files changed

+50
-60
lines changed

3 files changed

+50
-60
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

test/functional/CancelRequestTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testCancelPIRequest()
1919
try {
2020
http_post(
2121
__DIR__ . "/../../webroot/panel/new_account.php",
22-
["new_user_sel" => "pi", "eula" => "agree"]
22+
["new_user_sel" => "pi", "eula" => "agree", "confirm_pi" => "agree"]
2323
);
2424
} catch (PhpUnitNoDieException $e) {
2525
// Ignore the exception from http_post
@@ -29,9 +29,9 @@ public function testCancelPIRequest()
2929

3030
// Now try to cancel it
3131
try {
32-
http_get(
32+
http_post(
3333
__DIR__ . "/../../webroot/panel/new_account.php",
34-
["cancel" => "true"]
34+
["cancel" => "true"] # value of cancel is arbitrary
3535
);
3636
} catch (PhpUnitNoDieException $e) {
3737
// Ignore the exception from http_post
@@ -58,9 +58,9 @@ public function testCancelGroupJoinRequest()
5858

5959
// Now try to cancel it
6060
try {
61-
http_get(
61+
http_post(
6262
__DIR__ . "/../../webroot/panel/new_account.php",
63-
["cancel" => "true"]
63+
["cancel" => "true"] # value of cancel is arbitrary
6464
);
6565
} catch (PhpUnitNoDieException $e) {
6666
// Ignore the exception from http_post

webroot/panel/new_account.php

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,48 @@
44

55
use UnityWebPortal\lib\UnitySite;
66
use UnityWebPortal\lib\UnityGroup;
7+
use UnityWebPortal\lib\UnitySQL;
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+
if (isset($_POST["new_user_sel"])) {
17+
if (!isset($_POST["eula"]) || $_POST["eula"] != "agree") {
18+
UnitySite::badRequest("user did not agree to EULA");
19+
}
20+
if ($_POST["new_user_sel"] == "not_pi") {
21+
$form_group = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
22+
if (!$form_group->exists()) {
23+
UnitySite::badRequest("The selected PI does not exist");
24+
}
25+
$form_group->newUserRequest($USER);
2726
}
28-
}
29-
// Request Account Form was Submitted
30-
if (count($errors) == 0) {
3127
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.");
28+
if (!isset($_POST["confirm_pi"]) || $_POST["confirm_pi"] != "agree") {
29+
UnitySite::badRequest("user did not agree to account policy");
3530
}
36-
// requesting a PI account
3731
$USER->getPIGroup()->requestGroup($SEND_PIMESG_TO_ADMINS);
38-
} elseif ($_POST["new_user_sel"] == "not_pi") {
39-
$form_group->newUserRequest($USER);
4032
}
4133
}
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);
34+
elseif (isset($_POST["cancel"])) {
35+
foreach ($pending_requests as $request) {
36+
if ($request["request_for"] == "admin") {
37+
$USER->getPIGroup()->cancelGroupRequest();
38+
} else {
39+
$pi_group = new UnityGroup($request["request_for"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
40+
$pi_group->cancelGroupJoinRequest($user=$USER);
41+
}
5342
}
43+
} else {
44+
UnitySite::badRequest("neither 'new_user_sel' or 'cancel' are set!");
5445
}
5546
UnitySite::redirect($_SERVER['PHP_SELF']);
5647
}
57-
48+
require_once $LOC_HEADER;
5849
?>
5950

6051
<h1>Request Account</h1>
@@ -63,21 +54,30 @@
6354
<?php if (count($pending_requests) > 0) : ?>
6455
<p>You have pending account activation requests:</p>
6556
<?php foreach ($pending_requests as $request) : ?>
57+
<ul><li>
6658
<?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>";
59+
$pi_uid = $request["request_for"];
60+
if ($pi_uid == UnitySQL::REQUEST_BECOME_PI) {
61+
$group_uid = $USER->getPIGroup()->getPIUID();
62+
echo "<p>Ownership of PI Account/Group: <code>$group_uid</code> </p>";
7363
} else {
7464
$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>";
65+
echo "<p>Membership in PI Group owned by: <code>$owner_uid</code></p>";
7866
}
7967
?>
80-
<a href="?cancel=true">Cancel Request</a>
68+
</li></ul>
69+
<hr>
70+
<p><strong>Requesting Ownership of PI Account/Group</strong></p>
71+
<p>You will receive an email when your account has been approved.</p>
72+
<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>
73+
<br>
74+
<p><strong>Requesting Membership in a PI Group</strong></p>
75+
<p>You will receive an email when your account has been approved by the PI.</p>
76+
<p>You may need to remind them.</p>
77+
<hr>
78+
<form action="" method="POST">
79+
<input name="cancel" style='margin-top: 10px;' type='submit' value='Cancel Request'/>
80+
</form>
8181
<?php endforeach; ?>
8282
<?php else : ?>
8383
<form id="newAccountForm" action="" method="POST">
@@ -116,16 +116,6 @@
116116

117117
<br>
118118
<input style='margin-top: 10px;' type='submit' value='Request Account'>
119-
120-
<?php
121-
if (isset($errors)) {
122-
echo "<div class='message'>";
123-
foreach ($errors as $err) {
124-
echo "<p class='message-failure'>" . $err . "</p>";
125-
}
126-
echo "</div>";
127-
}
128-
?>
129119
</form>
130120
<?php endif; ?>
131121

0 commit comments

Comments
 (0)