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:
Patrick 2024-09-26 16:37:49 +02:00
commit 32f9c57c01
3 changed files with 39 additions and 14 deletions

View file

@ -1,7 +1,8 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
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);
@ -16,10 +17,20 @@ const Login: React.FC = () => {
const [newAccountPassword, setNewAccountPassword] = useState('');
const [newAccountName, setNewAccountName] = useState('');
// Fixed credentials
const fixedEmail = '';
const fixedPassword = '';
const fixedAccount = '';
// On component mount, check if there are credentials in localStorage
useEffect(() => {
const savedAccountName = localStorage.getItem('accountName');
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
const toggleLoginPopup = () => setShowLoginPopup(!showLoginPopup);
@ -32,22 +43,27 @@ const Login: React.FC = () => {
// Function to handle login
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
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 {
alert('Incorrect credentials');
}
};
const handleLogout = () => {
setIsLoggedIn(false);
setShowSettingsPopup(false); // Optionally close settings popup on logout
};
// Function to handle account creation
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.');
toggleSignUpPopup(); // Close sign-up popup
};
@ -100,7 +116,7 @@ const Login: React.FC = () => {
{/* Text for creating an account */}
<p>
Don't have an account yet? Create one {' '}
Don't have an account yet? Create one{' '}
<span
style={{ color: 'blue', cursor: 'pointer' }}
onClick={toggleSignUpPopup}

View file

@ -84,7 +84,15 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
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 [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
useEffect(() => {
const settings = {
@ -851,6 +859,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
<div className="settings-option">
<button
onClick={() => {
handleLogout();
closeSettings(); // Optionally close settings after logout
}}
className="logout-button"

View file

@ -1,4 +1,4 @@
from flask import Flask, request, jsonify
from flask i mport Flask, request, jsonify
from flask_cors import CORS
import secrets
import threading