forked from React-Group/interstellar_ai
Merge pull request 'Account' (#58) from sageTheDm/interstellar_ai:main into main
Reviewed-on: https://interstellardevelopment.org/code/code/React-Group/interstellar_ai/pulls/58
This commit is contained in:
commit
32f9c57c01
3 changed files with 39 additions and 14 deletions
|
@ -1,7 +1,8 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } 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);
|
||||||
|
@ -16,10 +17,20 @@ const Login: React.FC = () => {
|
||||||
const [newAccountPassword, setNewAccountPassword] = useState('');
|
const [newAccountPassword, setNewAccountPassword] = useState('');
|
||||||
const [newAccountName, setNewAccountName] = useState('');
|
const [newAccountName, setNewAccountName] = useState('');
|
||||||
|
|
||||||
// Fixed credentials
|
// On component mount, check if there are credentials in localStorage
|
||||||
const fixedEmail = '';
|
useEffect(() => {
|
||||||
const fixedPassword = '';
|
const savedAccountName = localStorage.getItem('accountName');
|
||||||
const fixedAccount = '';
|
const savedAccountEmail = localStorage.getItem('accountEmail');
|
||||||
|
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);
|
||||||
|
@ -32,22 +43,27 @@ const Login: React.FC = () => {
|
||||||
|
|
||||||
// Function to handle login
|
// Function to handle login
|
||||||
const handleLogin = () => {
|
const handleLogin = () => {
|
||||||
if ((email === fixedEmail || accountName === fixedAccount) && password === fixedPassword) {
|
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
|
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 = () => {
|
||||||
console.log('New Account Created:', newAccountEmail, newAccountPassword);
|
localStorage.setItem('accountName', newAccountName);
|
||||||
|
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
|
||||||
};
|
};
|
||||||
|
@ -100,7 +116,7 @@ const Login: React.FC = () => {
|
||||||
|
|
||||||
{/* Text for creating an account */}
|
{/* Text for creating an account */}
|
||||||
<p>
|
<p>
|
||||||
Don't have an account yet? Create one {' '}
|
Don't have an account yet? Create one{' '}
|
||||||
<span
|
<span
|
||||||
style={{ color: 'blue', cursor: 'pointer' }}
|
style={{ color: 'blue', cursor: 'pointer' }}
|
||||||
onClick={toggleSignUpPopup}
|
onClick={toggleSignUpPopup}
|
||||||
|
|
|
@ -84,6 +84,14 @@ 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(() => {
|
||||||
|
@ -851,6 +859,7 @@ 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"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import Flask, request, jsonify
|
from flask i mport Flask, request, jsonify
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
import secrets
|
import secrets
|
||||||
import threading
|
import threading
|
||||||
|
|
Loading…
Reference in a new issue