added email verification

This commit is contained in:
andrei-mihnea-cerbu
2025-02-04 19:08:34 +02:00
parent 9baec7a7cb
commit dcf505c89b
67 changed files with 3922 additions and 3638 deletions
+1 -10
View File
@@ -1,11 +1,9 @@
// Load announcement content from the application info when the page loads
async function loadAnnouncement() {
try {
const announcementText = await window.electronAPI.readApplicationInfo('announcement');
const announcementText = await window.electronAPI.readAnnouncement();
const announcementContent = document.getElementById('announcement-content');
if (announcementContent && announcementText) {
console.log('Announcement:', announcementText);
announcementContent.innerHTML = formatTextForHtml(announcementText);
}
} catch (error) {
@@ -15,14 +13,8 @@ async function loadAnnouncement() {
}
function formatTextForHtml(text) {
// Replace newlines with <br> tags
let formattedText = text.replace(/\n/g, '<br>');
// Replace tabs with a few non-breaking spaces for indentation
formattedText = formattedText.replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;');
// Replace other special characters as needed
// Example: Handle double spaces by converting to &nbsp;
formattedText = formattedText.replace(/ /g, ' &nbsp;');
return formattedText;
@@ -30,6 +22,5 @@ function formatTextForHtml(text) {
// Close the window when the close button is clicked
function closeWindow() {
window.electronAPI.writeApplicationInfo('announcement', '');
window.electronAPI.closeAnnouncementWindow();
}
+3 -3
View File
@@ -13,7 +13,7 @@ function fadeOut(destination) {
container.addEventListener('animationend', async () => {
try {
await window.electronAPI.changeContent(destination);
await window.uiAPI.changeContent(destination);
console.log('Navigated to', destination);
} catch (error) {
console.error('Error navigating:', error);
@@ -24,9 +24,9 @@ function fadeOut(destination) {
async function waitForResponse() {
return new Promise((resolve) => {
const idResponseCheck = setInterval(async () => {
if (await window.electronAPI.hasResponseArrived()) {
if (await window.networkAPI.hasResponseArrived()) {
clearInterval(idResponseCheck);
resolve(await window.electronAPI.getLastUcResult()); // Resolve the response or null if not available
resolve(await window.networkAPI.getLastUcResult()); // Resolve the response or null if not available
}
}, 100); // Check every 100 milliseconds if the response has arrived
});
+33 -42
View File
@@ -8,10 +8,12 @@ document.addEventListener('DOMContentLoaded', async function () {
const resetPasswordButton = document.getElementById('resetPassword');
const signUpButton = document.getElementById('signup');
await window.databaseAPI.setLoginStatus(false);
// Retrieve the operation codes via IPC
const operationCodes = await window.electronAPI.getOperationsCodes();
const operationCodes = await window.networkAPI.getOperationsCodes();
if (!operationCodes) {
await window.electronAPI.showAlert('Internal error of the application. Failed to retrieve operation codes.');
await window.uiAPI.showAlert('Internal error of the application. Failed to retrieve operation codes.');
return;
}
@@ -22,12 +24,12 @@ document.addEventListener('DOMContentLoaded', async function () {
resetPasswordButton.addEventListener('click', function (e) {
e.preventDefault();
window.electronAPI.changeContent('reset_password');
window.uiAPI.changeContent('reset_password');
});
signUpButton.addEventListener('click', function (e) {
e.preventDefault();
window.electronAPI.changeContent('sign_up');
window.uiAPI.changeContent('sign_up');
});
// Submit button logic (handle login)
@@ -42,50 +44,52 @@ document.addEventListener('DOMContentLoaded', async function () {
const password = formData.get('password');
// Open a TCP socket to the stored IP
if (!await window.electronAPI.openUcSocket()) {
await window.electronAPI.showAlert('Internal error of the application. Unable to open socket.');
if (!await window.networkAPI.openUcSocket()) {
await window.uiAPI.showAlert('Internal error of the application. Unable to open socket.');
return;
}
// Attempt login
if (!await attemptLogin(email, password)) {
await window.electronAPI.closeUcSocket();
await window.networkAPI.closeUcSocket();
return;
}
// Fetch and store user info
if (!await fetchAndStoreUserInfo(email)) {
await window.electronAPI.closeUcSocket();
await window.networkAPI.closeUcSocket();
return;
}
// Fetch user info from local storage
const userInfo = await window.electronAPI.readUserConfig('user_info');
const userInfo = await window.databaseAPI.getUserInfo('user_info');
if (!userInfo) {
await window.electronAPI.closeUcSocket();
await window.electronAPI.showAlert('Failed to fetch user info.');
await window.networkAPI.closeUcSocket();
await window.uiAPI.showAlert('Failed to fetch user info.');
return;
}
// Fetch and store encryption key
if (!await fetchAndStoreEncryptionKey(userInfo.id)) {
await window.electronAPI.closeUcSocket();
await window.networkAPI.closeUcSocket();
return;
}
// Close the socket and navigate to main menu after success
await window.electronAPI.closeUcSocket();
await window.electronAPI.changeContent('main_menu');
await window.networkAPI.closeUcSocket();
await window.uiAPI.startWorkers();
await window.databaseAPI.setLoginStatus(true);
await window.uiAPI.changeContent('main_menu');
});
});
async function attemptLogin(email, password) {
const app_type = await window.electronAPI.readUserConfig('app_type');
const app_type = await window.databaseAPI.getAppType();
const messageData = {email, password, app_type};
// Send the login message to the server
if (!await window.electronAPI.sendUcMessage(codeLogin, messageData)) {
await window.electronAPI.showAlert('Failed to send login request.');
if (!await window.networkAPI.sendUcMessage(codeLogin, messageData)) {
await window.uiAPI.showAlert('Failed to send login request.');
return false;
}
@@ -93,57 +97,44 @@ async function attemptLogin(email, password) {
const response = await waitForResponse();
if (!response) {
await window.electronAPI.showAlert('No response from server.');
await window.uiAPI.showAlert('No response from server.');
return false;
}
if (response.operationCode !== codeOk) {
await window.electronAPI.showAlert(response.metaInfo.message);
await window.uiAPI.showAlert(response.metaInfo.message);
return false;
}
const user_info = await window.electronAPI.readUserConfig('user_info');
if (!user_info || (user_info && user_info.email !== email)) {
await window.electronAPI.resetApplicationInfo();
await window.electronAPI.resetMemory();
await window.electronAPI.resetUserConfig();
await window.electronAPI.writeUserConfig('app_type', app_type);
await window.electronAPI.writeUserConfig('user_info', {email, password});
return true;
}
return true;
}
async function fetchAndStoreUserInfo(userEmail) {
if (!await window.electronAPI.sendUcMessage(codeFindByEmail, {email: userEmail})) {
await window.electronAPI.showAlert('Failed to send request to fetch user info.');
if (!await window.networkAPI.sendUcMessage(codeFindByEmail, {email: userEmail})) {
await window.uiAPI.showAlert('Failed to send request to fetch user info.');
return false;
}
// Wait for the response using waitForResponse
const response = await waitForResponse();
if (response && response.operationCode === codeOk) {
let userInfo = await window.electronAPI.readUserConfig('user_info');
if (!userInfo) {
userInfo = {};
}
const userInfo = {};
userInfo.id = response.metaInfo.id;
userInfo.email = response.metaInfo.email;
userInfo.departmentId = response.metaInfo.departmentId;
userInfo.name = response.metaInfo.name || 'User';
await window.electronAPI.writeUserConfig('user_info', userInfo);
await window.databaseAPI.writeUserInfo(userInfo);
return true;
}
await window.electronAPI.showAlert('Failed to fetch user info from server.');
await window.uiAPI.showAlert('Failed to fetch user info from server.');
return false;
}
async function fetchAndStoreEncryptionKey(userId) {
if (!await window.electronAPI.sendUcMessage(codeFindKeyByUser, {userId})) {
await window.electronAPI.showAlert('Failed to send request to fetch encryption key.');
if (!await window.networkAPI.sendUcMessage(codeFindKeyByUser, {userId})) {
await window.uiAPI.showAlert('Failed to send request to fetch encryption key.');
return false;
}
@@ -155,10 +146,10 @@ async function fetchAndStoreEncryptionKey(userId) {
iv: response.metaInfo.key.iv,
};
await window.electronAPI.writeUserConfig('encryption_key', encryptionKey);
await window.databaseAPI.writeEncryptionKey(encryptionKey);
return true;
}
await window.electronAPI.showAlert('Failed to fetch encryption key from server.');
await window.uiAPI.showAlert('Failed to fetch encryption key from server.');
return false;
}
+33 -83
View File
@@ -1,3 +1,7 @@
let backupDirId = '';
let shareDirId = '';
let departmentDirId = '';
document.addEventListener('DOMContentLoaded', async function () {
setInterval(loadReceivedFiles, 3000); // Call loadReceivedFiles every 3000 ms (3 seconds)
@@ -47,16 +51,15 @@ async function initialSetup(){
}
async function restoreBackup() {
const backupDirectory = await window.electronAPI.readApplicationInfo('backupDirectory');
const backupDirectory = await window.databaseAPI.isBackupSet();
if (backupDirectory && backupDirectory.path) {
// If backup directory is already set, display an alert
await window.electronAPI.showAlert('You have already set a backup directory. You cannot restore again.');
if (backupDirectory) {
await window.uiAPI.showAlert('You have already set a backup directory. You cannot restore again.');
return;
}
// Prompt the user to choose the destination for the restored backup
const destinationPath = await window.electronAPI.selectDirectory();
const destinationPath = await window.uiAPI.selectDirectory();
if (!destinationPath) {
return; // User canceled the directory selection
}
@@ -69,26 +72,31 @@ async function restoreBackup() {
}
async function checkAndSetAllDirectories() {
await attachNotificationButton('backupDirectory', 'Set your backup directory!', 'backup_alert', 'alert');
await attachNotificationButton('shareDirectory', 'Set your share directory!', 'share_alert', 'alert');
await attachNotificationButton('departmentDirectory', 'Set your department directory!', 'department_alert', 'alert');
const directorySchemes = await window.databaseAPI.getLocalResources();
backupDirId = directorySchemes.backup.id;
shareDirId = directorySchemes.shared.id;
departmentDirId = directorySchemes.department.id;
await attachNotificationButton(backupDirId, 'Set your backup directory!', 'backup_alert', 'alert');
await attachNotificationButton(shareDirId, 'Set your share directory!', 'share_alert', 'alert');
await attachNotificationButton(departmentDirId, 'Set your department directory!', 'department_alert', 'alert');
}
async function checkPathExistence(pathKey) {
return await window.electronAPI.readApplicationInfo(pathKey);
async function checkPathExistence(id) {
const dirInfo = await window.databaseAPI.getDirectoryInfo(id);
return dirInfo.path !== ''
}
async function setPath(pathKey) {
const path = await window.electronAPI.selectDirectory();
if (path === undefined) return;
async function setPath(id){
const path = await window.uiAPI.selectDirectory();
if (path === undefined) return false;
const id = await window.electronAPI.createMemoryEntry()
console.log({id, path})
await window.electronAPI.writeApplicationInfo(pathKey, {id, path});
return await window.databaseAPI.writeDirectoryPath(id, path);
}
async function attachNotificationButton(pathKey, buttonText, buttonId, buttonName) {
const path = await checkPathExistence(pathKey);
async function attachNotificationButton(entryId, buttonText, buttonId, buttonName) {
const path = await checkPathExistence(entryId);
if (!path) {
const notificationsDiv = document.getElementById('notifications');
const button = document.createElement('button');
@@ -97,8 +105,7 @@ async function attachNotificationButton(pathKey, buttonText, buttonId, buttonNam
button.name = buttonName;
button.textContent = buttonText;
button.addEventListener('click', async function () {
await setPath(pathKey);
button.remove(); // Remove button after setting the path
if(await setPath(entryId)) button.remove();
});
notificationsDiv.appendChild(button);
}
@@ -108,7 +115,7 @@ async function fetchUserInfo() {
const usernameField = document.getElementById('username-field');
// Read the user credentials from the userConfig
let userInfo = await window.electronAPI.readUserConfig('user_info');
let userInfo = await window.databaseAPI.getUserInfo();
if (userInfo && userInfo.name) {
usernameField.textContent = userInfo.name;
return;
@@ -116,7 +123,7 @@ async function fetchUserInfo() {
// Update the greeting with the fetched user's name
if (usernameField) {
usernameField.textContent = userInfo.name; // Update the h1 with the user's name
usernameField.textContent = userInfo.name;
} else {
console.error("Username field is not available in the DOM.");
}
@@ -124,29 +131,14 @@ async function fetchUserInfo() {
async function loadReceivedFiles() {
// Read the shareDirectory from applicationInfo
const shareDirectoryData = await window.electronAPI.readApplicationInfo('shareDirectory');
if (!shareDirectoryData || !shareDirectoryData.id) {
console.log('No received files or directory ID found.');
return;
}
const directoryId = shareDirectoryData.id;
// Fetch the directory structure (JSON objects with user names and file paths)
const directoryStructure = await window.electronAPI.readMemoryEntry(directoryId);
if (!directoryStructure || !directoryStructure.structure) {
console.log('No received files found in the directory structure.');
return;
}
const shareDirData = await window.databaseAPI.getDirectoryInfo(shareDirId);
const notificationsDiv = document.getElementById('notifications');
const existingButtons = Array.from(notificationsDiv.children).map(button => button.getAttribute('data-filepath'));
// Iterate over each user and their files in the structure
Object.keys(directoryStructure.structure).forEach(userName => {
const userFiles = directoryStructure.structure[userName];
Object.keys(shareDirData.structure).forEach(userName => {
const userFiles = shareDirData.structure[userName];
// Iterate over each file of the user
Object.keys(userFiles).forEach(fileName => {
@@ -166,56 +158,14 @@ async function loadReceivedFiles() {
});
}
async function removeReceivedFile(filePath) {
// Read the shareDirectory from applicationInfo
const shareDirectoryData = await window.electronAPI.readApplicationInfo('shareDirectory');
if (!shareDirectoryData || !shareDirectoryData.id) {
console.log('No directory ID found to update.');
return;
}
const directoryId = shareDirectoryData.id;
// Fetch the directory structure
let directoryStructure = await window.electronAPI.readMemoryEntry(directoryId);
if (directoryStructure && directoryStructure.structure) {
// Iterate over each user and their files
for (let userName in directoryStructure.structure) {
let userFiles = directoryStructure.structure[userName];
// Check if the file exists and remove it
if (userFiles[filePath]) {
delete userFiles[filePath];
// Remove the user if no more files are left
if (Object.keys(userFiles).length === 0) {
delete directoryStructure.structure[userName];
}
// Update the directory structure in memory
await window.electronAPI.updateMemoryEntry(directoryId, directoryStructure);
console.log(`File ${filePath} removed from memory.`);
return;
}
}
} else {
console.log('No directory structure found in memory to update.');
}
}
async function handleFileReceivedButtonPressed(filePath, button) {
console.log('Notification button clicked!');
// Open the file in the file explorer
await window.electronAPI.showFileInExplorer(filePath)
await window.uiAPI.showFileInExplorer(filePath)
.then(() => console.log('File explorer opened for: ' + filePath))
.catch(error => console.error('Error opening file explorer:', error));
// Remove the button after opening the file
button.remove();
// Remove the file from memory
await removeReceivedFile(filePath);
}
+17 -14
View File
@@ -1,22 +1,27 @@
let id = '';
let departmentId = '';
document.addEventListener('DOMContentLoaded', async function () {
const {email, password, name} = await window.electronAPI.readUserConfig('user_info');
const {id: userId, name, email, departmentId: userDepartmentId} = await window.databaseAPI.getUserInfo();
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;
id = userId
departmentId = userDepartmentId;
usernameInput.value = name;
passwordInput.value = password;
emailInput.value = email;
passwordInput.value = '';
const backButton = document.getElementById('back');
const submitButton = document.getElementById('submit');
// Get operation codes from the backend
const operationCodes = await window.electronAPI.getOperationsCodes();
const operationCodes = await window.networkAPI.getOperationsCodes();
if (!operationCodes) {
await window.electronAPI.showAlert('Internal error of the application.');
await window.uiAPI.showAlert('Internal error of the application.');
return;
}
@@ -39,8 +44,7 @@ document.addEventListener('DOMContentLoaded', async function () {
const name = usernameInput.value;
const password = passwordInput.value;
const { id, departmentId } = await window.electronAPI.readUserConfig('user_info'); // Fetch login data
const app_type = await window.electronAPI.readUserConfig('app_type'); // Fetch app type
const app_type = await window.databaseAPI.getAppType();
// Prepare the data to be sent via the UC socket
const messageData = {
@@ -49,18 +53,18 @@ document.addEventListener('DOMContentLoaded', async function () {
email: email,
password: password,
departmentId: departmentId,
app_type: app_type // Include app_type in the payload
app_type: app_type
};
// Open UC socket
if (!await window.electronAPI.openUcSocket()) {
await window.electronAPI.showAlert('Failed to open socket. Internal error of the application.');
if (!await window.networkAPI.openUcSocket()) {
await window.uiAPI.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.');
if (!await window.networkAPI.sendUcMessage(codeModifyUser, messageData)) {
await window.uiAPI.showAlert('Failed to send message.');
return;
}
@@ -70,8 +74,7 @@ document.addEventListener('DOMContentLoaded', async function () {
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});
await window.databaseAPI.writeUserInfo({ id: id, email: email, name: name, departmentId: departmentId });
// Navigate back to the main menu
fadeOut('main_menu');
+3 -1
View File
@@ -1,4 +1,6 @@
document.addEventListener('DOMContentLoaded', async function () {
await new Promise(resolve => setTimeout(resolve, 7000));
window.electronAPI.changeContent('login');
await window.databaseAPI.resetInternalDatabase();
await window.uiAPI.stopWorkers();
await window.uiAPI.changeContent('welcome');
});
+12 -12
View File
@@ -6,9 +6,9 @@ document.addEventListener('DOMContentLoaded', async function () {
const resetPasswordButton = document.getElementById('resetPassword');
// Retrieve the operation codes via IPC
const operationCodes = await window.electronAPI.getOperationsCodes();
const operationCodes = await window.networkAPI.getOperationsCodes();
if (!operationCodes) {
await window.electronAPI.showAlert('Internal error of the application.');
await window.uiAPI.showAlert('Internal error of the application.');
return;
}
@@ -18,14 +18,14 @@ document.addEventListener('DOMContentLoaded', async function () {
// Back to login
backToLoginButton.addEventListener('click', function (e) {
e.preventDefault();
window.electronAPI.changeContent('login');
window.uiAPI.changeContent('login');
});
// Reset password logic
resetPasswordButton.addEventListener('click', async function (e) {
e.preventDefault();
if (!await window.electronAPI.openUcSocket()) {
await window.electronAPI.showAlert('Internal error of the application.');
if (!await window.networkAPI.openUcSocket()) {
await window.uiAPI.showAlert('Internal error of the application.');
return;
}
@@ -36,7 +36,7 @@ document.addEventListener('DOMContentLoaded', async function () {
// Ensure the email and new password are provided
if (!email || !newPassword) {
await window.electronAPI.showAlert('Please provide both email and new password.');
await window.uiAPI.showAlert('Please provide both email and new password.');
return;
}
@@ -44,23 +44,23 @@ document.addEventListener('DOMContentLoaded', async function () {
return;
}
await window.electronAPI.closeUcSocket();
await window.electronAPI.showAlert('Password reset successfully.');
window.electronAPI.changeContent('login');
await window.networkAPI.closeUcSocket();
await window.uiAPI.showAlert('Password reset successfully.');
await window.uiAPI.changeContent('login');
});
});
async function attemptResetPassword(email, newPassword) {
const app_type = await window.electronAPI.readUserConfig('app_type');
const app_type = await window.databaseAPI.getAppType();
const messageData = { email, newPassword, app_type };
if (!await window.electronAPI.sendUcMessage(codeResetPassword, messageData)) return false;
if (!await window.networkAPI.sendUcMessage(codeResetPassword, messageData)) return false;
const response = await waitForResponse();
if (response && response.operationCode === codeOk) {
return true;
} else {
await window.electronAPI.showAlert(response?.metaInfo?.message || 'Error resetting password.');
await window.uiAPI.showAlert(response?.metaInfo?.message || 'Error resetting password.');
return false;
}
}
+10 -16
View File
@@ -9,7 +9,7 @@ document.addEventListener('DOMContentLoaded', async function () {
selectFileButton.addEventListener('click', async function (event) {
event.preventDefault();
try {
pathToFile = await window.electronAPI.selectFile();
pathToFile = await window.uiAPI.selectFile();
updateFileName();
} catch (error) {
console.error('Error opening file dialog:', error);
@@ -20,11 +20,11 @@ document.addEventListener('DOMContentLoaded', async function () {
// Check if a file was chosen
if (!pathToFile.trim()) {
await window.electronAPI.showAlert('File not chosen!');
await window.uiAPI.showAlert('File not chosen!');
return;
}
const user_info = await window.electronAPI.readUserConfig('user_info');
const user_info = await window.databaseAPI.getUserInfo();
if (!user_info) {
return;
}
@@ -36,7 +36,7 @@ document.addEventListener('DOMContentLoaded', async function () {
.map(checkbox => checkbox.value); // Get IP of the selected users
if (!selectedUserIps.length) {
await window.electronAPI.showAlert('No user selected!');
await window.uiAPI.showAlert('No user selected!');
return;
}
@@ -48,8 +48,8 @@ document.addEventListener('DOMContentLoaded', async function () {
path: pathToFile, // File path
userName: user_info.name // Sender's username from userConfig
};
await window.electronAPI.addTaskToSendFileQueue(task);
await window.electronAPI.showAlert('File sent to the queue.');
await window.databaseAPI.addTaskToSendFileQueue(task);
await window.uiAPI.showAlert('File sent to the queue.');
console.log(`Task added to send file to IP ${selectedUserIp}`);
} catch (error) {
console.error(`Error processing IP ${selectedUserIp}:`, error);
@@ -85,18 +85,12 @@ async function fetchUsersAndCreateCheckboxes() {
.map(checkbox => checkbox.value)
);
const usersInfoId = await window.electronAPI.readApplicationInfo('active_users_info');
if (!usersInfoId) {
await window.electronAPI.showAlert('Internal error.');
return;
}
const usersInfo = await window.electronAPI.readMemoryEntry(usersInfoId);
const usersInfo = await window.databaseAPI.getActiveUsers();
if (!usersInfo || usersInfo.length === 0) {
await window.electronAPI.showAlert('No active users found.');
await window.uiAPI.showAlert('No active users found.');
clearInterval(fetchUsersInterval);
fetchUsersInterval = null;
await window.electronAPI.changeContent('main_menu');
await window.uiAPI.changeContent('main_menu');
return;
}
@@ -115,7 +109,7 @@ async function fetchUsersAndCreateCheckboxes() {
}
const label = document.createElement('label');
label.innerHTML = `${user.user_info.name}`; // Display user's name
label.innerHTML = `${user.user_info.name}`;
label.insertBefore(checkbox, label.firstChild);
usersDiv.appendChild(label);
+11 -11
View File
@@ -18,12 +18,12 @@ document.addEventListener('DOMContentLoaded', async function () {
const step1 = document.getElementById('step1');
const step2 = document.getElementById('step2');
if (!await window.electronAPI.openUcSocket()) {
if (!await window.networkAPI.openUcSocket()) {
alert('Internal error of the application.');
return;
}
const operationCodes = await window.electronAPI.getOperationsCodes();
const operationCodes = await window.networkAPI.getOperationsCodes();
if (!operationCodes) {
await window.electronAPI.showAlert('Internal error of the application.');
return;
@@ -35,7 +35,7 @@ document.addEventListener('DOMContentLoaded', async function () {
let departments = await getDepartments();
if (departments === null) {
await window.electronAPI.showAlert('Failed to fetch departments.');
await window.uiAPI.showAlert('Failed to fetch departments.');
return;
}
@@ -47,7 +47,7 @@ document.addEventListener('DOMContentLoaded', async function () {
userData.email = document.querySelector('input[name="email"]').value;
userData.name = document.querySelector('input[name="name"]').value;
userData.password = document.querySelector('input[name="password"]').value;
userData.app_type = await window.electronAPI.readUserConfig('app_type');
userData.app_type = await window.databaseAPI.getAppType();
// Move to Step 2
const departmentList = document.getElementById('departmentList');
@@ -75,7 +75,7 @@ document.addEventListener('DOMContentLoaded', async function () {
// Get the selected department
userData.departmentId = document.querySelector('input[name="dept"]:checked')?.value;
if (!userData.departmentId) {
await window.electronAPI.showAlert('Please select a department.');
await window.uiAPI.showAlert('Please select a department.');
return;
}
@@ -84,8 +84,8 @@ document.addEventListener('DOMContentLoaded', async function () {
return;
}
await window.electronAPI.showAlert('Signup successful!');
await window.electronAPI.changeContent('login');
await window.uiAPI.showAlert('Signup successful!');
await window.uiAPI.changeContent('login');
});
// Back to Step 1 from Step 2
@@ -96,8 +96,8 @@ document.addEventListener('DOMContentLoaded', async function () {
// Back to login
backToLogin.addEventListener('click', async function (e) {
e.preventDefault();
await window.electronAPI.closeUcSocket();
await window.electronAPI.changeContent('login');
await window.networkAPI.closeUcSocket();
await window.uiAPI.changeContent('login');
});
});
@@ -113,13 +113,13 @@ async function getDepartments() {
}
async function attemptSignUp() {
if (!await window.electronAPI.sendUcMessage(codeSignUp, userData)) return false;
if (!await window.networkAPI.sendUcMessage(codeSignUp, userData)) return false;
const response = await waitForResponse();
if (response && response.operationCode === codeOk) {
return true;
}
await window.electronAPI.showAlert(`Signup failed: ${response?.metaInfo?.message || 'Unknown error'}`);
await window.uiAPI.showAlert(`Signup failed: ${response?.metaInfo?.message || 'Unknown error'}`);
return false;
}