|
86 | 86 | die(); |
87 | 87 | } |
88 | 88 | } |
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( |
93 | 94 | 'Accept: application/json', |
94 | | - 'Authorization: Bearer ' . SettingsManager::getSetting("PterodactylAPIKey"), |
95 | 95 | '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( |
100 | 99 | 'username' => $username, |
101 | 100 | 'first_name' => $first_name, |
102 | 101 | '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; |
115 | 113 |
|
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(); |
122 | 160 | die(); |
123 | 161 | } |
124 | 162 | } 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?"); |
126 | 164 | die(); |
127 | 165 | } |
128 | | - } |
129 | 166 |
|
130 | | - curl_close($ch); |
| 167 | + } else { |
| 168 | + $panel_id = $result['attributes']['id']; |
| 169 | + } |
131 | 170 |
|
132 | 171 | $conn->query("INSERT INTO mythicaldash_login_logs (ipaddr, userkey) VALUES ('" . $session->getIP() . "', '$skey')"); |
133 | 172 | $default = "https://www.gravatar.com/avatar/00000000000000000000000000000000"; |
|
157 | 196 | `backups`, |
158 | 197 | `first_ip` |
159 | 198 | ) VALUES ( |
160 | | - '" . $panelId . "', |
| 199 | + '" . $panel_id . "', |
161 | 200 | '" . $email . "', |
162 | 201 | '" . $username . "', |
163 | 202 | '" . Encryption::encrypt($first_name, $ekey) . "', |
|
185 | 224 | die(); |
186 | 225 | } else { |
187 | 226 | header('location: /auth/register?e=Username or email already exists. Please choose a different one'); |
| 227 | + $conn->close(); |
188 | 228 | die(); |
189 | 229 | } |
190 | 230 | } else { |
191 | 231 | header('location: /auth/register?e=Please fill in all the required info'); |
| 232 | + $conn->close(); |
192 | 233 | die(); |
193 | 234 | } |
194 | 235 | } else { |
195 | 236 | header("location: /auth/register?e=I'm sorry, but it looks like the pterodactyl panel is not linked to the dash."); |
| 237 | + $conn->close(); |
196 | 238 | die(); |
197 | 239 | } |
198 | 240 | } else { |
199 | 241 | header("location: /auth/register?e=Captcha verification failed; please refresh!"); |
| 242 | + $conn->close(); |
200 | 243 | die(); |
201 | 244 | } |
202 | 245 | } |
|
0 commit comments