fixed some backend and database stuff
This commit is contained in:
parent
7c2f179c8b
commit
e594ecd7c2
6 changed files with 567 additions and 525 deletions
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue