This commit is contained in:
Николай 2023-05-14 23:37:16 +04:00
parent 9e6b5cc2db
commit b43b77ac12
6 changed files with 33 additions and 37 deletions

Binary file not shown.

View File

@ -24,8 +24,6 @@ export default function App() {
{ path: 'catalog', label: "Catalog", userGroup: "AUTH" },
{ path: 'readerAction', label: "ReaderAction", userGroup: "USER" },
{ path: 'creatorAction', label: "CreatorAction", userGroup: "ADMIN" },
{ path: 'creator', label: "Creator", userGroup: "ADMIN" },
{ path: 'reader', label: "Reader", userGroup: "ADMIN" },
{ path: 'users', label: "Users", userGroup: "ADMIN" }
];
return (

View File

@ -2,7 +2,38 @@ import {NavLink, useNavigate} from 'react-router-dom';
import {useEffect, useState} from "react";
export default function Header(props) {
const navigate = useNavigate();
useEffect(() => {
window.addEventListener("storage", () => {
let token = localStorage.getItem("token");
if (token) {
getRole(token).then((role) => {
if (localStorage.getItem("role") != role) {
localStorage.removeItem("token");
localStorage.removeItem("user");
localStorage.removeItem("role");
window.dispatchEvent(new Event("storage"));
navigate("/catalog");
}
});
}
});
}, [])
const getRole = async function (token) {
const requestParams = {
method: "GET",
headers: {
"Content-Type": "application/json"
}
};
const requestUrl = `http://localhost:8080/who_am_i?token=${token}`;
const response = await fetch(requestUrl, requestParams);
return await response.text();
}
const logoutButtonOnClick = function () {
localStorage.removeItem("token");
localStorage.removeItem("user");

View File

@ -10,10 +10,8 @@ export default function ReaderList(props) {
props.readers?.map((reader) =>
<div key={reader.id} className="d-flex flex-row flex-wrap flex-grow-1 align-items-center mt-3">
<div>
<div className="pt-3 description d-flex flex-column justify-content-start mb-3 fs-6 fw-bold">
<NavLink className="text-white fs-5 fw-bold pt-3 mb-3"
to={`/readeraction?id=${reader.id}`}>Имя пользователя: {reader.readerName}
</NavLink>
<div className="text-white pt-3 description d-flex flex-column justify-content-start mb-3 fs-6 fw-bold">
Имя пользователя: {reader.login}
</div>
</div>
</div>

View File

@ -3,36 +3,7 @@ import {useEffect} from "react";
const PrivateRoutes = (props) => {
const navigate = useNavigate();
useEffect(() => {
window.addEventListener("storage", () => {
let token = localStorage.getItem("token");
if (token) {
getRole(token).then((role) => {
if (localStorage.getItem("role") != role) {
localStorage.removeItem("token");
localStorage.removeItem("user");
localStorage.removeItem("role");
window.dispatchEvent(new Event("storage"));
navigate("/catalog");
}
});
}
});
}, [])
const getRole = async function (token) {
const requestParams = {
method: "GET",
headers: {
"Content-Type": "application/json"
}
};
const requestUrl = `http://localhost:8080/who_am_i?token=${token}`;
const response = await fetch(requestUrl, requestParams);
return await response.text();
}
let isAllowed = false;
let userRole = localStorage.getItem("role");

View File

@ -23,8 +23,6 @@ public class UserDto {
this.email = user.getEmail();
this.password = user.getPassword();
this.role = user.getRole();
this.creatortId = user.getCreator().getId();
this.readerId = user.getReader().getId();
}
public void setId(Long id) {