Merge branch 'main' into main

This commit is contained in:
Patrick 2024-10-01 15:45:37 +02:00
commit 119832ee39
6 changed files with 567 additions and 525 deletions

View file

@ -31,6 +31,19 @@ export const sendToDatabase = async (data: any): Promise<boolean> => {
}
};
export const sendToDatabaseAndGetString = async (data: any): Promise<string> => {
try {
const response = await axios.post("http://localhost:5000/interstellar_ai/db", data);
const status = response.data.status;
const success = response.data.response;
postMessage({ status, success });
return success;
} catch (error) {
postMessage({ status: 500, success: false });
return "false";
}
};
// Functions for each action
export const createAccount = async (username: string, email: string, password: string) => {
const data = {
@ -60,7 +73,27 @@ export const getData = async (usernameOrEmail: string, password: string) => {
email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined,
password,
};
return await sendToDatabase(data);
return await sendToDatabaseAndGetString(data);
};
export const getEmail = async (usernameOrEmail: string, password: string): Promise<string> => {
const data = {
action: "get_email",
username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail,
email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined,
password,
};
return await sendToDatabaseAndGetString(data);
};
export const getName = async (usernameOrEmail: string, password: string): Promise<string> => {
const data = {
action: "get_name",
username: usernameOrEmail.includes('@') ? undefined : usernameOrEmail,
email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined,
password,
};
return await sendToDatabaseAndGetString(data);
};
export const changeData = async (usernameOrEmail: string, password: string, newData: any) => {
@ -81,7 +114,13 @@ export const checkCredentials = async (usernameOrEmail: string, password: string
email: usernameOrEmail.includes('@') ? usernameOrEmail : undefined,
password,
};
return await sendToDatabase(data);
var sendBack = await sendToDatabase(data);
if (sendBack) {
localStorage.setItem("accountEmail", await getEmail(usernameOrEmail, password))
localStorage.setItem("accountName", await getName(usernameOrEmail, password))
localStorage.setItem("accountPassword", password)
}
return sendBack
};
export const deleteAccount = async (usernameOrEmail: string, password: string) => {

View file

@ -50,25 +50,11 @@ const Login: React.FC = () => {
// Function to handle login
const handleLogin = async () => {
const savedAccountEmail = localStorage.getItem('accountEmail');
const savedAccountPassword = localStorage.getItem('accountPassword');
const savedAccountName = localStorage.getItem('accountName');
// Check if savedAccountName or savedAccountEmail is not null before passing to checkCredentials
var accountIdentifier = savedAccountName || savedAccountEmail;
if (!accountIdentifier) {
accountIdentifier = accountName
}
if (accountIdentifier && password) {
const success = await checkCredentials(accountIdentifier, password);
if (accountName && password) {
const success = await checkCredentials(accountName, password);
if (success) {
setIsLoggedIn(true); // Successful login
setShowLoginPopup(false); // Close the login popup
// Save credentials to localStorage (optional in case of changes)
localStorage.setItem('accountName', savedAccountName || accountName);
localStorage.setItem('accountEmail', savedAccountEmail || email);
localStorage.setItem('accountPassword', savedAccountPassword || password);
} else {
alert('Incorrect credentials');
}

View file

@ -37,11 +37,8 @@ const PrivacySettings: React.FC<PrivacySettingsProps> = ({ selectedOption, handl
>
None{openSourceMode ? ' (FOSS)' : ''}
</div>
</div>
</div>
<br />
<p>
After changing the preferred settings, please reload the website so it can update itself properly.
</p>
</div>
</>
);

File diff suppressed because it is too large Load diff