program finalizat
This commit is contained in:
+99
-85
@@ -1,7 +1,12 @@
|
||||
let codeLogin = '';
|
||||
let codeFindByEmail = '';
|
||||
let codeFindKeyByUser = '';
|
||||
let codeOk = '';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async function () {
|
||||
const submitButton = document.getElementById('submit');
|
||||
const signUpButton = document.getElementById('signup');
|
||||
const resetPasswordButton = document.getElementById('resetPassword');
|
||||
const signUpButton = document.getElementById('signup');
|
||||
|
||||
// Retrieve the operation codes via IPC
|
||||
const operationCodes = await window.electronAPI.getOperationsCodes();
|
||||
@@ -10,21 +15,21 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
return;
|
||||
}
|
||||
|
||||
const codeLogin = operationCodes.LOGIN;
|
||||
const codeFindByEmail = operationCodes.FIND_BY_EMAIL;
|
||||
const codeFindKeyByUser = operationCodes.FIND_KEY_BY_USER_ID;
|
||||
const codeOk = operationCodes.OK;
|
||||
|
||||
signUpButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
window.electronAPI.changeContent('sign_up');
|
||||
});
|
||||
codeLogin = operationCodes.LOGIN;
|
||||
codeFindByEmail = operationCodes.FIND_BY_EMAIL;
|
||||
codeFindKeyByUser = operationCodes.FIND_KEY_BY_USER_ID;
|
||||
codeOk = operationCodes.OK;
|
||||
|
||||
resetPasswordButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
window.electronAPI.changeContent('reset_password');
|
||||
});
|
||||
|
||||
signUpButton.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
window.electronAPI.changeContent('sign_up');
|
||||
});
|
||||
|
||||
// Submit button logic (handle login)
|
||||
submitButton.addEventListener('click', async function (e) {
|
||||
e.preventDefault();
|
||||
@@ -72,79 +77,88 @@ document.addEventListener('DOMContentLoaded', async function () {
|
||||
await window.electronAPI.closeUcSocket();
|
||||
await window.electronAPI.changeContent('main_menu');
|
||||
});
|
||||
|
||||
async function attemptLogin(email, password) {
|
||||
const app_type = await window.electronAPI.readUserConfig('app_type');
|
||||
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.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wait for the response using waitForResponse
|
||||
const response = await waitForResponse();
|
||||
if (response && response.operationCode === codeOk) {
|
||||
await window.electronAPI.resetApplicationInfo();
|
||||
await window.electronAPI.resetUserConfig();
|
||||
await window.electronAPI.writeUserConfig('app_type', app_type);
|
||||
await window.electronAPI.writeUserConfig('user_info', { email, password });
|
||||
return true;
|
||||
}else if(response && respone.operationCode !== codeOk){
|
||||
await window.electronAPI.showAlert(response.metaInfo.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
await window.electronAPI.showAlert('Invalid login response received.');
|
||||
return false;
|
||||
}
|
||||
|
||||
async function fetchAndStoreUserInfo(userEmail) {
|
||||
if (!await window.electronAPI.sendUcMessage(codeFindByEmail, { email: userEmail })) {
|
||||
await window.electronAPI.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 = {};
|
||||
}
|
||||
|
||||
userInfo.id = response.metaInfo.id;
|
||||
userInfo.departmentId = response.metaInfo.departmentId;
|
||||
userInfo.name = response.metaInfo.name || 'User';
|
||||
|
||||
await window.electronAPI.writeUserConfig('user_info', userInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
await window.electronAPI.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.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wait for the response using waitForResponse
|
||||
const response = await waitForResponse();
|
||||
if (response && response.operationCode === codeOk) {
|
||||
const encryptionKey = {
|
||||
key: response.metaInfo.key.key,
|
||||
iv: response.metaInfo.key.iv,
|
||||
};
|
||||
|
||||
await window.electronAPI.writeUserConfig('encryption_key', encryptionKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
await window.electronAPI.showAlert('Failed to fetch encryption key from server.');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
async function attemptLogin(email, password) {
|
||||
const app_type = await window.electronAPI.readUserConfig('app_type');
|
||||
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.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wait for the response using waitForResponse
|
||||
const response = await waitForResponse();
|
||||
|
||||
if (!response) {
|
||||
await window.electronAPI.showAlert('No response from server.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (response.operationCode !== codeOk) {
|
||||
await window.electronAPI.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.');
|
||||
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 = {};
|
||||
}
|
||||
|
||||
userInfo.id = response.metaInfo.id;
|
||||
userInfo.departmentId = response.metaInfo.departmentId;
|
||||
userInfo.name = response.metaInfo.name || 'User';
|
||||
|
||||
await window.electronAPI.writeUserConfig('user_info', userInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
await window.electronAPI.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.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wait for the response using waitForResponse
|
||||
const response = await waitForResponse();
|
||||
if (response && response.operationCode === codeOk) {
|
||||
const encryptionKey = {
|
||||
key: response.metaInfo.key.key,
|
||||
iv: response.metaInfo.key.iv,
|
||||
};
|
||||
|
||||
await window.electronAPI.writeUserConfig('encryption_key', encryptionKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
await window.electronAPI.showAlert('Failed to fetch encryption key from server.');
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user