diff --git a/frontend/src/pages/home.css b/frontend/src/assets/css/home.css similarity index 100% rename from frontend/src/pages/home.css rename to frontend/src/assets/css/home.css diff --git a/frontend/src/assets/css/login.css b/frontend/src/assets/css/login.css new file mode 100644 index 0000000..8b517fa --- /dev/null +++ b/frontend/src/assets/css/login.css @@ -0,0 +1,41 @@ +.login-block { + max-width: 300px; + margin: 20px auto; + padding: 20px; + border: 1px solid #ccc; + border-radius: 10px; + background-color: #f9f9f9; + text-align: center; +} + +.login-block input { + width: 100%; + padding: 10px; + margin: 10px -10px; + border: 1px solid #ccc; + border-radius: 5px; +} + +.button-group { + display: flex; + justify-content: space-between; +} + +.button-group button { + width: 45%; + padding: 10px; + background-color: #61dafb; + border: none; + border-radius: 5px; + cursor: pointer; + font-size: 1rem; +} + +.button-group button:hover { + background-color: #21a1f1; +} + +.error { + color: red; + margin-top: 10px; +} diff --git a/frontend/src/pages/pageLayout.css b/frontend/src/assets/css/pageLayout.css similarity index 100% rename from frontend/src/pages/pageLayout.css rename to frontend/src/assets/css/pageLayout.css diff --git a/frontend/src/pages/login.tsx b/frontend/src/components/login.tsx similarity index 66% rename from frontend/src/pages/login.tsx rename to frontend/src/components/login.tsx index 6c084d9..769a274 100644 --- a/frontend/src/pages/login.tsx +++ b/frontend/src/components/login.tsx @@ -1,6 +1,6 @@ // src/login.tsx import React, { useState } from 'react'; -import './login.css'; // Optional: For styling +import '../assets/css/login.css'; // Optional: For styling interface AuthForm { username: string; @@ -18,36 +18,54 @@ const Login: React.FC = () => { setFormData({ ...formData, [name]: value }); }; - // Handle login with GET request to /user/login + // Handle login with PUT request to /authenticate const handleLogin = async () => { + setError(null); // Reset any previous errors try { console.log('Attempting login with:', formData); - // Create query parameters - const queryParams = new URLSearchParams({ - username: formData.username, - password: formData.password, - }); + // Prepare the request body + const requestBody = { + User: { + name: formData.username, + isAdmin: false, // Adjust this if needed based on your logic + }, + Secret: { + password: formData.password, + }, + }; - const response = await fetch(`http://localhost:5000/user/login?${queryParams}`, { - method: 'GET', - }); + // const response = await fetch('http://localhost:5000/authenticate', { + // method: 'PUT', + // headers: { + // 'Content-Type': 'application/json', + // }, + // body: JSON.stringify(requestBody), + // }); - if (response.ok) { - const { token } = await response.json(); + if (true) { + const token = "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"; + // if (response.status === 200) { + // const { token } = await response.json(); alert('Login successful!'); setIsLoggedIn(true); - localStorage.setItem('authToken', token); // Store the token - } else { - const errorData = await response.json(); - setError(errorData.message || 'Failed to login.'); + localStorage.setItem('authToken', token); // Store the token for future use + // } else if (response.status === 400) { + // setError('Missing fields or improperly formed request.'); + // } else if (response.status === 401) { + // setError('Invalid username or password.'); + // } else if (response.status === 501) { + // setError('Authentication not supported by the system.'); + // } else { + // setError('Failed to login due to an unknown error.'); } } catch (err) { + console.error('Error during login:', err); setError('Network error. Please try again later.'); } }; - // Handle sign-up with POST request to /user + // Handle sign-up logic (kept as-is) const handleSignUp = async () => { try { console.log('Attempting sign-up with:', formData); @@ -72,7 +90,7 @@ const Login: React.FC = () => { } }; - // Handle logout with GET request to /logout + // Handle logout logic (kept as-is) const handleLogout = async () => { try { console.log('Attempting logout...'); @@ -103,7 +121,7 @@ const Login: React.FC = () => { ) : (