Skip to content

Commit 9929878

Browse files
committed
Add Pterodactyl API key form to /account/edit page
1 parent 63b4c02 commit 9929878

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

public/js/app.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,11 +1241,62 @@ function renderAccountEdit() {
12411241
<button type="submit" class="btn btn-primary btn-full" id="change-pw-btn">Change Password</button>
12421242
</form>
12431243
</div>
1244+
1245+
<div class="card">
1246+
<h2 class="card-title" style="margin-bottom:8px">Pterodactyl API Key</h2>
1247+
<p style="color:var(--text-secondary);font-size:0.85rem;line-height:1.6;margin-bottom:16px">
1248+
Add your Pterodactyl Client API key to enable live resource monitoring and server power state detection directly in the dashboard.
1249+
Generate one at <a href="https://panel.zero-host.org/account/api" target="_blank">panel.zero-host.org/account/api</a>.
1250+
</p>
1251+
<form id="api-key-form">
1252+
<div class="api-key-input-group">
1253+
<input type="password" id="ptero-api-key-input" placeholder="ptla_..." autocomplete="off" />
1254+
<button type="submit" class="btn btn-primary" id="save-api-key-btn">Save</button>
1255+
</div>
1256+
</form>
1257+
<div id="api-key-status" style="margin-top:8px;font-size:0.82rem;color:var(--text-muted)"></div>
1258+
</div>
12441259
</div>
12451260
`;
12461261

12471262
$('#change-email-form').addEventListener('submit', handleChangeEmail);
12481263
$('#change-password-form').addEventListener('submit', handleChangePassword);
1264+
$('#api-key-form').addEventListener('submit', handleSaveApiKey);
1265+
}
1266+
1267+
async function handleSaveApiKey(e) {
1268+
e.preventDefault();
1269+
const btn = $('#save-api-key-btn');
1270+
const input = $('#ptero-api-key-input');
1271+
const status = $('#api-key-status');
1272+
const key = input.value.trim();
1273+
1274+
if (!key) {
1275+
status.textContent = 'Please enter an API key.';
1276+
status.style.color = 'var(--accent-red)';
1277+
return;
1278+
}
1279+
1280+
btn.disabled = true;
1281+
btn.innerHTML = '<span class="spinner"></span>';
1282+
status.textContent = '';
1283+
1284+
try {
1285+
await api('/servers/client-api-key', {
1286+
method: 'PUT',
1287+
body: JSON.stringify({ apiKey: key }),
1288+
});
1289+
status.textContent = 'API key saved successfully!';
1290+
status.style.color = 'var(--accent-green)';
1291+
input.value = '';
1292+
showToast('Pterodactyl API key saved', 'success');
1293+
} catch (err) {
1294+
status.textContent = err.message;
1295+
status.style.color = 'var(--accent-red)';
1296+
} finally {
1297+
btn.disabled = false;
1298+
btn.innerHTML = 'Save';
1299+
}
12491300
}
12501301

12511302
function renderAccountLinks() {

0 commit comments

Comments
 (0)