Skip to content
Snippets Groups Projects
Commit 5a75698a authored by Shrey Patel's avatar Shrey Patel
Browse files

Merge branch 'czar'

parents 4a45ab81 be6465ab
No related branches found
No related tags found
No related merge requests found
......@@ -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() {
......
......@@ -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>
</>
)}
</>
......
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
......
......@@ -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">
......
......@@ -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)
......
......@@ -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())
{
......
......@@ -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
{
......
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