update to engin
This commit is contained in:
@@ -14,6 +14,7 @@ import Favorites from "./pages/Favorites";
|
|||||||
import ProductDetail from "./pages/ProductDetail";
|
import ProductDetail from "./pages/ProductDetail";
|
||||||
import ItemForm from "./pages/MyListings";
|
import ItemForm from "./pages/MyListings";
|
||||||
import SearchPage from "./pages/SearchPage"; // Make sure to import the SearchPage
|
import SearchPage from "./pages/SearchPage"; // Make sure to import the SearchPage
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
// Authentication state - initialize from localStorage if available
|
// Authentication state - initialize from localStorage if available
|
||||||
@@ -31,6 +32,8 @@ function App() {
|
|||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
const [userId, setUserId] = useState(null);
|
||||||
|
|
||||||
// New verification states
|
// New verification states
|
||||||
const [verificationStep, setVerificationStep] = useState("initial"); // 'initial', 'code-sent', 'verifying'
|
const [verificationStep, setVerificationStep] = useState("initial"); // 'initial', 'code-sent', 'verifying'
|
||||||
const [tempUserData, setTempUserData] = useState(null);
|
const [tempUserData, setTempUserData] = useState(null);
|
||||||
@@ -190,6 +193,9 @@ function App() {
|
|||||||
sessionStorage.setItem("isAuthenticated", "true");
|
sessionStorage.setItem("isAuthenticated", "true");
|
||||||
sessionStorage.setItem("user", JSON.stringify(newUser));
|
sessionStorage.setItem("user", JSON.stringify(newUser));
|
||||||
|
|
||||||
|
// After successful signup, send session data to server
|
||||||
|
sendSessionDataToServer(); // Call it after signup
|
||||||
|
|
||||||
// Reset verification steps
|
// Reset verification steps
|
||||||
setVerificationStep("initial");
|
setVerificationStep("initial");
|
||||||
setTempUserData(null);
|
setTempUserData(null);
|
||||||
@@ -293,6 +299,9 @@ function App() {
|
|||||||
sessionStorage.setItem("isAuthenticated", "true");
|
sessionStorage.setItem("isAuthenticated", "true");
|
||||||
sessionStorage.setItem("user", JSON.stringify(userObj));
|
sessionStorage.setItem("user", JSON.stringify(userObj));
|
||||||
|
|
||||||
|
// After successful signup, send session data to server
|
||||||
|
sendSessionDataToServer(); // Call it after signup
|
||||||
|
|
||||||
sessionStorage.getItem("user");
|
sessionStorage.getItem("user");
|
||||||
|
|
||||||
console.log("Login successful for:", userData.email);
|
console.log("Login successful for:", userData.email);
|
||||||
@@ -357,6 +366,48 @@ function App() {
|
|||||||
setError("");
|
setError("");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sendSessionDataToServer = async () => {
|
||||||
|
try {
|
||||||
|
// Retrieve data from sessionStorage
|
||||||
|
const user = JSON.parse(sessionStorage.getItem("user"));
|
||||||
|
const isAuthenticated =
|
||||||
|
sessionStorage.getItem("isAuthenticated") === "true";
|
||||||
|
|
||||||
|
if (!user || !isAuthenticated) {
|
||||||
|
console.log("User is not authenticated");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare the data to send
|
||||||
|
const requestData = {
|
||||||
|
userId: user.ID, // or user.ID depending on your user structure
|
||||||
|
email: user.email,
|
||||||
|
isAuthenticated,
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Sending user data to the server:", requestData);
|
||||||
|
|
||||||
|
// Send data to Python server (replace with your actual server URL)
|
||||||
|
const response = await fetch("http://localhost:5000/api/user/session", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(requestData),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check the response
|
||||||
|
if (response.ok) {
|
||||||
|
const result = await response.json();
|
||||||
|
console.log("Server response:", result);
|
||||||
|
} else {
|
||||||
|
console.error("Failed to send session data to the server");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error sending session data:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Login component
|
// Login component
|
||||||
const LoginComponent = () => (
|
const LoginComponent = () => (
|
||||||
<div className="flex h-screen bg-white">
|
<div className="flex h-screen bg-white">
|
||||||
|
|||||||
26
recommondation-engine/server.py
Normal file
26
recommondation-engine/server.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from flask import Flask, request, jsonify
|
||||||
|
from flask_cors import CORS
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
CORS(app) # Enable CORS for all routes
|
||||||
|
|
||||||
|
@app.route('/api/user/session', methods=['POST'])
|
||||||
|
def handle_session_data():
|
||||||
|
try:
|
||||||
|
data = request.get_json()
|
||||||
|
user_id = data.get('userId')
|
||||||
|
email = data.get('email')
|
||||||
|
is_authenticated = data.get('isAuthenticated')
|
||||||
|
|
||||||
|
if not user_id or not email or is_authenticated is None:
|
||||||
|
return jsonify({'error': 'Invalid data'}), 400
|
||||||
|
|
||||||
|
print(f"Received session data: User ID: {user_id}, Email: {email}, Authenticated: {is_authenticated}")
|
||||||
|
return jsonify({'message': 'Session data received successfully'})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {e}")
|
||||||
|
return jsonify({'error': 'Server error'}), 500
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True, host='0.0.0.0', port=5000)
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import socket
|
|
||||||
import threading
|
|
||||||
import json
|
|
||||||
|
|
||||||
# Sample recommendations function
|
|
||||||
def get_recommendations(user_id):
|
|
||||||
# This is a mock function. Replace it with your actual recommendation logic.
|
|
||||||
return {"recommendations": [f"Product {user_id} - Item 1", f"Product {user_id} - Item 2", f"Product {user_id} - Item 3"]}
|
|
||||||
|
|
||||||
# Handle client connection
|
|
||||||
def handle_client(client_socket, client_address):
|
|
||||||
print(f"New connection from {client_address}")
|
|
||||||
|
|
||||||
# Receive the client request (user_id)
|
|
||||||
request = client_socket.recv(1024).decode("utf-8")
|
|
||||||
if request:
|
|
||||||
data = json.loads(request)
|
|
||||||
user_id = data.get("user_id")
|
|
||||||
|
|
||||||
# Get recommendations for the user
|
|
||||||
recommendations = get_recommendations(user_id)
|
|
||||||
|
|
||||||
# Send the response back to the client
|
|
||||||
client_socket.send(json.dumps(recommendations).encode("utf-8"))
|
|
||||||
|
|
||||||
# Close the connection after sending the response
|
|
||||||
client_socket.close()
|
|
||||||
|
|
||||||
# Start the server to handle multiple clients
|
|
||||||
def start_server():
|
|
||||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
server.bind(("0.0.0.0", 9999)) # Bind to all interfaces on port 9999
|
|
||||||
server.listen(5)
|
|
||||||
print("Server listening on port 9999...")
|
|
||||||
|
|
||||||
while True:
|
|
||||||
client_socket, client_address = server.accept()
|
|
||||||
client_thread = threading.Thread(target=handle_client, args=(client_socket, client_address))
|
|
||||||
client_thread.start()
|
|
||||||
|
|
||||||
# Run the server
|
|
||||||
start_server()
|
|
||||||
Reference in New Issue
Block a user