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 {
} 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>
);
......
......@@ -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>
);
......
......@@ -36,3 +36,8 @@ button {
button:hover {
background-color: #0056b3;
}
.success-message {
color: green;
margin-top: 10px;
}
\ No newline at end of file
......@@ -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
......
......@@ -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")
......
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
......
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