Skip to content

Commit 5c81170

Browse files
committed
PUSH
-> Pterodactyl Registration Rewrite
1 parent a22e03a commit 5c81170

File tree

1 file changed

+74
-31
lines changed

1 file changed

+74
-31
lines changed

view/auth/register.php

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,48 +86,87 @@
8686
die();
8787
}
8888
}
89-
$ch = curl_init();
90-
curl_setopt($ch, CURLOPT_URL, SettingsManager::getSetting("PterodactylURL") . '/api/application/users');
91-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
92-
curl_setopt($ch, CURLOPT_HTTPHEADER, [
89+
$pterodactyl_url = SettingsManager::getSetting("PterodactylURL");
90+
$pterodactyl_api = SettingsManager::getSetting("PterodactylAPIKey");
91+
92+
$panelapi = curl_init($pterodactyl_url . "/api/application/users");
93+
$headers = array(
9394
'Accept: application/json',
94-
'Authorization: Bearer ' . SettingsManager::getSetting("PterodactylAPIKey"),
9595
'Content-Type: application/json',
96-
]);
97-
curl_setopt($ch, CURLOPT_POST, true);
98-
$data = [
99-
'email' => $email,
96+
'Authorization: Bearer ' . $pterodactyl_api
97+
);
98+
$postfields = array(
10099
'username' => $username,
101100
'first_name' => $first_name,
102101
'last_name' => $last_name,
103-
'password' => $upassword,
104-
'language' => 'en',
105-
];
106-
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
107-
$response = curl_exec($ch);
108-
109-
if (curl_errno($ch)) {
110-
$error_message = curl_error($ch);
111-
header('location: /auth/register?e=We are sorry but our panel is down!');
112-
die();
113-
} else {
114-
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
102+
'email' => $email,
103+
'password' => $upassword
104+
);
105+
curl_setopt($panelapi, CURLOPT_HTTPHEADER, $headers);
106+
curl_setopt($panelapi, CURLOPT_POST, 1);
107+
curl_setopt($panelapi, CURLOPT_RETURNTRANSFER, 1);
108+
curl_setopt($panelapi, CURLOPT_POSTFIELDS, json_encode($postfields));
109+
$result = curl_exec($panelapi);
110+
curl_close($panelapi);
111+
$result = json_decode($result, true);
112+
$panel_id = null;
115113

116-
if ($http_status === 201) {
117-
$responseData = json_decode($response, true);
118-
if (isset($responseData['attributes']['id'])) {
119-
$panelId = $responseData['attributes']['id'];
120-
} else {
121-
header('location: /auth/register?e=We are sorry but our panel is down!');
114+
if (!isset($result['object'])) {
115+
$error = $result['errors'][0]['detail'];
116+
if ($error == "The email has already been taken.") {
117+
$ch = curl_init($pterodactyl_url . "/api/application/users?filter%5Bemail%5D=$email");
118+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
119+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
120+
'Authorization: Bearer ' . $pterodactyl_api,
121+
'Content-Type: application/json',
122+
'Accept: application/json'
123+
)
124+
);
125+
$result12 = curl_exec($ch);
126+
curl_close($ch);
127+
$result13 = json_decode($result12, true);
128+
if (!isset($result13['object'])) {
129+
header("location: /auth/login?e=There was an unexpected error while attempting to link your panel account to the client portal.");
130+
$conn->close();
131+
die();
132+
}
133+
$panel_id = $result13['data'][0]['attributes']['id'];
134+
$ch = curl_init($pterodactyl_url . "/api/application/users/$panel_id");
135+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
136+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
137+
'Authorization: Bearer ' . $pterodactyl_api,
138+
'Content-Type: application/json',
139+
'Accept: application/json'
140+
)
141+
);
142+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
143+
curl_setopt($ch, CURLOPT_POST, 1);
144+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(
145+
array(
146+
'username' => $username,
147+
'first_name' => $first_name,
148+
'last_name' => $last_name,
149+
'email' => $email,
150+
'password' => $upassword,
151+
'language' => 'en'
152+
)
153+
));
154+
$updateUserResult = curl_exec($ch);
155+
curl_close($ch);
156+
$updateUserResult = json_decode($updateUserResult, true);
157+
if (!isset($updateUserResult['object'])) {
158+
header('location: /auth/login?e=There was an error while updating your panel information on sign-up');
159+
$conn->close();
122160
die();
123161
}
124162
} else {
125-
header('location: /auth/register?e=We are sorry but our panel is down!');
163+
header("location: /auth/login?e=There was an error while signing up. Is our game panel down?");
126164
die();
127165
}
128-
}
129166

130-
curl_close($ch);
167+
} else {
168+
$panel_id = $result['attributes']['id'];
169+
}
131170

132171
$conn->query("INSERT INTO mythicaldash_login_logs (ipaddr, userkey) VALUES ('" . $session->getIP() . "', '$skey')");
133172
$default = "https://www.gravatar.com/avatar/00000000000000000000000000000000";
@@ -157,7 +196,7 @@
157196
`backups`,
158197
`first_ip`
159198
) VALUES (
160-
'" . $panelId . "',
199+
'" . $panel_id . "',
161200
'" . $email . "',
162201
'" . $username . "',
163202
'" . Encryption::encrypt($first_name, $ekey) . "',
@@ -185,18 +224,22 @@
185224
die();
186225
} else {
187226
header('location: /auth/register?e=Username or email already exists. Please choose a different one');
227+
$conn->close();
188228
die();
189229
}
190230
} else {
191231
header('location: /auth/register?e=Please fill in all the required info');
232+
$conn->close();
192233
die();
193234
}
194235
} else {
195236
header("location: /auth/register?e=I'm sorry, but it looks like the pterodactyl panel is not linked to the dash.");
237+
$conn->close();
196238
die();
197239
}
198240
} else {
199241
header("location: /auth/register?e=Captcha verification failed; please refresh!");
242+
$conn->close();
200243
die();
201244
}
202245
}

0 commit comments

Comments
 (0)