Skip to content

Commit b9b53d1

Browse files
committed
Cloud settings to dashboard
1 parent ef946b4 commit b9b53d1

File tree

2 files changed

+213
-0
lines changed

2 files changed

+213
-0
lines changed
0 Bytes
Binary file not shown.

host/web/index.html

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,50 @@ <h5 id="version_description">Description: loading...</h3>
13291329
</div>
13301330
</div>
13311331
</div>
1332+
<div class="section" id="cloud-section">
1333+
<div class="section_title">
1334+
<p>Cloud settings</p>
1335+
<div class="dropdown_icon"></div>
1336+
</div>
1337+
<div class="section_content">
1338+
<p style="font-size: 17px;">Manage your cloud connectivity and data synchronization.</p>
1339+
<div class="horizontal-align">
1340+
<label for="cloud-enable">Cloud sync:</label>
1341+
<select id="cloud-enable">
1342+
<option>Enabled</option>
1343+
<option>Disabled</option>
1344+
</select>
1345+
</div>
1346+
<div class="horizontal-align" style="margin-top: 15px;">
1347+
<label style="font-size: 16px; font-weight: 600;">Register Cloud Account</label>
1348+
</div>
1349+
<div class="horizontal-align">
1350+
<label for="cloud-email">Email:</label>
1351+
<input type="email" name="cloud-email" id="cloud-email" class="textbox">
1352+
</div>
1353+
<div class="horizontal-align">
1354+
<label for="cloud-username">Username:</label>
1355+
<input type="text" name="cloud-username" id="cloud-username" class="textbox">
1356+
</div>
1357+
<div class="horizontal-align">
1358+
<label for="cloud-password">Password:</label>
1359+
<input type="password" name="cloud-password" id="cloud-password" class="textbox">
1360+
</div>
1361+
<div class="horizontal-align" style="margin-top: 15px;">
1362+
<div style="width: 100%;"></div>
1363+
<div id="cloud_saved" class="saved_text">Account created</div>
1364+
<div class="accept_btn" id="cloud_accept"><img src="web/assets/pipe.png" alt="pipe" class="centered-img"></div>
1365+
</div>
1366+
<div class="horizontal-align" style="margin-top: 15px; border-top: 1px solid #333; padding-top: 15px;">
1367+
<label style="font-size: 16px; font-weight: 600; color: #e74c3c;">Danger Zone</label>
1368+
</div>
1369+
<div class="horizontal-align" style="margin-top: 10px;">
1370+
<label style="font-size: 14px;">Re-authenticate cloud connection</label>
1371+
<div style="width: 20px;"></div>
1372+
<div class="accept_btn" id="cloud_reauth" style="background-color: #f39c12;"><img src="web/assets/pipe.png" alt="pipe" class="centered-img"></div>
1373+
</div>
1374+
</div>
1375+
</div>
13321376
</div>
13331377
<div class="resize_handle"></div>
13341378
</div>
@@ -5718,5 +5762,174 @@ <h3 class="notification-title" id="notification-title"></h3>
57185762
}, 100);
57195763
}
57205764

5765+
async function loadCloudSettings() {
5766+
try {
5767+
const response = await fetch(`${baseURL}/api/cloud/get`, {
5768+
method: 'GET',
5769+
headers: getAuthHeaders()
5770+
});
5771+
5772+
if (response.ok) {
5773+
const settings = await response.json();
5774+
5775+
document.getElementById('cloud-enable').value = settings.enabled ? 'Enabled' : 'Disabled';
5776+
5777+
if (settings.email) {
5778+
document.getElementById('cloud-email').value = settings.email;
5779+
}
5780+
if (settings.username) {
5781+
document.getElementById('cloud-username').value = settings.username;
5782+
}
5783+
}
5784+
} catch (error) {
5785+
console.error('Error loading cloud settings:', error);
5786+
}
5787+
}
5788+
5789+
function isValidEmail(email) {
5790+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
5791+
return emailRegex.test(email);
5792+
}
5793+
5794+
async function saveCloudSettings() {
5795+
const enabled = document.getElementById('cloud-enable').value === 'Enabled';
5796+
5797+
try {
5798+
const response = await fetch(`${baseURL}/api/cloud/manage`, {
5799+
method: 'POST',
5800+
headers: {
5801+
...getAuthHeaders(),
5802+
'Content-Type': 'application/json'
5803+
},
5804+
body: JSON.stringify({
5805+
action: 'enable',
5806+
enabled: enabled
5807+
})
5808+
});
5809+
5810+
if (response.ok) {
5811+
const savedDiv = document.getElementById('cloud_saved');
5812+
if (savedDiv) {
5813+
savedDiv.classList.add('visible');
5814+
clearTimeout(savedDiv._hideTimeout);
5815+
savedDiv._hideTimeout = setTimeout(() => {
5816+
savedDiv.classList.remove('visible');
5817+
}, 5000);
5818+
}
5819+
} else {
5820+
const errorData = await response.json();
5821+
showNotification(`Failed to save cloud settings: ${errorData.error}`, 'error');
5822+
}
5823+
} catch (error) {
5824+
showNotification('Failed to save cloud settings', 'error');
5825+
}
5826+
}
5827+
5828+
async function signupCloudAccount() {
5829+
const email = document.getElementById('cloud-email').value.trim();
5830+
const username = document.getElementById('cloud-username').value.trim();
5831+
const password = document.getElementById('cloud-password').value;
5832+
5833+
if (!email || !username || !password) {
5834+
showNotification('Please fill in all fields for cloud signup', 'warning');
5835+
return;
5836+
}
5837+
5838+
if (!isValidEmail(email)) {
5839+
showNotification('Please enter a valid email address', 'warning');
5840+
return;
5841+
}
5842+
5843+
if (password.length < 6) {
5844+
showNotification('Password must be at least 6 characters long', 'warning');
5845+
return;
5846+
}
5847+
5848+
try {
5849+
const response = await fetch(`${baseURL}/api/cloud/manage`, {
5850+
method: 'POST',
5851+
headers: {
5852+
...getAuthHeaders(),
5853+
'Content-Type': 'application/json'
5854+
},
5855+
body: JSON.stringify({
5856+
action: 'signup',
5857+
email: email,
5858+
username: username,
5859+
password: password
5860+
})
5861+
});
5862+
5863+
if (response.ok) {
5864+
showNotification('Cloud account signup successful', 'success');
5865+
document.getElementById('cloud-password').value = '';
5866+
} else {
5867+
const errorData = await response.json();
5868+
showNotification(`Cloud signup failed: ${errorData.error}`, 'error');
5869+
}
5870+
} catch (error) {
5871+
showNotification('Failed to signup for cloud account', 'error');
5872+
}
5873+
}
5874+
5875+
async function reauthenticateCloud() {
5876+
if (!confirm('This will delete all current cloud authentication data and require re-authentication. Continue?')) {
5877+
return;
5878+
}
5879+
5880+
try {
5881+
const response = await fetch(`${baseURL}/api/cloud/manage`, {
5882+
method: 'POST',
5883+
headers: {
5884+
...getAuthHeaders(),
5885+
'Content-Type': 'application/json'
5886+
},
5887+
body: JSON.stringify({
5888+
action: 'delete_auth'
5889+
})
5890+
});
5891+
5892+
if (response.ok) {
5893+
showNotification('Cloud authentication data cleared successfully', 'success');
5894+
document.getElementById('cloud-email').value = '';
5895+
document.getElementById('cloud-username').value = '';
5896+
document.getElementById('cloud-password').value = '';
5897+
} else {
5898+
const errorData = await response.json();
5899+
showNotification(`Failed to clear cloud data: ${errorData.error}`, 'error');
5900+
}
5901+
} catch (error) {
5902+
showNotification('Failed to clear cloud authentication data', 'error');
5903+
}
5904+
}
5905+
5906+
document.addEventListener('DOMContentLoaded', () => {
5907+
loadCloudSettings();
5908+
5909+
document.getElementById('cloud_accept')?.addEventListener('click', saveCloudSettings);
5910+
5911+
document.getElementById('cloud-enable')?.addEventListener('change', saveCloudSettings);
5912+
5913+
document.getElementById('cloud_reauth')?.addEventListener('click', reauthenticateCloud);
5914+
});
5915+
5916+
document.querySelectorAll('.accept_btn, .update_btn').forEach(btn => {
5917+
btn.addEventListener('click', async function () {
5918+
5919+
if (this.id === 'cloud_accept') {
5920+
const email = document.getElementById('cloud-email').value.trim();
5921+
const username = document.getElementById('cloud-username').value.trim();
5922+
const password = document.getElementById('cloud-password').value.trim();
5923+
5924+
if (email && username && password) {
5925+
await signupCloudAccount();
5926+
} else {
5927+
await saveCloudSettings();
5928+
}
5929+
}
5930+
5931+
});
5932+
});
5933+
57215934
</script>
57225935
</html>

0 commit comments

Comments
 (0)