diff --git a/inventory-manager/src/App.jsx b/inventory-manager/src/App.jsx index d61d0abf5c4c66ac7c617bcf8928e35e81fd58ae..95eca88ac922b7cba5194e47d35db540973443c3 100644 --- a/inventory-manager/src/App.jsx +++ b/inventory-manager/src/App.jsx @@ -11,7 +11,6 @@ import { import { useState } from "react"; import useToken from "./components/useToken"; import AccountInformation from "./components/user/AccountInformation"; -import ProtectedRoute from "./routes/ProtectedRoute"; import PrivateRoutes from "./routes/PrivateRoutes"; function App() { diff --git a/inventory-manager/src/components/Navbar.jsx b/inventory-manager/src/components/Navbar.jsx index f8188be0eb13e777fa1af32efb26a480eaa689d1..d50d6dd01741ff8a07ab3819387039008504ae14 100644 --- a/inventory-manager/src/components/Navbar.jsx +++ b/inventory-manager/src/components/Navbar.jsx @@ -34,6 +34,16 @@ export const Navbar = ({ token }) => { <li> <NavLink to="/accountinfo">Account Information</NavLink> </li> + <li> + <NavLink + to="/" + onClick={() => { + sessionStorage.removeItem("token"); + window.location.reload(false); + }}> + Sign Out + </NavLink> + </li> </> )} </> diff --git a/inventory-manager/src/components/user/AccountInformation.jsx b/inventory-manager/src/components/user/AccountInformation.jsx index 61e8007769a936e361a8c56925789670c3ec6c3e..2bd5ab093d5453eff25d4f3042091fab1eab29e3 100644 --- a/inventory-manager/src/components/user/AccountInformation.jsx +++ b/inventory-manager/src/components/user/AccountInformation.jsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from "react"; import Axios from "axios"; import PropTypes from "prop-types"; -import './AccountInformation.css'; // Import your external CSS file +import "./AccountInformation.css"; // Import your external CSS file const AccountInformation = ({ token }) => { const [userInfo, setUserInfo] = useState({ @@ -21,10 +21,10 @@ const AccountInformation = ({ token }) => { const getUserInfo = async () => { try { - const response = await Axios.post( - "http://localhost:8080/user/user", - { jwt: token.jwt } - ); + console.log(token); + const response = await Axios.post("http://localhost:8080/user/user", { + jwt: token.jwt, + }); setUserInfo(response.data); } catch (error) { console.error("Error fetching user information:", error); @@ -33,17 +33,14 @@ const AccountInformation = ({ token }) => { const handleUpdate = async () => { try { - const response = await Axios.put( - "http://localhost:8080/user/update", - { - fname: userInfo.fname, - lname: userInfo.lname, - password: userInfo.password, - phoneNumber: userInfo.phoneNumber, - email: userInfo.email, - jwt: token.jwt, - } - ); + const response = await Axios.put("http://localhost:8080/user/update", { + fname: userInfo.fname, + lname: userInfo.lname, + password: userInfo.password, + phoneNumber: userInfo.phoneNumber, + email: userInfo.email, + jwt: token.jwt, + }); setUserInfo(response.data); setUpdateSuccess(true); console.log("User information updated successfully"); @@ -63,7 +60,9 @@ const AccountInformation = ({ token }) => { return ( <div className="account-info-container"> <h2>Account Information</h2> - {updateSuccess && <p className="success-message">Information updated successfully!</p>} + {updateSuccess && ( + <p className="success-message">Information updated successfully!</p> + )} <div className="info-form"> <label htmlFor="fname">First Name</label> <input diff --git a/inventory-manager/src/components/user/Login.jsx b/inventory-manager/src/components/user/Login.jsx index cd488b1fb98c36166a176023c0ec12e1a22f908e..b55e91c929791fa95d537790ac985eeff6f930ed 100644 --- a/inventory-manager/src/components/user/Login.jsx +++ b/inventory-manager/src/components/user/Login.jsx @@ -10,6 +10,7 @@ export const Login = ({ setToken }) => { const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [loggedIn, setLoggedIn] = useState(false); + const mytoken = null; const handleSubmit = (e) => { e.preventDefault(); setLoading(true); @@ -24,6 +25,7 @@ export const Login = ({ setToken }) => { if (response.data.result === "success") { setToken(response); setLoggedIn(true); + mytoken = response.data; } else { setError("Invalid email or password. Please try again."); } @@ -37,7 +39,7 @@ export const Login = ({ setToken }) => { }); }; if (loggedIn) { - return <Navigate to="/" />; + return <Navigate to="/accountinfo" token={mytoken} />; } return ( <div className="auth-form-container"> diff --git a/phase 1.sql b/phase 1.sql index 7fd89501b4f4092b5511aee1bbe15e9cb0b5c850..bc2724f697f66904564b54db00b25eedbe9aa956 100644 --- a/phase 1.sql +++ b/phase 1.sql @@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS ORGANIZATION ( CREATE TABLE IF NOT EXISTS MANAGER ( userEmail VARCHAR(128) NOT NULL, organizationId INT NOT NULL, + type ENUM('MEMBER', 'MANAGER') NOT NULL, PRIMARY KEY (userEmail, organizationId), CONSTRAINT fk_user_manager FOREIGN KEY (userEmail) REFERENCES USER (email), CONSTRAINT fk_organization_manager FOREIGN KEY (organizationId) REFERENCES ORGANIZATION (organizationId) diff --git a/src/main/java/com/example/accessingdatamysql/MainController.java b/src/main/java/com/example/accessingdatamysql/MainController.java index 0fb782e6733d1e312def9a08cfe92aa7684cd9f4..466ba8cb1c2afb29f7efd155ba454659d53b9e51 100644 --- a/src/main/java/com/example/accessingdatamysql/MainController.java +++ b/src/main/java/com/example/accessingdatamysql/MainController.java @@ -74,6 +74,7 @@ public class MainController { found.setEmail("failed"); return found; } + System.out.println(res.get("user")); Optional<User> usr = userRepository.findById(res.get("user")); if (!usr.isPresent()) { diff --git a/src/main/java/com/example/accessingdatamysql/auth/AuthController.java b/src/main/java/com/example/accessingdatamysql/auth/AuthController.java index 2ae5969fd5e05d94d453fbf869172174f1971a00..7afd8e6d263c661510baadeda11a34a19f96a053 100644 --- a/src/main/java/com/example/accessingdatamysql/auth/AuthController.java +++ b/src/main/java/com/example/accessingdatamysql/auth/AuthController.java @@ -46,7 +46,7 @@ public class AuthController { { res.put("user", user.get().getEmail()); //give them a token - res.put("jwt", JWT.createJWT("id", "issuer", "sarthaks@vt.edu", 99999999)); + res.put("jwt", JWT.createJWT("id", "issuer", json.get("email"), 99999999)); res.put("result", "success"); return res; } @@ -57,6 +57,9 @@ public class AuthController { return res; } + //create auth/organization end point to authenticate the user for a specific organization. + //also create a verification end point to verify their access to this one org. + @PostMapping(path="/verify") public @ResponseBody Map<String, String> verify(@RequestBody Map<String, String> json) { @@ -66,9 +69,12 @@ public class AuthController { Claims claim = JWT.decodeJWT(json.get("jwt")); if (claim != null) { - - } res.put("user", claim.getSubject()); + } + else + { + res.put("login", "failed - expired/bad token"); + } } else {