Compare commits

..

No commits in common. "32f9c57c01536d04c70bfc5a7e729b510a4a6d96" and "3d6c5eeee6c89be3cbfe97b895516f21bacf7662" have entirely different histories.

3 changed files with 14 additions and 39 deletions

View file

@ -1,8 +1,7 @@
import React, { useState, useEffect } from 'react'; import React, { useState } from 'react';
import Settings from './Settings'; // Import the Settings component import Settings from './Settings'; // Import the Settings component
const Login: React.FC = () => { const Login: React.FC = () => {
// State to handle popup visibility // State to handle popup visibility
const [showLoginPopup, setShowLoginPopup] = useState(false); const [showLoginPopup, setShowLoginPopup] = useState(false);
const [showSignUpPopup, setShowSignUpPopup] = useState(false); const [showSignUpPopup, setShowSignUpPopup] = useState(false);
@ -17,20 +16,10 @@ const Login: React.FC = () => {
const [newAccountPassword, setNewAccountPassword] = useState(''); const [newAccountPassword, setNewAccountPassword] = useState('');
const [newAccountName, setNewAccountName] = useState(''); const [newAccountName, setNewAccountName] = useState('');
// On component mount, check if there are credentials in localStorage // Fixed credentials
useEffect(() => { const fixedEmail = '';
const savedAccountName = localStorage.getItem('accountName'); const fixedPassword = '';
const savedAccountEmail = localStorage.getItem('accountEmail'); const fixedAccount = '';
const savedAccountPassword = localStorage.getItem('accountPassword');
// If credentials are found in localStorage, log the user in
if (savedAccountName && savedAccountEmail && savedAccountPassword) {
setAccountName(savedAccountName);
setEmail(savedAccountEmail);
setPassword(savedAccountPassword);
setIsLoggedIn(true); // Automatically log in
}
}, []);
// Function to toggle the login popup // Function to toggle the login popup
const toggleLoginPopup = () => setShowLoginPopup(!showLoginPopup); const toggleLoginPopup = () => setShowLoginPopup(!showLoginPopup);
@ -43,27 +32,22 @@ const Login: React.FC = () => {
// Function to handle login // Function to handle login
const handleLogin = () => { const handleLogin = () => {
const savedAccountEmail = localStorage.getItem('accountEmail'); if ((email === fixedEmail || accountName === fixedAccount) && password === fixedPassword) {
const savedAccountPassword = localStorage.getItem('accountPassword');
const savedAccountName = localStorage.getItem('accountName');
if ((email === savedAccountEmail || accountName === savedAccountName) && password === savedAccountPassword) {
setIsLoggedIn(true); // Successful login setIsLoggedIn(true); // Successful login
setShowLoginPopup(false); // Close the login popup setShowLoginPopup(false); // Close the login popup
// Save credentials to localStorage
localStorage.setItem('accountName', savedAccountName || accountName);
localStorage.setItem('accountEmail', savedAccountEmail || email);
localStorage.setItem('accountPassword', savedAccountPassword || password);
} else { } else {
alert('Incorrect credentials'); alert('Incorrect credentials');
} }
}; };
const handleLogout = () => {
setIsLoggedIn(false);
setShowSettingsPopup(false); // Optionally close settings popup on logout
};
// Function to handle account creation // Function to handle account creation
const handleCreateAccount = () => { const handleCreateAccount = () => {
localStorage.setItem('accountName', newAccountName); console.log('New Account Created:', newAccountEmail, newAccountPassword);
localStorage.setItem('accountEmail', newAccountEmail);
localStorage.setItem('accountPassword', newAccountPassword);
alert('Account created successfully! You can now log in.'); alert('Account created successfully! You can now log in.');
toggleSignUpPopup(); // Close sign-up popup toggleSignUpPopup(); // Close sign-up popup
}; };

View file

@ -84,14 +84,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
const [anthropic, setAnthropic] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-anthropic').trim()); const [anthropic, setAnthropic] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-anthropic').trim());
const [google, setGoogle] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-google').trim()); const [google, setGoogle] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-google').trim());
const [isLoggedIn, setIsLoggedIn] = useState(false);
const handleLogout = () => {
setIsLoggedIn(false);
localStorage.removeItem('accountName');
localStorage.removeItem('accountEmail');
localStorage.removeItem('accountPassword');
};
// Effect hooks to update localStorage whenever any state changes // Effect hooks to update localStorage whenever any state changes
useEffect(() => { useEffect(() => {
@ -859,7 +851,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
<div className="settings-option"> <div className="settings-option">
<button <button
onClick={() => { onClick={() => {
handleLogout();
closeSettings(); // Optionally close settings after logout closeSettings(); // Optionally close settings after logout
}} }}
className="logout-button" className="logout-button"