diff --git a/inventory-manager/src/App.jsx b/inventory-manager/src/App.jsx index 539bd716901ca8374f1cfa68672653d16c5652cb..c913e15501418b5110e971f36fc40092361abe2b 100644 --- a/inventory-manager/src/App.jsx +++ b/inventory-manager/src/App.jsx @@ -10,6 +10,7 @@ import { } from "./components/user/index"; import { useState } from "react"; import useToken from "./components/useToken"; +import AccountInformation from "./components/user/AccountInformation"; function App() { @@ -29,6 +30,7 @@ function App() { <Route path="/register" element={<Register />} /> <Route path="/deleteUser" element={<DeleteUser token={token}/>} /> <Route path="/updatepassword" element={<UpdatePassword />} /> + <Route path="/accountinfo" element={<AccountInformation token={token}/> } /> </Routes> </div> ); diff --git a/inventory-manager/src/components/Navbar.jsx b/inventory-manager/src/components/Navbar.jsx index a80a03812e335c3d8da08a6d9773b87857e5b806..201968a58fe2d32a8dea784b3ea5f1155bb5b811 100644 --- a/inventory-manager/src/components/Navbar.jsx +++ b/inventory-manager/src/components/Navbar.jsx @@ -31,6 +31,9 @@ export const Navbar = () => { <li> <NavLink to="/updatepassword">Update Password</NavLink> </li> + <li> + <NavLink to="/accountinfo">Account Information</NavLink> + </li> </ul> </nav> ); diff --git a/inventory-manager/src/components/user/AccountInformation.css b/inventory-manager/src/components/user/AccountInformation.css index ce3388d7489802f4359e9ed7a4074a51d5243525..b44c18c9862137588e0ea6f70e6f0a13f2319804 100644 --- a/inventory-manager/src/components/user/AccountInformation.css +++ b/inventory-manager/src/components/user/AccountInformation.css @@ -36,3 +36,8 @@ button { button:hover { background-color: #0056b3; } + +.success-message { + color: green; + margin-top: 10px; +} \ No newline at end of file diff --git a/inventory-manager/src/components/user/AccountInformation.jsx b/inventory-manager/src/components/user/AccountInformation.jsx index 7884328e9ce5c013b6c4c2c74d066f0999f245e3..61e8007769a936e361a8c56925789670c3ec6c3e 100644 --- a/inventory-manager/src/components/user/AccountInformation.jsx +++ b/inventory-manager/src/components/user/AccountInformation.jsx @@ -12,6 +12,8 @@ const AccountInformation = ({ token }) => { email: "", }); + const [updateSuccess, setUpdateSuccess] = useState(false); + useEffect(() => { // Fetch user information when the component mounts getUserInfo(); @@ -43,6 +45,7 @@ const AccountInformation = ({ token }) => { } ); setUserInfo(response.data); + setUpdateSuccess(true); console.log("User information updated successfully"); } catch (error) { console.error("Error updating user information:", error); @@ -60,6 +63,7 @@ const AccountInformation = ({ token }) => { return ( <div className="account-info-container"> <h2>Account Information</h2> + {updateSuccess && <p className="success-message">Information updated successfully!</p>} <div className="info-form"> <label htmlFor="fname">First Name</label> <input diff --git a/src/main/java/com/example/accessingdatamysql/MainController.java b/src/main/java/com/example/accessingdatamysql/MainController.java index b3933ca29db98d1634e9b660732cd11c5f6009f3..0fb782e6733d1e312def9a08cfe92aa7684cd9f4 100644 --- a/src/main/java/com/example/accessingdatamysql/MainController.java +++ b/src/main/java/com/example/accessingdatamysql/MainController.java @@ -63,11 +63,24 @@ public class MainController { return userRepository.findAll(); } - @GetMapping(path = "/user") - public @ResponseBody Optional<User> getUser(@RequestBody Map<String, String> json) + @PostMapping(path = "/user") + public @ResponseBody User getUser(@RequestBody Map<String, String> json) { - String email = json.get("email"); - return userRepository.findById(email); + User found = new User(); + AuthController au = new AuthController(); + Map<String, String> res = au.verify(json); // if the jwt token could not be verified + if (res.containsKey("login") && res.get("login").equals("failed")) + { + found.setEmail("failed"); + return found; + } + Optional<User> usr = userRepository.findById(res.get("user")); + if (!usr.isPresent()) + { + found.setEmail("not found"); + return found; + } + return usr.get(); } @PostMapping(path = "/delete") diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 9dca1e157892d572a9afe5a7b1ac4084aa26316f..f791667e1463c0933552a2a6d33e06865c2276c9 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ -spring.jpa.hibernate.ddl-auto=create +spring.jpa.hibernate.ddl-auto=none spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/inventory spring.datasource.username=root spring.datasource.password=czarthak