forked from React-Group/interstellar_ai
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
This commit is contained in:
parent
f85eb35e93
commit
10b37fdad4
3 changed files with 178 additions and 40 deletions
|
@ -1,8 +1,11 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
createAccount,
|
||||
checkCredentials,
|
||||
} from '../backend/database';
|
||||
import Settings from './Settings'; // Import the Settings component
|
||||
|
||||
const Login: React.FC = () => {
|
||||
|
||||
// State to handle popup visibility
|
||||
const [showLoginPopup, setShowLoginPopup] = useState(false);
|
||||
const [showSignUpPopup, setShowSignUpPopup] = useState(false);
|
||||
|
@ -28,7 +31,11 @@ const Login: React.FC = () => {
|
|||
setAccountName(savedAccountName);
|
||||
setEmail(savedAccountEmail);
|
||||
setPassword(savedAccountPassword);
|
||||
setIsLoggedIn(true); // Automatically log in
|
||||
const check = async () => {
|
||||
const success = await checkCredentials(savedAccountName, savedAccountPassword);
|
||||
setIsLoggedIn(success); // Automatically log in
|
||||
};
|
||||
check();
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
@ -42,33 +49,40 @@ const Login: React.FC = () => {
|
|||
};
|
||||
|
||||
// Function to handle login
|
||||
const handleLogin = () => {
|
||||
const handleLogin = async () => {
|
||||
const savedAccountEmail = localStorage.getItem('accountEmail');
|
||||
const savedAccountPassword = localStorage.getItem('accountPassword');
|
||||
const savedAccountName = localStorage.getItem('accountName');
|
||||
|
||||
if (
|
||||
(email === savedAccountEmail || accountName === savedAccountName) &&
|
||||
password === savedAccountPassword
|
||||
) {
|
||||
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);
|
||||
// Check if savedAccountName or savedAccountEmail is not null before passing to checkCredentials
|
||||
const accountIdentifier = savedAccountName || savedAccountEmail;
|
||||
|
||||
if (accountIdentifier && password === savedAccountPassword) {
|
||||
const success = await checkCredentials(accountIdentifier, 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');
|
||||
}
|
||||
} else {
|
||||
alert('Incorrect credentials');
|
||||
}
|
||||
};
|
||||
|
||||
// Function to handle account creation
|
||||
const handleCreateAccount = () => {
|
||||
localStorage.setItem('accountName', newAccountName);
|
||||
localStorage.setItem('accountEmail', newAccountEmail);
|
||||
localStorage.setItem('accountPassword', newAccountPassword);
|
||||
alert('Account created successfully! You can now log in.');
|
||||
toggleSignUpPopup(); // Close sign-up popup
|
||||
const handleCreateAccount = async () => {
|
||||
const success = await createAccount(newAccountName, newAccountEmail, newAccountPassword);
|
||||
if (success) {
|
||||
alert('Account created successfully! You can now log in.');
|
||||
toggleSignUpPopup(); // Close sign-up popup
|
||||
} else {
|
||||
alert('Account creation failed. Please try again.');
|
||||
}
|
||||
};
|
||||
|
||||
// Function to toggle the settings popup
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue