From 5dd9a0d2e11ef474b0b0749ae77c9bfcd98115cb Mon Sep 17 00:00:00 2001 From: Nikita Sergeev Date: Sun, 14 May 2023 13:53:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 36 ++--- front/index.html | 17 ++- front/src/App.jsx | 107 ++++++++++----- .../components/catalogs/CatalogHistory.jsx | 2 +- front/src/components/catalogs/Login.jsx | 109 ++++++++++++++++ .../src/components/catalogs/Registration.jsx | 115 ++++++++++++++++ front/src/components/catalogs/Users.jsx | 76 +++++++++++ front/src/components/common/Card.jsx | 123 +++++++++--------- front/src/components/common/Header.jsx | 94 ++++++++----- front/src/components/common/PrivateRoute.jsx | 45 +++++++ front/src/components/common/TableOrder.jsx | 2 +- .../src/components/common/ToolbarProduct.jsx | 34 ++--- front/src/models/Order.js | 1 + front/src/models/User.js | 7 + front/src/services/DataService.js | 42 +++++- .../java/ip/labwork/LabworkApplication.java | 8 +- .../configuration/OpenAPI30Configuration.java | 28 ++++ .../PasswordEncoderConfiguration.java | 14 ++ .../configuration/SecurityConfiguration.java | 92 +++++++++++++ .../{ => configuration}/WebConfiguration.java | 11 +- .../configuration/jwt/JwtException.java | 11 ++ .../labwork/configuration/jwt/JwtFilter.java | 72 ++++++++++ .../configuration/jwt/JwtProperties.java | 27 ++++ .../configuration/jwt/JwtProvider.java | 107 +++++++++++++++ .../shop/controller/ComponentController.java | 12 +- .../shop/controller/OrderController.java | 29 ++++- .../ip/labwork/shop/controller/OrderDTO.java | 20 +++ .../shop/controller/ProductController.java | 25 +++- .../java/ip/labwork/shop/model/Order.java | 25 +++- .../ip/labwork/shop/service/OrderService.java | 27 +++- .../user/controller/UserController.java | 64 +++++++++ .../ip/labwork/user/controller/UserDto.java | 44 +++++++ .../labwork/user/controller/UserInfoDto.java | 34 +++++ .../labwork/user/controller/UsersPageDTO.java | 29 +++++ src/main/java/ip/labwork/user/model/User.java | 83 ++++++++++++ .../java/ip/labwork/user/model/UserRole.java | 20 +++ .../user/repository/UserRepository.java | 8 ++ .../user/service/UserExistsException.java | 7 + .../user/service/UserNotFoundException.java | 7 + .../ip/labwork/user/service/UserService.java | 99 ++++++++++++++ .../util/validation/ValidationException.java | 4 + src/main/resources/application.properties | 4 +- 42 files changed, 1518 insertions(+), 203 deletions(-) create mode 100644 front/src/components/catalogs/Login.jsx create mode 100644 front/src/components/catalogs/Registration.jsx create mode 100644 front/src/components/catalogs/Users.jsx create mode 100644 front/src/components/common/PrivateRoute.jsx create mode 100644 front/src/models/User.js create mode 100644 src/main/java/ip/labwork/configuration/OpenAPI30Configuration.java create mode 100644 src/main/java/ip/labwork/configuration/PasswordEncoderConfiguration.java create mode 100644 src/main/java/ip/labwork/configuration/SecurityConfiguration.java rename src/main/java/ip/labwork/{ => configuration}/WebConfiguration.java (83%) create mode 100644 src/main/java/ip/labwork/configuration/jwt/JwtException.java create mode 100644 src/main/java/ip/labwork/configuration/jwt/JwtFilter.java create mode 100644 src/main/java/ip/labwork/configuration/jwt/JwtProperties.java create mode 100644 src/main/java/ip/labwork/configuration/jwt/JwtProvider.java create mode 100644 src/main/java/ip/labwork/user/controller/UserController.java create mode 100644 src/main/java/ip/labwork/user/controller/UserDto.java create mode 100644 src/main/java/ip/labwork/user/controller/UserInfoDto.java create mode 100644 src/main/java/ip/labwork/user/controller/UsersPageDTO.java create mode 100644 src/main/java/ip/labwork/user/model/User.java create mode 100644 src/main/java/ip/labwork/user/model/UserRole.java create mode 100644 src/main/java/ip/labwork/user/repository/UserRepository.java create mode 100644 src/main/java/ip/labwork/user/service/UserExistsException.java create mode 100644 src/main/java/ip/labwork/user/service/UserNotFoundException.java create mode 100644 src/main/java/ip/labwork/user/service/UserService.java diff --git a/build.gradle b/build.gradle index 8fdd46b..70b7195 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.0.2' - id 'io.spring.dependency-management' version '1.1.0' + id 'java' + id 'org.springframework.boot' version '3.0.2' + id 'io.spring.dependency-management' version '1.1.0' } group = 'ip' @@ -9,26 +9,30 @@ version = '0.0.1-SNAPSHOT' sourceCompatibility = '17' repositories { - mavenCentral() + mavenCentral() } jar { - enabled = false + enabled = false } dependencies { - implementation(project(':front')) - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'com.h2database:h2:2.1.210' - implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5' - implementation 'org.hibernate.validator:hibernate-validator' - implementation group: 'org.springframework', name: 'spring-tx' - implementation 'org.springdoc:springdoc-openapi-ui:1.6.5' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation(project(':front')) + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'com.h2database:h2:2.1.210' + implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5' + implementation 'org.hibernate.validator:hibernate-validator' + implementation group: 'org.springframework', name: 'spring-tx' + implementation 'org.springdoc:springdoc-openapi-ui:1.6.5' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation 'org.springframework.boot:spring-boot-starter-validation' + + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'com.auth0:java-jwt:4.4.0' } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform() } diff --git a/front/index.html b/front/index.html index 319a625..71f8140 100644 --- a/front/index.html +++ b/front/index.html @@ -1,9 +1,8 @@ - - - - + + + - + + +
+ + diff --git a/front/src/App.jsx b/front/src/App.jsx index 58dfdfd..1a838f8 100644 --- a/front/src/App.jsx +++ b/front/src/App.jsx @@ -1,46 +1,91 @@ -import './App.css'; -import { useRoutes, Outlet, BrowserRouter } from 'react-router-dom'; -import Header from './components/common/Header'; +import "./App.css"; +import { + useRoutes, + Outlet, + BrowserRouter, + Routes, + Route, +} from "react-router-dom"; +import Header from "./components/common/Header"; +import PrivateRoute from "./components/common/PrivateRoute"; import Footer from "./components/common/Footer"; -import CatalogStudents from './components/catalogs/CatalogStudents'; -import Menu from './components/catalogs/Menu'; -import Basket from './components/catalogs/Basket'; -import History from './components/catalogs/History'; -import { useState } from 'react'; +import CatalogStudents from "./components/catalogs/CatalogStudents"; +import Menu from "./components/catalogs/Menu"; +import Basket from "./components/catalogs/Basket"; +import History from "./components/catalogs/History"; +import Registration from "./components/catalogs/Registration"; +import { useState } from "react"; +import Login from "./components/catalogs/Login"; +import Users from "./components/catalogs/Users"; function Router(props) { return useRoutes(props.rootRoute); } export default function App() { - const [product,setProduct] = useState([]); + const [product, setProduct] = useState([]); const routes = [ { index: true, element: }, - { path: "catalogs/menu", element: , label: "Меню" }, - { path: "catalogs/component", element: , label: "Компоненты" }, - { path: "catalogs/basket", element: , label: "Корзина" }, - { path: "catalogs/history", element: , label: "История" } + { + path: "catalogs/menu", + label: "Меню", + }, + { + path: "catalogs/component", + label: "Компоненты", + role: "ADMIN", + }, + { + path: "catalogs/basket", + label: "Корзина", + }, + { path: "catalogs/history", label: "История" }, + { + path: "catalogs/users", + label: "Пользователи", + role: "ADMIN", + }, + { + path: "catalogs/registration", + label: "Регистрация", + }, + { + path: "catalogs/login", + label: "Вход в систему", + }, ]; - const links = routes.filter(route => route.hasOwnProperty('label')); - const rootRoute = [ - { path: '/', element: render(links), children: routes } - ]; - - function render(links) { - return ( - <> -
-
- -
-
- - ); - } + const links = routes.filter((route) => route.hasOwnProperty("label")); return ( - +
+
+ + }> + } + path="/catalogs/menu" + exact + /> + } + path="*" + /> + } + path="/catalogs/basket" + /> + } path="/catalogs/history" /> + + }> + } path="/catalogs/component" /> + } path="/catalogs/users" /> + + } path="/catalogs/login" /> + } path="/catalogs/registration" /> + +
+