BACKEND DONE FOR ALL APPS

This commit is contained in:
andrei-mihnea-cerbu
2024-10-21 18:34:45 +03:00
parent 4157ca9e7d
commit ab1eaec413
349 changed files with 17199 additions and 14015 deletions
+82
View File
@@ -0,0 +1,82 @@
document.addEventListener('DOMContentLoaded', async function () {
const {email, password, name} = await window.electronAPI.readUserConfig('user_info');
const emailInput = document.querySelector('input[name="email"]');
const usernameInput = document.querySelector('input[name="username"]');
const passwordInput = document.querySelector('input[name="password"]');
// Pre-fill form fields with existing data
emailInput.value = email;
usernameInput.value = name;
passwordInput.value = password;
const backButton = document.querySelector('button[name="login"]');
const submitButton = document.querySelector('button[name="submit"]');
// Get operation codes from the backend
const operationCodes = await window.electronAPI.getOperationsCodes();
if (!operationCodes) {
await window.electronAPI.showAlert('Internal error of the application.');
return;
}
const codeModifyUser = operationCodes.MODIFY_USER;
const codeOk = operationCodes.OK;
// Handle the back button click
backButton.addEventListener('click', async function () {
console.log('Back button clicked!');
fadeOut('main_menu');
});
// Handle the submit button click
submitButton.addEventListener('click', async function (e) {
e.preventDefault();
console.log('Submit button clicked!');
// Fetch form values
const email = emailInput.value;
const name = usernameInput.value;
const password = passwordInput.value;
const { id, departmentId, app_type } = await window.electronAPI.readUserConfig('user_info'); // Fetch login data
// Prepare the data to be sent via the UC socket
const messageData = {
id: id,
name: name,
email: email,
password: password,
departmentId: departmentId,
app_type: app_type // Include app_type in the payload
};
// Open UC socket
if (!await window.electronAPI.openUcSocket()) {
await window.electronAPI.showAlert('Failed to open socket. Internal error of the application.');
return;
}
// Send the message to the server using the UC socket
if (!await window.electronAPI.sendUcMessage(codeModifyUser, messageData)) {
await window.electronAPI.showAlert('Failed to send message.');
return;
}
// Wait for the response
const response = await waitForResponse();
if (response && response.operationCode === codeOk) {
console.log('User update successful.');
// Save updated user info to the userConfig
await window.electronAPI.writeUserConfig('user_credentials', { email: email, password: password });
await window.electronAPI.writeUserConfig('user_info', {id: id, departmentId: departmentId, name: name});
// Navigate back to the main menu
fadeOut('main_menu');
} else {
console.log('Error updating user:', response?.metaInfo?.message || 'Unknown error');
await window.electronAPI.showAlert(response?.metaInfo?.message || 'Unknown error occurred');
}
});
});