From 93bb9f4e455059c58a3db2f7991a82c19a7474a2 Mon Sep 17 00:00:00 2001 From: Sarthak Shrivastava <sarthaks@vt.edu> Date: Fri, 24 Nov 2023 23:58:25 -0500 Subject: [PATCH] small safety commit --- inventory-manager/src/App.jsx | 2 ++ inventory-manager/src/components/Navbar.jsx | 3 +++ .../components/user/AccountInformation.css | 5 +++++ .../components/user/AccountInformation.jsx | 4 ++++ .../accessingdatamysql/MainController.java | 21 +++++++++++++++---- src/main/resources/application.properties | 2 +- 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/inventory-manager/src/App.jsx b/inventory-manager/src/App.jsx index 539bd71..c913e15 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 a80a038..201968a 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 ce3388d..b44c18c 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 7884328..61e8007 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 b3933ca..0fb782e 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 9dca1e1..f791667 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 -- GitLab