Skip to content
Snippets Groups Projects
Commit 93bb9f4e authored by Sarthak Shrivastava's avatar Sarthak Shrivastava
Browse files

small safety commit

parent b342569a
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
} from "./components/user/index"; } from "./components/user/index";
import { useState } from "react"; import { useState } from "react";
import useToken from "./components/useToken"; import useToken from "./components/useToken";
import AccountInformation from "./components/user/AccountInformation";
function App() { function App() {
...@@ -29,6 +30,7 @@ function App() { ...@@ -29,6 +30,7 @@ function App() {
<Route path="/register" element={<Register />} /> <Route path="/register" element={<Register />} />
<Route path="/deleteUser" element={<DeleteUser token={token}/>} /> <Route path="/deleteUser" element={<DeleteUser token={token}/>} />
<Route path="/updatepassword" element={<UpdatePassword />} /> <Route path="/updatepassword" element={<UpdatePassword />} />
<Route path="/accountinfo" element={<AccountInformation token={token}/> } />
</Routes> </Routes>
</div> </div>
); );
......
...@@ -31,6 +31,9 @@ export const Navbar = () => { ...@@ -31,6 +31,9 @@ export const Navbar = () => {
<li> <li>
<NavLink to="/updatepassword">Update Password</NavLink> <NavLink to="/updatepassword">Update Password</NavLink>
</li> </li>
<li>
<NavLink to="/accountinfo">Account Information</NavLink>
</li>
</ul> </ul>
</nav> </nav>
); );
......
...@@ -36,3 +36,8 @@ button { ...@@ -36,3 +36,8 @@ button {
button:hover { button:hover {
background-color: #0056b3; background-color: #0056b3;
} }
.success-message {
color: green;
margin-top: 10px;
}
\ No newline at end of file
...@@ -12,6 +12,8 @@ const AccountInformation = ({ token }) => { ...@@ -12,6 +12,8 @@ const AccountInformation = ({ token }) => {
email: "", email: "",
}); });
const [updateSuccess, setUpdateSuccess] = useState(false);
useEffect(() => { useEffect(() => {
// Fetch user information when the component mounts // Fetch user information when the component mounts
getUserInfo(); getUserInfo();
...@@ -43,6 +45,7 @@ const AccountInformation = ({ token }) => { ...@@ -43,6 +45,7 @@ const AccountInformation = ({ token }) => {
} }
); );
setUserInfo(response.data); setUserInfo(response.data);
setUpdateSuccess(true);
console.log("User information updated successfully"); console.log("User information updated successfully");
} catch (error) { } catch (error) {
console.error("Error updating user information:", error); console.error("Error updating user information:", error);
...@@ -60,6 +63,7 @@ const AccountInformation = ({ token }) => { ...@@ -60,6 +63,7 @@ const AccountInformation = ({ token }) => {
return ( return (
<div className="account-info-container"> <div className="account-info-container">
<h2>Account Information</h2> <h2>Account Information</h2>
{updateSuccess && <p className="success-message">Information updated successfully!</p>}
<div className="info-form"> <div className="info-form">
<label htmlFor="fname">First Name</label> <label htmlFor="fname">First Name</label>
<input <input
......
...@@ -63,11 +63,24 @@ public class MainController { ...@@ -63,11 +63,24 @@ public class MainController {
return userRepository.findAll(); return userRepository.findAll();
} }
@GetMapping(path = "/user") @PostMapping(path = "/user")
public @ResponseBody Optional<User> getUser(@RequestBody Map<String, String> json) public @ResponseBody User getUser(@RequestBody Map<String, String> json)
{ {
String email = json.get("email"); User found = new User();
return userRepository.findById(email); 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") @PostMapping(path = "/delete")
......
spring.jpa.hibernate.ddl-auto=create spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/inventory spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/inventory
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=czarthak spring.datasource.password=czarthak
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment