singup & login now bug free
This commit is contained in:
@@ -2,9 +2,7 @@ import express, { json } from "express";
|
|||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import mysql from "mysql2";
|
import mysql from "mysql2";
|
||||||
import nodemailer from "nodemailer";
|
import nodemailer from "nodemailer";
|
||||||
|
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import jwt from "jsonwebtoken";
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
@@ -120,7 +118,7 @@ async function sendVerificationEmail(email, verificationCode) {
|
|||||||
await transporter.sendMail({
|
await transporter.sendMail({
|
||||||
from: "campusplug@zohomailcloud.ca",
|
from: "campusplug@zohomailcloud.ca",
|
||||||
to: email,
|
to: email,
|
||||||
subject: "Your Verification Code",
|
subject: "Campus Plug: Signup Verification Code",
|
||||||
text: `Your verification code is: ${verificationCode}. This code will expire in 15 minutes.`,
|
text: `Your verification code is: ${verificationCode}. This code will expire in 15 minutes.`,
|
||||||
html: `<p>Your verification code is: <strong>${verificationCode}</strong></p><p>This code will expire in 15 minutes.</p>`,
|
html: `<p>Your verification code is: <strong>${verificationCode}</strong></p><p>This code will expire in 15 minutes.</p>`,
|
||||||
});
|
});
|
||||||
@@ -215,6 +213,11 @@ app.post("/complete-signup", (req, res) => {
|
|||||||
return res.status(500).json({ error: "Could not create role" });
|
return res.status(500).json({ error: "Could not create role" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db_con.query(
|
||||||
|
`SELECT * FROM User WHERE Email='${data.Email}'`,
|
||||||
|
(err, userID),
|
||||||
|
);
|
||||||
|
|
||||||
// Delete verification record
|
// Delete verification record
|
||||||
db_con.query(
|
db_con.query(
|
||||||
`DELETE FROM AuthVerification WHERE Email = '${data.email}'`,
|
`DELETE FROM AuthVerification WHERE Email = '${data.email}'`,
|
||||||
@@ -225,10 +228,10 @@ app.post("/complete-signup", (req, res) => {
|
|||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "User registration completed successfully",
|
message: "User registration completed successfully",
|
||||||
|
userID: userID,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
email: data.email,
|
email: data.email,
|
||||||
UCID: data.UCID,
|
UCID: data.UCID,
|
||||||
phone: data.phone,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -248,7 +251,7 @@ function cleanupExpiredCodes() {
|
|||||||
if (err) {
|
if (err) {
|
||||||
console.error("Error cleaning up expired codes:", err);
|
console.error("Error cleaning up expired codes:", err);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Cleaned up ${results} expired verification codes`);
|
console.log(`Cleaned up ${result} expired verification codes`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -267,22 +270,21 @@ app.get("/fetch_all_users", (req, res) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//Fetch One user Data:
|
//Fetch One user Data with all fields:
|
||||||
app.post("/find_user", (req, res) => {
|
app.post("/find_user", (req, res) => {
|
||||||
const { email, password } = req.body;
|
const { email } = req.body;
|
||||||
|
|
||||||
// Input validation
|
// Input validation
|
||||||
if (!email || !password) {
|
if (!email) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
found: false,
|
found: false,
|
||||||
error: "Email and password are required",
|
error: "Email is required",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query to find user with matching email and password
|
// Query to find user with matching email and password
|
||||||
const query = "SELECT * FROM User WHERE email = ? AND password = ?";
|
const query = "SELECT * FROM User WHERE email = ?";
|
||||||
|
db_con.query(query, [email], (err, data) => {
|
||||||
db_con.query(query, [email, password], (err, data) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("Error finding user:", err);
|
console.error("Error finding user:", err);
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
@@ -296,11 +298,17 @@ app.post("/find_user", (req, res) => {
|
|||||||
console.log(data);
|
console.log(data);
|
||||||
const user = data[0];
|
const user = data[0];
|
||||||
|
|
||||||
// Return user data without sensitive information
|
// Return all user data except password
|
||||||
return res.json({
|
return res.json({
|
||||||
found: true,
|
found: true,
|
||||||
|
userID: user.UserID,
|
||||||
name: user.Name,
|
name: user.Name,
|
||||||
email: user.Email,
|
email: user.Email,
|
||||||
|
UCID: user.UCID,
|
||||||
|
phone: user.Phone,
|
||||||
|
address: user.Address,
|
||||||
|
// Include any other fields your user might have
|
||||||
|
// Make sure the field names match exactly with your database column names
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// User not found or invalid credentials
|
// User not found or invalid credentials
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ import ProductDetail from "./pages/ProductDetail";
|
|||||||
function App() {
|
function App() {
|
||||||
// Authentication state - initialize from localStorage if available
|
// Authentication state - initialize from localStorage if available
|
||||||
const [isAuthenticated, setIsAuthenticated] = useState(() => {
|
const [isAuthenticated, setIsAuthenticated] = useState(() => {
|
||||||
return localStorage.getItem("isAuthenticated") === "true";
|
return sessionStorage.getItem("isAuthenticated") === "true";
|
||||||
});
|
});
|
||||||
const [user, setUser] = useState(() => {
|
const [user, setUser] = useState(() => {
|
||||||
const savedUser = localStorage.getItem("user");
|
const savedUser = sessionStorage.getItem("user");
|
||||||
return savedUser ? JSON.parse(savedUser) : null;
|
return savedUser ? JSON.parse(savedUser) : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,7 +32,6 @@ function App() {
|
|||||||
// 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);
|
||||||
const [verificationCode, setVerificationCode] = useState("");
|
|
||||||
|
|
||||||
// Auto-hide image on smaller screens
|
// Auto-hide image on smaller screens
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -166,10 +165,10 @@ function App() {
|
|||||||
if (result.success) {
|
if (result.success) {
|
||||||
// Create user object from API response
|
// Create user object from API response
|
||||||
const newUser = {
|
const newUser = {
|
||||||
|
ID: result.userID,
|
||||||
name: result.name || userData.name,
|
name: result.name || userData.name,
|
||||||
email: result.email || userData.email,
|
email: result.email || userData.email,
|
||||||
UCID: result.UCID || userData.ucid,
|
UCID: result.UCID || userData.ucid,
|
||||||
phone: result.phone || userData.phone,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set authenticated user
|
// Set authenticated user
|
||||||
@@ -177,8 +176,8 @@ function App() {
|
|||||||
setIsAuthenticated(true);
|
setIsAuthenticated(true);
|
||||||
|
|
||||||
// Save to localStorage to persist across refreshes
|
// Save to localStorage to persist across refreshes
|
||||||
localStorage.setItem("isAuthenticated", "true");
|
sessionStorage.setItem("isAuthenticated", "true");
|
||||||
localStorage.setItem("user", JSON.stringify(newUser));
|
sessionStorage.setItem("user", JSON.stringify(newUser));
|
||||||
|
|
||||||
// Reset verification steps
|
// Reset verification steps
|
||||||
setVerificationStep("initial");
|
setVerificationStep("initial");
|
||||||
@@ -265,7 +264,8 @@ function App() {
|
|||||||
if (userData && userData.found) {
|
if (userData && userData.found) {
|
||||||
// Create user object
|
// Create user object
|
||||||
const userObj = {
|
const userObj = {
|
||||||
name: userData.name || userData.email,
|
ID: userData.userID,
|
||||||
|
name: userData.name,
|
||||||
email: userData.email,
|
email: userData.email,
|
||||||
// Add any other user data returned from the API
|
// Add any other user data returned from the API
|
||||||
};
|
};
|
||||||
@@ -275,8 +275,10 @@ function App() {
|
|||||||
setIsAuthenticated(true);
|
setIsAuthenticated(true);
|
||||||
|
|
||||||
// Save to localStorage to persist across refreshes
|
// Save to localStorage to persist across refreshes
|
||||||
localStorage.setItem("isAuthenticated", "true");
|
sessionStorage.setItem("isAuthenticated", "true");
|
||||||
localStorage.setItem("user", JSON.stringify(userObj));
|
sessionStorage.setItem("user", JSON.stringify(userObj));
|
||||||
|
|
||||||
|
sessionStorage.getItem("user");
|
||||||
|
|
||||||
console.log("Login successful for:", userData.email);
|
console.log("Login successful for:", userData.email);
|
||||||
} else {
|
} else {
|
||||||
@@ -314,8 +316,9 @@ function App() {
|
|||||||
setTempUserData(null);
|
setTempUserData(null);
|
||||||
|
|
||||||
// Clear localStorage
|
// Clear localStorage
|
||||||
localStorage.removeItem("isAuthenticated");
|
//
|
||||||
localStorage.removeItem("user");
|
sessionStorage.removeItem("user");
|
||||||
|
sessionStorage.removeItem("isAuthenticated");
|
||||||
|
|
||||||
console.log("User logged out");
|
console.log("User logged out");
|
||||||
};
|
};
|
||||||
@@ -592,14 +595,12 @@ function App() {
|
|||||||
{isAuthenticated && (
|
{isAuthenticated && (
|
||||||
<Navbar onLogout={handleLogout} userName={user?.name} />
|
<Navbar onLogout={handleLogout} userName={user?.name} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Routes>
|
<Routes>
|
||||||
{/* Public routes */}
|
{/* Public routes */}
|
||||||
<Route
|
<Route
|
||||||
path="/login"
|
path="/login"
|
||||||
element={isAuthenticated ? <Navigate to="/" /> : <LoginComponent />}
|
element={isAuthenticated ? <Navigate to="/" /> : <LoginComponent />}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Protected routes */}
|
{/* Protected routes */}
|
||||||
<Route
|
<Route
|
||||||
path="/"
|
path="/"
|
||||||
@@ -611,7 +612,6 @@ function App() {
|
|||||||
</ProtectedRoute>
|
</ProtectedRoute>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="/product/:id"
|
path="/product/:id"
|
||||||
element={
|
element={
|
||||||
@@ -620,7 +620,6 @@ function App() {
|
|||||||
</ProtectedRoute>
|
</ProtectedRoute>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="/settings"
|
path="/settings"
|
||||||
element={
|
element={
|
||||||
@@ -631,7 +630,6 @@ function App() {
|
|||||||
</ProtectedRoute>
|
</ProtectedRoute>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="/selling"
|
path="/selling"
|
||||||
element={
|
element={
|
||||||
@@ -653,7 +651,6 @@ function App() {
|
|||||||
</ProtectedRoute>
|
</ProtectedRoute>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="/favorites"
|
path="/favorites"
|
||||||
element={
|
element={
|
||||||
@@ -664,7 +661,6 @@ function App() {
|
|||||||
</ProtectedRoute>
|
</ProtectedRoute>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Redirect to login for any unmatched routes */}
|
{/* Redirect to login for any unmatched routes */}
|
||||||
<Route
|
<Route
|
||||||
path="*"
|
path="*"
|
||||||
|
|||||||
@@ -1,48 +1,147 @@
|
|||||||
import { useState } from 'react';
|
import { useState, useEffect } from "react";
|
||||||
import { User, Lock, Trash2, History, Search, Shield } from 'lucide-react';
|
import { User, Lock, Trash2, History, Search, Shield } from "lucide-react";
|
||||||
|
|
||||||
const Settings = () => {
|
const Settings = () => {
|
||||||
const [userData, setUserData] = useState({
|
const [userData, setUserData] = useState({
|
||||||
name: '',
|
userId: "",
|
||||||
email: '',
|
name: "",
|
||||||
phone: '',
|
email: "",
|
||||||
ucid: '',
|
phone: "",
|
||||||
currentPassword: '',
|
UCID: "",
|
||||||
newPassword: '',
|
address: "",
|
||||||
confirmPassword: ''
|
currentPassword: "",
|
||||||
|
newPassword: "",
|
||||||
|
confirmPassword: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
// Fetch user data when component mounts
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchUserData = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
// Get the user's data from localStorage
|
||||||
|
const storedUser = JSON.parse(sessionStorage.getItem("user"));
|
||||||
|
console.log(storedUser);
|
||||||
|
|
||||||
|
if (!storedUser || !storedUser.email) {
|
||||||
|
throw new Error("User details not found. Please log in again.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make API call to fetch user data
|
||||||
|
const response = await fetch("http://localhost:3030/find_user", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
email: storedUser.email,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
if (data.found) {
|
||||||
|
// Update state with fetched data
|
||||||
|
setUserData((prevData) => ({
|
||||||
|
...prevData,
|
||||||
|
userId: data.userId || storedUser.id || "", // Try both sources
|
||||||
|
name: data.name || storedUser.name || "",
|
||||||
|
email: data.email || storedUser.email || "",
|
||||||
|
UCID: data.UCID || storedUser.UCID || "",
|
||||||
|
phone: data.phone || storedUser.phone || "",
|
||||||
|
address: data.address || storedUser.address || "",
|
||||||
|
// Reset password fields
|
||||||
|
currentPassword: "",
|
||||||
|
newPassword: "",
|
||||||
|
confirmPassword: "",
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
throw new Error(data.error || "Failed to retrieve user data");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching user data:", error);
|
||||||
|
setError(
|
||||||
|
error.message || "An error occurred while loading your profile",
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchUserData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleInputChange = (e) => {
|
const handleInputChange = (e) => {
|
||||||
const { id, value } = e.target;
|
const { id, value } = e.target;
|
||||||
setUserData(prevData => ({
|
setUserData((prevData) => ({
|
||||||
...prevData,
|
...prevData,
|
||||||
[id]: value
|
[id]: value,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleProfileUpdate = (e) => {
|
const handleProfileUpdate = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// TODO: updated profile data to a server
|
try {
|
||||||
console.log('Profile updated:', userData);
|
// TODO: Implement the actual update API call
|
||||||
alert('Profile updated successfully!');
|
console.log("Profile updated:", userData);
|
||||||
};
|
|
||||||
|
|
||||||
const handlePasswordUpdate = (e) => {
|
// Update localStorage with new user data
|
||||||
e.preventDefault();
|
const storedUser = JSON.parse(localStorage.getItem("user"));
|
||||||
// TODO: validate and update password
|
const updatedUser = {
|
||||||
if (userData.newPassword !== userData.confirmPassword) {
|
...storedUser,
|
||||||
alert('New passwords do not match!');
|
name: userData.name,
|
||||||
return;
|
phone: userData.phone,
|
||||||
|
UCID: userData.UCID,
|
||||||
|
address: userData.address,
|
||||||
|
};
|
||||||
|
localStorage.setItem("user", JSON.stringify(updatedUser));
|
||||||
|
|
||||||
|
alert("Profile updated successfully!");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating profile:", error);
|
||||||
|
alert("Failed to update profile: " + error.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePasswordUpdate = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
// Validate passwords match
|
||||||
|
if (userData.newPassword !== userData.confirmPassword) {
|
||||||
|
alert("New passwords do not match!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Implement the actual password update API call
|
||||||
|
console.log("Password updated");
|
||||||
|
|
||||||
|
// Update password in localStorage
|
||||||
|
const storedUser = JSON.parse(localStorage.getItem("user"));
|
||||||
|
const updatedUser = {
|
||||||
|
...storedUser,
|
||||||
|
password: userData.newPassword,
|
||||||
|
};
|
||||||
|
localStorage.setItem("user", JSON.stringify(updatedUser));
|
||||||
|
|
||||||
|
// Reset password fields
|
||||||
|
setUserData((prevData) => ({
|
||||||
|
...prevData,
|
||||||
|
currentPassword: "",
|
||||||
|
newPassword: "",
|
||||||
|
confirmPassword: "",
|
||||||
|
}));
|
||||||
|
|
||||||
|
alert("Password updated successfully!");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating password:", error);
|
||||||
|
alert("Failed to update password: " + error.message);
|
||||||
}
|
}
|
||||||
console.log('Password updated');
|
|
||||||
// Reset password fields
|
|
||||||
setUserData(prevData => ({
|
|
||||||
...prevData,
|
|
||||||
currentPassword: '',
|
|
||||||
newPassword: '',
|
|
||||||
confirmPassword: ''
|
|
||||||
}));
|
|
||||||
alert('Password updated successfully!');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteHistory = (type) => {
|
const handleDeleteHistory = (type) => {
|
||||||
@@ -51,24 +150,91 @@ const Settings = () => {
|
|||||||
alert(`${type} history deleted successfully!`);
|
alert(`${type} history deleted successfully!`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDeleteAccount = async () => {
|
||||||
|
if (
|
||||||
|
window.confirm(
|
||||||
|
"Are you sure you want to delete your account? This action cannot be undone.",
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
// Get user ID from state or localStorage
|
||||||
|
const storedUser = JSON.parse(sessionStorage.getItem("user"));
|
||||||
|
const userId = storedUser.ID;
|
||||||
|
|
||||||
|
if (!userId) {
|
||||||
|
throw new Error("User ID not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make API call to delete the account
|
||||||
|
const response = await fetch("http://localhost:3030/delete", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
userId: userId,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.success) {
|
||||||
|
alert("Account deleted successfully. You will be logged out.");
|
||||||
|
// Clear user data from localStorage and redirect to login
|
||||||
|
sessionStorage.removeItem("user");
|
||||||
|
sessionStorage.removeItem("isAuthenticated");
|
||||||
|
window.location.href = "/login";
|
||||||
|
} else {
|
||||||
|
throw new Error(data.error || "Failed to delete account");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error deleting account:", error);
|
||||||
|
alert("Failed to delete account: " + error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Show loading state
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="flex justify-center items-center h-64">
|
||||||
|
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-green-500"></div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="max-w-3xl mx-auto">
|
<div className="max-w-3xl mx-auto">
|
||||||
<h1 className="text-2xl font-bold text-gray-800 mb-6">Account Settings</h1>
|
<h1 className="text-2xl font-bold text-gray-800 mb-6">
|
||||||
|
Account Settings
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
{/* Error message if any */}
|
||||||
|
{error && (
|
||||||
|
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Profile Information Section */}
|
{/* Profile Information Section */}
|
||||||
<div className="bg-white border border-gray-200 mb-6">
|
<div className="bg-white border border-gray-200 mb-6">
|
||||||
<div className="border-b border-gray-200 p-4">
|
<div className="border-b border-gray-200 p-4">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<User className="h-5 w-5 text-gray-500 mr-2" />
|
<User className="h-5 w-5 text-gray-500 mr-2" />
|
||||||
<h2 className="text-lg font-medium text-gray-800">Profile Information</h2>
|
<h2 className="text-lg font-medium text-gray-800">
|
||||||
|
Profile Information
|
||||||
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<form onSubmit={handleProfileUpdate}>
|
<form onSubmit={handleProfileUpdate}>
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="name" className="block text-sm font-medium text-gray-700 mb-1">
|
<label
|
||||||
|
htmlFor="name"
|
||||||
|
className="block text-sm font-medium text-gray-700 mb-1"
|
||||||
|
>
|
||||||
Full Name
|
Full Name
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -80,9 +246,12 @@ const Settings = () => {
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="email" className="block text-sm font-medium text-gray-700 mb-1">
|
<label
|
||||||
|
htmlFor="email"
|
||||||
|
className="block text-sm font-medium text-gray-700 mb-1"
|
||||||
|
>
|
||||||
Email Address
|
Email Address
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -92,11 +261,15 @@ const Settings = () => {
|
|||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
className="w-full p-2 border border-gray-300 focus:outline-none focus:border-green-500"
|
className="w-full p-2 border border-gray-300 focus:outline-none focus:border-green-500"
|
||||||
required
|
required
|
||||||
|
readOnly // Email is often used as identifier and not changeable
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="phone" className="block text-sm font-medium text-gray-700 mb-1">
|
<label
|
||||||
|
htmlFor="phone"
|
||||||
|
className="block text-sm font-medium text-gray-700 mb-1"
|
||||||
|
>
|
||||||
Phone Number
|
Phone Number
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -107,23 +280,42 @@ const Settings = () => {
|
|||||||
className="w-full p-2 border border-gray-300 focus:outline-none focus:border-green-500"
|
className="w-full p-2 border border-gray-300 focus:outline-none focus:border-green-500"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="ucid" className="block text-sm font-medium text-gray-700 mb-1">
|
<label
|
||||||
|
htmlFor="UCID"
|
||||||
|
className="block text-sm font-medium text-gray-700 mb-1"
|
||||||
|
>
|
||||||
UCID
|
UCID
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
id="ucid"
|
id="UCID"
|
||||||
value={userData.ucid}
|
value={userData.UCID}
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
className="w-full p-2 border border-gray-300 focus:outline-none focus:border-green-500"
|
className="w-full p-2 border border-gray-300 focus:outline-none focus:border-green-500"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
htmlFor="address"
|
||||||
|
className="block text-sm font-medium text-gray-700 mb-1"
|
||||||
|
>
|
||||||
|
Address
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="address"
|
||||||
|
value={userData.address}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
className="w-full p-2 border border-gray-300 focus:outline-none focus:border-green-500"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="bg-green-500 hover:bg-green-600 text-white font-medium py-2 px-4"
|
className="bg-green-500 hover:bg-green-600 text-white font-medium py-2 px-4"
|
||||||
>
|
>
|
||||||
@@ -132,7 +324,7 @@ const Settings = () => {
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Security Section */}
|
{/* Security Section */}
|
||||||
<div className="bg-white border border-gray-200 mb-6">
|
<div className="bg-white border border-gray-200 mb-6">
|
||||||
<div className="border-b border-gray-200 p-4">
|
<div className="border-b border-gray-200 p-4">
|
||||||
@@ -141,12 +333,15 @@ const Settings = () => {
|
|||||||
<h2 className="text-lg font-medium text-gray-800">Password</h2>
|
<h2 className="text-lg font-medium text-gray-800">Password</h2>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<form onSubmit={handlePasswordUpdate}>
|
<form onSubmit={handlePasswordUpdate}>
|
||||||
<div className="space-y-4 mb-4">
|
<div className="space-y-4 mb-4">
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="currentPassword" className="block text-sm font-medium text-gray-700 mb-1">
|
<label
|
||||||
|
htmlFor="currentPassword"
|
||||||
|
className="block text-sm font-medium text-gray-700 mb-1"
|
||||||
|
>
|
||||||
Current Password
|
Current Password
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -158,9 +353,12 @@ const Settings = () => {
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="newPassword" className="block text-sm font-medium text-gray-700 mb-1">
|
<label
|
||||||
|
htmlFor="newPassword"
|
||||||
|
className="block text-sm font-medium text-gray-700 mb-1"
|
||||||
|
>
|
||||||
New Password
|
New Password
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -172,9 +370,12 @@ const Settings = () => {
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="confirmPassword" className="block text-sm font-medium text-gray-700 mb-1">
|
<label
|
||||||
|
htmlFor="confirmPassword"
|
||||||
|
className="block text-sm font-medium text-gray-700 mb-1"
|
||||||
|
>
|
||||||
Confirm New Password
|
Confirm New Password
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -187,8 +388,8 @@ const Settings = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className="bg-green-500 hover:bg-green-600 text-white font-medium py-2 px-4"
|
className="bg-green-500 hover:bg-green-600 text-white font-medium py-2 px-4"
|
||||||
>
|
>
|
||||||
@@ -197,7 +398,7 @@ const Settings = () => {
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Privacy Section */}
|
{/* Privacy Section */}
|
||||||
<div className="bg-white border border-gray-200 mb-6">
|
<div className="bg-white border border-gray-200 mb-6">
|
||||||
<div className="border-b border-gray-200 p-4">
|
<div className="border-b border-gray-200 p-4">
|
||||||
@@ -206,7 +407,7 @@ const Settings = () => {
|
|||||||
<h2 className="text-lg font-medium text-gray-800">Privacy</h2>
|
<h2 className="text-lg font-medium text-gray-800">Privacy</h2>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex justify-between items-center pb-4 border-b border-gray-100">
|
<div className="flex justify-between items-center pb-4 border-b border-gray-100">
|
||||||
@@ -214,28 +415,34 @@ const Settings = () => {
|
|||||||
<Search className="h-5 w-5 text-gray-500 mr-2 mt-0.5" />
|
<Search className="h-5 w-5 text-gray-500 mr-2 mt-0.5" />
|
||||||
<div>
|
<div>
|
||||||
<h3 className="font-medium text-gray-800">Search History</h3>
|
<h3 className="font-medium text-gray-800">Search History</h3>
|
||||||
<p className="text-sm text-gray-500">Delete all your search history on StudentMarket</p>
|
<p className="text-sm text-gray-500">
|
||||||
|
Delete all your search history on StudentMarket
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleDeleteHistory('search')}
|
onClick={() => handleDeleteHistory("search")}
|
||||||
className="bg-gray-100 hover:bg-gray-200 text-gray-700 font-medium py-2 px-4 flex items-center"
|
className="bg-gray-100 hover:bg-gray-200 text-gray-700 font-medium py-2 px-4 flex items-center"
|
||||||
>
|
>
|
||||||
<Trash2 className="h-4 w-4 mr-1" />
|
<Trash2 className="h-4 w-4 mr-1" />
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
<div className="flex items-start">
|
<div className="flex items-start">
|
||||||
<History className="h-5 w-5 text-gray-500 mr-2 mt-0.5" />
|
<History className="h-5 w-5 text-gray-500 mr-2 mt-0.5" />
|
||||||
<div>
|
<div>
|
||||||
<h3 className="font-medium text-gray-800">Browsing History</h3>
|
<h3 className="font-medium text-gray-800">
|
||||||
<p className="text-sm text-gray-500">Delete all your browsing history on StudentMarket</p>
|
Browsing History
|
||||||
|
</h3>
|
||||||
|
<p className="text-sm text-gray-500">
|
||||||
|
Delete all your browsing history on StudentMarket
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleDeleteHistory('browsing')}
|
onClick={() => handleDeleteHistory("browsing")}
|
||||||
className="bg-gray-100 hover:bg-gray-200 text-gray-700 font-medium py-2 px-4 flex items-center"
|
className="bg-gray-100 hover:bg-gray-200 text-gray-700 font-medium py-2 px-4 flex items-center"
|
||||||
>
|
>
|
||||||
<Trash2 className="h-4 w-4 mr-1" />
|
<Trash2 className="h-4 w-4 mr-1" />
|
||||||
@@ -245,29 +452,25 @@ const Settings = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Delete Account (Danger Zone) */}
|
{/* Delete Account (Danger Zone) */}
|
||||||
<div className="bg-white border border-red-200 mb-6">
|
<div className="bg-white border border-red-200 mb-6">
|
||||||
<div className="border-b border-red-200 p-4 bg-red-50">
|
<div className="border-b border-red-200 p-4 bg-red-50">
|
||||||
<h2 className="text-lg font-medium text-red-700">Danger Zone</h2>
|
<h2 className="text-lg font-medium text-red-700">Danger Zone</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
<div>
|
<div>
|
||||||
<h3 className="font-medium text-gray-800">Delete Account</h3>
|
<h3 className="font-medium text-gray-800">Delete Account</h3>
|
||||||
<p className="text-sm text-gray-500">
|
<p className="text-sm text-gray-500">
|
||||||
Once you delete your account, there is no going back. Please be certain.
|
Once you delete your account, there is no going back. Please be
|
||||||
|
certain.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
className="bg-red-500 hover:bg-red-600 text-white font-medium py-2 px-4"
|
className="bg-red-500 hover:bg-red-600 text-white font-medium py-2 px-4"
|
||||||
onClick={() => {
|
onClick={handleDeleteAccount}
|
||||||
if (window.confirm('Are you sure you want to delete your account? This action cannot be undone.')) {
|
|
||||||
console.log('Account deletion requested');
|
|
||||||
alert('Account deletion request submitted. You will receive a confirmation email.');
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Delete Account
|
Delete Account
|
||||||
</button>
|
</button>
|
||||||
@@ -278,4 +481,4 @@ const Settings = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Settings;
|
export default Settings;
|
||||||
|
|||||||
Reference in New Issue
Block a user