|
6 | 6 | use UnityWebPortal\lib\UnityGroup; |
7 | 7 | use UnityWebPortal\lib\UnityHTTPD; |
8 | 8 |
|
| 9 | +$getPIGroupFromPost = function () { |
| 10 | + global $LDAP, $SQL, $MAILER, $WEBHOOK; |
| 11 | + $gid_or_mail = UnityHTTPD::getPostData("pi"); |
| 12 | + if (substr($gid_or_mail, 0, 3) !== "pi_" && str_contains($gid_or_mail, "@")) { |
| 13 | + try { |
| 14 | + $gid_or_mail = UnityGroup::ownerMail2GID($gid_or_mail); |
| 15 | + } catch (EntryNotFoundException) { |
| 16 | + // oh well, we tried |
| 17 | + } |
| 18 | + } |
| 19 | + $pi_group = new UnityGroup($gid_or_mail, $LDAP, $SQL, $MAILER, $WEBHOOK); |
| 20 | + if (!$pi_group->exists()) { |
| 21 | + UnityHTTPD::messageError("This PI Doesn't Exist", $gid_or_mail); |
| 22 | + UnityHTTPD::redirect(); |
| 23 | + } |
| 24 | + return $pi_group; |
| 25 | +}; |
| 26 | + |
9 | 27 | if ($_SERVER["REQUEST_METHOD"] == "POST") { |
10 | 28 | UnityHTTPD::validatePostCSRFToken(); |
11 | 29 | if (isset($_POST["form_type"])) { |
12 | | - if (isset($_POST["pi"])) { |
13 | | - $pi_groupname = $_POST["pi"]; |
14 | | - if (substr($pi_groupname, 0, 3) !== "pi_" && str_contains($pi_groupname, "@")) { |
15 | | - try { |
16 | | - $pi_groupname = UnityGroup::ownerMail2GID($pi_groupname); |
17 | | - } catch (EntryNotFoundException) { |
18 | | - } |
19 | | - } |
20 | | - $pi_account = new UnityGroup($pi_groupname, $LDAP, $SQL, $MAILER, $WEBHOOK); |
21 | | - if (!$pi_account->exists()) { |
22 | | - UnityHTTPD::messageError( |
23 | | - "Invalid Group Membership Request", |
24 | | - "This PI doesn't exist" |
25 | | - ); |
26 | | - UnityHTTPD::redirect(); |
27 | | - } |
28 | | - } |
29 | | - |
30 | 30 | switch ($_POST["form_type"]) { |
31 | 31 | case "addPIform": |
| 32 | + $pi_account = $getPIGroupFromPost(); |
32 | 33 | if (!isset($_POST["tos"]) || $_POST["tos"] != "agree") { |
33 | 34 | UnityHTTPD::badRequest("user did not agree to terms of service"); |
34 | 35 | } |
|
50 | 51 | } |
51 | 52 | $pi_account->newUserRequest($USER); |
52 | 53 | UnityHTTPD::redirect(); |
53 | | - break; |
| 54 | + break; /** @phpstan-ignore deadCode.unreachable */ |
54 | 55 | case "removePIForm": |
| 56 | + $pi_account = $getPIGroupFromPost(); |
55 | 57 | $pi_account->removeUser($USER); |
56 | 58 | UnityHTTPD::redirect(); |
57 | | - break; |
| 59 | + break; /** @phpstan-ignore deadCode.unreachable */ |
58 | 60 | case "cancelPIForm": |
| 61 | + $pi_account = $getPIGroupFromPost(); |
59 | 62 | $pi_account->cancelGroupJoinRequest($USER); |
60 | 63 | UnityHTTPD::redirect(); |
61 | | - break; |
| 64 | + break; /** @phpstan-ignore deadCode.unreachable */ |
62 | 65 | } |
63 | 66 | } |
64 | 67 | } |
|
0 commit comments